I want to show the multiple line with user select different property.
Now I has the data like I can't define the data Model with Class, because the property is dynamic.
How do i need to use the class, to show chart with multiple Line.
the code is which i want to realize, but it did't work.
Code: Select all
// http receive
string response = "[{\"name\":\"aa\",\"age\":10,\"height\":170},{\"name\":\"bb\",\"age\":11,\"height\":175},{\"name\":\"cc\",\"age\":12,\"height\":180}]";
using Newtonsoft.Json;
// the response has unknowed property, so i need use object to deserialize
JArray jArray = JsonConvert.DeserializeObject<JArray>(response);
// jArray element actual class type is JObject
// when i use Add( list as IList),it not work.
void showChart(string selXLabel, List<string> selYLineLabelList)
{
foreach (string item in selYLineLabelList)
{
Line line = new Line();
line.YValues.DataMember = item;
line.LabelMember = selXLabel;
List<object> list = jArray.ToObject<List<object>>();
line.Add(list as IList);
this.tChart1.Series.Add(line);
}
}
...
List<string> selList = ["Age","Height"].toList()....;
showChart("Name",selList );
I have use HashTable ,but it doesn't work too. The code like
Code: Select all
List<Hashtable> list = jArray.ToObject<List<Hashtable>>();
line.Add(list as IList);