Jump to content
Software FX Community

Newbie question - converting to string error


Aps.com

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...