0

I want to create a pie, using Highcharts.

The data are provided in a json format : Here's the lines of my script :

    function myPie(d){
    console.log(d);
    chart = new Highcharts.Chart({
    ...
    series: [{
    type: 'pie',
    name: 'Test',
    innerSize: '80%',
    data: d
   }
    ]
    ...
    });

The response at the console is Object { p0: "0.232697", p1: "0.259336", p2: "0.298506", p3: "0.177095", p4: "0.0323651" }

And I get nothing What's wrong ? How can I solve this problem. Thanks for help.

user2129506
  • 131
  • 8
  • You get nothing for at least 2 reasons, data needs to be an array, e.g. [{name: 'p0', y: 0.232697}, {name: 'p1', y: 0.259336},...] and data needs to be a number, not a string. – ewolden Sep 21 '18 at 07:34
  • OK thanks, but how can I correct my code ? – user2129506 Sep 21 '18 at 07:41
  • By changing `d`, to have the format I wrote in my comment – ewolden Sep 21 '18 at 07:46
  • I'm new to JQuery so, could you give me the way to do that ? Thanks – user2129506 Sep 21 '18 at 07:53
  • 3
    I am not going to do this for you, I have given you the format your data needs to be. You can chose to do this manually, or programatically. You could for example start here: https://stackoverflow.com/questions/13544551/how-to-iterate-through-a-json-object and here https://www.w3schools.com/jsref/jsref_parsefloat.asp – ewolden Sep 21 '18 at 08:06
  • I'm not sure about your browser compatibilities, but this should be enough: `data: Object.keys(d).map(name => [name, parseFloat(d[name])]);` – Paweł Fus Sep 21 '18 at 10:16

0 Answers0