I am trying to write a script that produces a line chart (Highcharts). The source JSON format is:
[
{"name":"Not used","data":[1,1,1]},
{"name":"Excellent","data":[3]},
{"name":"Good","data":[1,3,1]},
{"name":"Average","data":[1,1]},
{"name":"Poor","data":[1,1,1]}
]
What I need is a way of displaying the query result in a chart (Highcharts), I have tried to write the script but the results are not correct.
$(function () {
var chart;
$(document).ready(function() {
$.getJSON("../charts/1-2-4-overall_year_chart.php", function(json) {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container1',
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Monthly trend',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: 'Percentage %'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: json
});
});
});
});
I am trying to make the chart have a graph displaying the Poor, Average, Good, Excellent and Not used as horizontal lines on the x axis as a percentage grouped by the month. I have had an attemp at creating a JSFiddle but even this I can't get it to work.
Can anyone spare some time to help me out.
In each series values are draw according to order. As I see maximum length of array is 3, which means that you refer to categories from 0 do 2. If you need to have a point in declared value (april), use construciton [x,y] (3,3), where x is index of category.