0
I’m having trouble generating a pie chart in the style of Highcharts
. I have the following code to generate the series:
if (vlrTot1 >= 0)
{
Dictionary<string, object> aSeries = new Dictionary<string, object>();
aSeries["data"] = new List<object[]>();
aSeries["name"] = "TIR <= " + vlrLimInf.ToString();
object[] values = new object[2];
decimal vlr1 = Math.Round(((vlrTot1 / (vlrTot1 + vlrTot2 + vlrTot3)) * 100), 1 );
values[0] = "TIR <= " + vlrLimInf.ToString();
values[1] = vlr1;
((List<object[]>)aSeries["data"]).Add(values);
dataResult.Add(aSeries);
}
if (vlrTot2 >= 0)
{
Dictionary<string, object> aSeries = new Dictionary<string, object>();
aSeries["data"] = new List<object[]>();
aSeries["name"] = vlrLimInf.ToString() + " > TIR <= " + vlrLimSup.ToString();
object[] values = new object[ 2 ];
decimal vlr2 = Math.Round(((vlrTot2 / (vlrTot1 + vlrTot2 + vlrTot3)) * 100), 1);
values[0] = vlrLimInf.ToString() + " > TIR <= " + vlrLimSup.ToString();
values[1] = vlr2;
((List<object[]>)aSeries["data"]).Add(values);
dataResult.Add(aSeries);
}
if (vlrTot3 >= 0)
{
Dictionary<string, object> aSeries = new Dictionary<string, object>();
aSeries["data"] = new List<object[]>();
aSeries["name"] = "TIR > " + vlrLimSup.ToString();
object[] values = new object[2];
decimal vlr3 = Math.Round(((vlrTot3 / (vlrTot1 + vlrTot2 + vlrTot3)) * 100), 1);
values[0] = "TIR > " + vlrLimSup.ToString();
values[1] = vlr3;
((List<object[]>)aSeries["data"]).Add(values);
dataResult.Add(aSeries);
}
That’s generating this graph:
The two series are appearing with 100%.
But the correct graph would have to be this:
Below is the output to generate the chart with json:
var data = ServiceGraf.GetValuesByGrafPie(....PARAMETERS....);
return Json(data, JsonRequestBehavior.AllowGet);
I don’t know where it’s wrong. Below is the output Json value:
function (data) {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
ignoreHiddenSeries: false,
type: graf,
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Gráfico do Levantamento de ' + levant
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
series: data
});
}
Highcharts, a priori, accepts an Object array (
object[]
). What you are going through is a list of Object arrays, which can make the script get lost.– Leonel Sanches da Silva
For the line chart, I did pretty much the same thing, and it worked really well to have several series, but with this one I don’t know what’s going on.
– rysahara
The difference is that the line chart accepts series while the pie chart does not.
– Paulo Lima
I figured out what was going wrong.
– rysahara