how to use JSON Data in chart.js?

前端 未结 2 1982
南方客
南方客 2021-02-06 19:40

hi i have been trying to use data from MYSQL database and use them to create graphical chart with chart.js. i encoded data into JSON data( through a php file name data1.php), no

相关标签:
2条回答
  • 2021-02-06 19:51

    So this a JSON data example,

    var data = '{"name":"tom","Second":"smith","age":"20","height":"180"}'
    

    Create a Variable to Parse the data

    var obj9 = JSON.parse(data);
    

    Then make another Variable to store your specific data. (.age, this is relative to your data set, eg .name, .height)

    var cat = obj9.age;
    

    Then you can use the the variable cat in your graph data.

    data : [cat9,randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
    

    Hope that helps.

    Find out more about JSON http://www.w3schools.com/json/default.asp

    0 讨论(0)
  • 2021-02-06 19:54

    I am not quite sure if you mean this:

    var chartjsData = [];
    for (var i = 0; i < json.length; i++) {
        chartjsData.push(json[i].present_worth);  
    }
    

    http://jsfiddle.net/rnX2Z/1/

    Otherwise comment ;)

    0 讨论(0)
提交回复
热议问题