6
I have the following code in C#:
Dictionary<string, object> dataResult = new Dictionary<string, object>();
dataResult["data"] = new List<object[]>();
dataResult["name"] = i;
foreach (var item in query)
{
object[] values = new object[2];
values[0] = Convert.ToDecimal(item.ini) ;
values[1] = Convert.ToDecimal(item.ir);
((List<object[]>)dataResult["data"]).Add(values);
}
With it I will present the following JSON:
var data = [
{"TESTE2008",23.4,2},
{"TESTE2008",24.4,3},
{"TESTE2008",25.4,4},
{"TESTE2008",26.4,5},
{"TESTE2008",27.4,6},
{"TESTE2008",28.4,7},
{"TESTE2008",29.4,8},
{"TESTE2008",30.4,9},
{"TESTE2009",30.4,2},
{"TESTE2009",31.4,3},
{"TESTE2009",32.4,4},
{"TESTE2009",33.4,5},
{"TESTE2009",34.4,6},
{"TESTE2009",35.4,7},
{"TESTE2009",36.4,8},
{"TESTE2009",37.4,9},
];
and would like the data to be formatted as follows:
series: [{
name: 'TESTE2008',
data: [[23.4,2],[24.4,3],[25.4,4],[26.4,5],[27.4,6],[28.4,7],[29.4,8],[30.4,9]
]},
{
name: 'TESTE2009',
data: [[30.4,2],[31.4,3],[32.4,4],[33.4,5],[34.4,6],[35.4,7],[36.4,8],[37.4,9]]},
});
How to change my code to produce the desired output?
There are actually two errors there. 1. Your [tag:json] is being misgenerated. This [tag:json] that is in the question is not a valid [tag:json]. Every object in [tag:json] needs to be named. 2. [tag:highcharts] does not accept a
array
as a value if a given.– Erlon Charles
If you need two values in a single series, you actually need two different series.
– Erlon Charles
I managed to put together a series, but I’m not getting more than one. I could check what is wrong with the script I put in this doubt: http://answall.com/questions/6019/varias-series-em-highchart-mvc-asp-net
– rysahara
Your json needs to be like this
[{
 name: 'TESTE2008',
 data: [23.4,2,24.4,3,25.4,4,26.4,5,27.4,6,28.4,7,29.4,8,30.4,9]
}, {
 name: 'TESTE2009',
 data: [30.4,2,31.4,3,32.4,4,33.4,5,34.4,6,35.4,7,36.4,8,37.4,9]
}]
– Erlon Charles
Got it, thanks for the help...
– rysahara