I am trying to populate a dojo pie chart from a json array created by a url.
the url returns an array that looks like this
{“pieItems”:[[“IPv4 TCP”,475919493840],[“IPv6 TCP”,37443255432],[“IPv4 UDP”,34595392128],[“IPv6 ICMP”,14496],[“IPv4 ICMP”,46560],[“IP Other”,12385112]]}
I have attempted to redo the format of the array changing it to one that looks like this
{“IPv4 TCP”:[475919493840],”IPv6 TCP”:[37443255432],”IPv4 UDP”:[34595392128],”IPv6 ICMP”:[14496],”IPv4 ICMP”:[46560],”IP Other”:[12385112]} .
the code I used to change the format is:
var len = responseObj.pieItems.length, i, hash = {};
for (i = 0; i < len; i++) {
hash[responseObj.pieItems[i][0]] = responseObj.pieItems[i][1];
}
After changing the format I can only populate the chart with on item by adding the series and specifying the name.
chart1.addSeries(“IP Other”, hash[“IPv6 ICMP”])
This populates the chart with that one item but if i try to add another series for example
chart1.addSeries(“IP Other”, hash[“IPv4 Other”])
It overwrites the chart and shows the data for IP Other instead of adding another slice.
How can I add all the items in the array into the pie chart?
Pie chart supports just one series object by definition. You should add different data points for different slices. A sketch: