Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
43
rated 0 times [  44] [ 1]  / answers: 1 / hits: 8179  / 11 Years ago, sun, december 29, 2013, 12:00:00

I am newbie parsing JSON object to highchart and I would like to plot basic bar graph.
I have done on the title of graph. The problem is that the series that I would like to show is not showing.(count as series and qpAnswer as xAxis).



Here is my JSON data



[
{
qpQuestion: Is that a dog?,
qpAnswerId: 1,
qpAnswer: Yes,
count: 0
},
{
qpQuestion: Is that a dog?,
qpAnswerId: 2,
qpAnswer: No,
count: 0
},
{
qpQuestion: Is that a dog?,
qpAnswerId: 3,
qpAnswer: ok,
count: 0
}
]


Here is my JS



var url=sections.php?request=graph;
$.getJSON(url,function(data1){

var options={
chart: {
renderTo: 'container',
type: 'column'
},
title: {
text: data1[0].qpQuestion
},
xAxis:{
categories: data1.qpAnswer
title: {
text: 'Answer'
}
},
yAxis: {
min: 0,
title: {
text: 'Answer Count'
}
},
series:data1
};

var chart = new Highcharts.Chart(options);
});

More From » json

 Answers
5

You can pre-process the data to form like



var answers = ['Yes','No' ,'OK'];
var answer_counts= [
{name: 'Yes', data : [2,0,0]},
{name: 'No', data: [0,3,0]},
{name: 'OK', data: [0,0,1]} ];


Then plot it with



var options={
chart: {
renderTo: 'container',
type: 'column'
},
title: {
text:'QA Answers'
},
xAxis:{
categories: answers,
title: {
text: 'Answer'
}
},
yAxis: {
min: 0,
title: {
text: 'Answer Count'
}
},
series:answer_counts
};

var chart = new Highcharts.Chart(options);


I have done in the fiddle, http://jsfiddle.net/gwC2V/1/



Let us know if it helps.


[#49159] Friday, December 27, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yulissamirandah

Total Points: 493
Total Questions: 115
Total Answers: 94

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
;