Argument RGraph.Line Variable

Share RGraph:   Share or Like RGraph on Facebook!

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Laurent on 24th October 2012
Hello,

I fetch a JSON data from my php file thanks to jquery.ajax.
I got some values like theses following lines .

0 Object { calldate="20120901 08:09", a_MoS=4.2, b_MoS=4.1}
1 Object { calldate="20120901 08:09", a_MoS=4.5, b_MoS=4.3}
n .......................................................

Then, I record only take one value : var amos = result[indice].a_MoS;
I got some numbers in console.log(amos).
And finally, I create the Line chart object with ID canvas and the variable data.

But it doesn't work.
I have in firebug TypeError: lineCoords[i - 1] is undefined


Code :

function() {
     $.ajax({
      url: 'proxy_stats_mos_by_filter.php',
      type: 'POST',
      data: 'st_search_number='+$('#st_search_number').val(),
      dataType: 'json',
      cache: false,
      error: function(xhr, textStatus, errorThrown) {
      console.log(textStatus + " [" + errorThrown + "]");
      },
      success: function(result, textStatus, XMLHttpRequest) {

      $.each(result, function(indice, ligne) {
                 var amos = result[indice].a_MoS;
                 console.log(amos); // I have a number
                        
                 var chart1 = new RGraph.Line('cvs', amos );
                 chart1.Set('chart.background.barcolor1', 'black');
                 chart1.Set('chart.background.barcolor2', 'black');
                 chart1.Set('chart.background.grid.color', 'rgba(238,238,238,1)');
                 chart1.Set('chart.filled', true);
                 chart1.Set('chart.fillstyle','rgba(0,255,0,1)');
                 chart1.Set('chart.colors', ['green']);
                 chart1.Set('chart.text.color',['green']);
                 chart1.Set('chart.linewidth', 2);
                 chart1.Set('chart.hmargin', 5);
                 chart1.Set('chart.tickmarks', 'endcircle');
                 chart1.Set('chart.labels', ['Barry','Paul','Rich','Steve','Olga','Lynn','Pete'] );
                 chart1.Draw();
        });
 
      }
      }
     )
}


Thanks
Posted by RGraph support on 24th October 2012
Hi,

By the sounds of it you're not passing RGraph what you think you are - so you need to check this. There is a p() function that you can use that is part of RGraph that will use alert() to show you the variable and its structure. You can use this function to verify that you are indeed passing in to RGraph what you think you are. It should be an array with the Line chart like this:

[4,8,5,3,5,4]
Posted by Enter your name... on 26th October 2012
Indeed, I haven't gotten the right format
Now, it works

        $.ajax
        ..................etc................
        var T_amos = [];
        $.each(result, function(indice, ligne) {
            T_amos.push( ligne.a_MoS );
        });
    
         var chart1 = new RGraph.Line('cvs',T_amos );
         ..................etc................


Thank you
Posted by RGraph support on 26th October 2012
Hi,

> Now, it works

Great.

Thanks.

Add a reply




« Back to message list