Home Forums Chart Support How can I use JSON.parse with a chart?

How can I use JSON.parse with a chart?

Viewing 6 posts - 1 through 6 (of 6 total)
  • #6140

    I want to use JSON.parse to convert json to an object. I don’t know where I should put this code, in the function makeChart() ? If so, how exactly?

    var obj = JSON.parse(response);
    (obj.tot1);
    (obj.tot2);
    (obj.tot3);

    Where & how do I use this in this example:

    function makeChart() {
    
        var tot1v = 
        var tot2v = 
        var tot3v = 
    
        var chart = new CanvasJS.Chart("colChartContainer", {
            theme: "theme2",
            title: {
                text: "Coin Toss Results"
            },
            data: [{
                type: "column",
                dataPoints: [{
                    label: "tot3",
                    y: tot1v
                }, {
                    label: "tot2",
                    y: tot2v
                },{
                   label: "tot3",
                    y: tot3v                   
                }]
            }]
        });
    
        chart.render();
    }

    I have modified this http://jsfiddle.net/jx9sJ/5/
    My code above in a code share http://codeshare.io/aYM2n

    #6142

    Structure of JSON is {"tot1":5,"tot2":10,"tot3":7}

    I’d really appreciate support on this. Thanks.

    #6151

    [Update]

    Now we have a Tutorial on Creating Charts from JSON Data in our documentation.

    Matthewpoll,

    Here is a JSFiddle that I created.

    • This reply was modified 8 years, 2 months ago by Sunil Urs.
    #29841

    how can I feed a array of JSONs like [{“x”:1,”y”:12,”label”:”Jan”},{“x”:2,”y”:9,”label”:”Apr”},{“x”:3,”y”:10,”label”:”Jul”},{“x”:4,”y”:11,”label”:”Oct”}], in which format should i convert this before handing this to dataPoints tag?.

    #29845

    @smabalan95,

    You can pass entire JSON to dataPoints as shown in this JSFiddle.

    To know more about the format accepted by CanvasJS, please take a look at this documentation page.

    —–
    Manoj Mohan
    Team CanvasJS

    #29847

    Thank You!

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.