Home forums Using CanvasJS How can I use JSON.parse with a chart?

Tagged: ,

This topic contains 2 replies, has 2 voices, and was last updated by  Sunil Urs 2 years, 6 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #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);

    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                   

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



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

    I’d really appreciate support on this. Thanks.


    Sunil Urs


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


    Here is a JSFiddle that I created.

    • This reply was modified 1 month, 1 week ago by  Sunil Urs.
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.