Jump to content
Software FX Community

Newbie question - converting to string error


Aps.com
 Share

Recommended Posts

Below is sample code I am using to attempt to produce a bar graphic with the yAxis as string data. I have seen examples in these forms that suggesting using a datatable column and implementing the "typeof" method to convert to string.  I have tried that with no success I continue to get the message "input string not correct format"

Please help.

DataTable mydt = new DataTable();

mydt.Columns.Add(

"Range");mydt.Columns.Add("Month",typeof(string));

DataRow mydr1 = mydt.NewRow();mydr1["Range"] = 100;mydr1["Month"] = "March";

mydt.Rows.Add(mydr1);

mydt.AcceptChanges();

DataRow mydr2 = mydt.NewRow();

mydr2[

"Range"] = 200;mydr2["Month"] = "April";

mydt.Rows.Add(mydr2);

mydt.AcceptChanges();

DataRow mydr3 = mydt.NewRow();

mydr3[

"Range"] = 300;mydr3["Month"] = "May";

mydt.Rows.Add(mydr3);

mydt.AcceptChanges();

Chart1.DataSourceSettings.Fields.Add(new FieldMap("Month", FieldUsage.XValue));

Chart1.DataSourceSettings.Fields.Add(

new FieldMap("Range", FieldUsage.Value));

Chart1.DataSource = mydt;

Link to comment
Share on other sites

A month name can not be used as a value (there is no numerical value associated with it). Instead you can use it as a label.

Chart1.DataSourceSettings.Fields.Add(new FieldMap("Month", FieldUsage.Label));

For Range, you need to create it as a numeric column:

mydt.Columns.Add("Range",typeof(double));

 

post-4685-13922403237797_thumb.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...