AJAX response inside jqplot not working
- by JuanGesino
I'm trying to render data from an AJAX response as a bar chart with jqplot. To render this bar chart I use two variables:
s1 which contains the numbers ex: s1 = [22,67,32,89]
ticks which contains the name corresponding to a number inside s1 ex: ticks = ["Jack", "Mary", "Paul", "John"]
So my AJAX returns two variables, data1 and data2.
When I console.log(data1) I get 22,67,32,89
When I console.log(data2) I get "Jack", "Mary", "Paul", "John"
I then add the square brackets and change variable:
s1 = [data1]
ticks = [data2]
When I console.log(s1) I get ["22,67,32,89"]
When I console.log(ticks) I get "Jack", "Mary", "Paul", "John"
And the graph does not render, this is my code:
s1 = [data];
ticks = [data];
plot4 = $.jqplot('chartdiv4', [s1], {
animate: !$.jqplot.use_excanvas,
series:[{color:'#5FAB78'}],
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true }
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks
},
yaxis:{min:0, max:100, label:'%',labelRenderer: $.jqplot.CanvasAxisLabelRenderer}
},
highlighter: { show: false }
});
});