Chartjs-Create a chart.js point dataset from json

2👍

You can parse your JSON string and transform resulting json object to dataset like below:

var json_str = '{"Values":{"2018-01-16 09:24:34":"10","2018-01-16 19:24:31":"5","2018-01-17 09:24:33":"8","2018-01-18 09:24:35":"9"}}'
var json = JSON.parse(json_str);

var data = [];
for (var d in json.Values) {
    console.log(d, json.Values[d]);
    data.push({
        x : new Date(d),
        y : json.Values[d]
    })
}
var dataset = {
    label : "c",
    backgroundColor : "rgba(0,0,255,0.5)",
    borderColor : 'green',
    fill : false,
    data : data
};
// add to existing datasets
adddata.push(dataset);

So this is the result: https://jsfiddle.net/beaver71/mfvc9p9x/

Leave a comment