Note that there are some explanatory texts on larger screens.

plurals
  1. POHighcharts: Parse multi-variable JSON data
    primarykey
    data
    text
    <p>I am trying to make a highcharts chart similar to the one in this demo: <a href="http://www.highcharts.com/demo/column-basic" rel="nofollow">http://www.highcharts.com/demo/column-basic</a> with json data, but I cant see how I can parse my json data in a sensible matter. My data is grouped by week-day, and has three categories. The following is an example:</p> <pre><code>{ "Monday": { "inv": 1126, "oppm": 276, "perc": "24.51" }, "Tuesday": { "inv": 1072, "oppm": 273, "perc": "25.47" }, "Wednesday": { "inv": 1032, "oppm": 271, "perc": "26.26" }, "Thursday": { "inv": 989, "oppm": 259, "perc": "26.19" }, "Friday": { "inv": 937, "oppm": 240, "perc": "25.61" } } </code></pre> <p>Is there a way to do this in a simple matter? Would it help if I changed my json data structure?</p> <p>Thanks in advance!</p> <p><strong>EDIT: Solution:</strong></p> <p>I found a not-too-complicated way of doing it, although I'm sure it could be done even easier if you know your JS. This solution works nicely with my JSON data anyway:</p> <pre><code>//Convert received AJAX data success: function(data) { cleanData = $.parseJSON(data); //Make some empty arrays for the categories and data days = Array(); inv = Array(); oppm = Array(); perc = Array(); //Iterate the data and fill in the new arrays $.each(cleanData, function(index, value) { days.push(index); inv.push(parseFloat(value['inv'])); oppm.push(parseFloat(value['oppm'])); perc.push(parseFloat(value['perc'])); }); //Use the new arrays in the chart chart1 = new Highcharts.Chart({ chart: { renderTo: 'div_chart', type: 'column' }, xAxis:{ categories: days, title: { text: 'Week day' } }, series: [{ name: 'Invited', data: inv }, { name: 'Met', data: oppm }, { name: '%', data: perc }], }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload