how to use JSON Data in chart.js?

前端 未结 2 1983
南方客
南方客 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

提交回复
热议问题