RGraph Pie not reading my data


« 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 John C on 5th June 2017
I'm trying to use the Ajax functions to get my data - it is closely based upon the Ajax Json pie example in RGraph demos. It's not finding it, though, because the pie.js blows up with a null in get contextOf. Here is the code in the View:

<canvas id="testGraph" width="250" height="200" style="border:1px solid #000000;">
                 [No canvas support]
</canvas>

Here is the script code:

RGraph.AJAX('/Home/GetGraphData', function (json) {
         var pie = new RGraph.Pie({
             id: 'testGraph',
             data: json.data,
             options: {
                 labels: json.labels,
                 linewidth: 2,
                 strokestyle: 'white'
             }
         }).draw();
     });

If I go to /Home/GetGraphData, I get a json file that looks like this:

{"data":[8176,2],"labels":["74.3.7","74.72.38"]}

It's almost exactly the same as what you see in the demo:

{data:[60,42,68,6,5,1,32,71,45,93], labels: ['Gary','Olga','Lewis','Rachel','Nathan','Matt','Kevin','Indigo','Lou','Pete']}

So why isn't it reading anything? I've tried /Home/GetGraphData?json, /Home/GetGraphData.json, etc but at best it doesn't blow up - I just get a box with no pie at all.

- John C



Posted by Richard on 5th June 2017
Hi there,

The RGraph.AJAX function does not do any processing on the page that it retrieves, so it will just be a string of text. It looks like you'd be better off using the RGraph.AJAX.getJSON function:



RGraph.AJAX.getJSON('/Home/GetGraphData', function (json)
{
     // Before making the chart ensure that the json
     // data is what you expect it to be

     $p(json);

     //var pie = new RGraph.Pie({
     // id: 'testGraph',
     // data: json.data,
     // options: {
     // labels: json.labels,
     // linewidth: 2,
     // strokestyle: 'white'
     // }
     //}).draw();
});


Richard
Posted by John C on 5th June 2017
That did the trick, thank you :)

Add a reply

 




« Back to message list
Share RGraph!