AJAX response inside jqplot not working

Posted by JuanGesino on Stack Overflow See other posts from Stack Overflow or by JuanGesino
Published on 2014-05-31T15:22:50Z Indexed on 2014/05/31 15:24 UTC
Read the original article Hit count: 290

Filed under:
|
|
|

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:

  1. s1 which contains the numbers ex: s1 = [22,67,32,89]
  2. 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 }
            });
        });

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery