I want to create a google line chart from MySQL data which is in json form. JSON data is in this format:
{
"result": [
{
"Date": "Dec 17,2017",
"start_time": "22,08,17",
"selected_time": "[00,00,00]"
},
{
"Date": "Dec 18,2017",
"start_time": "21,48,57",
"selected_time": "[00,00,00]"
},
{
"Date": "Dec 21,2017",
"start_time": "13,23,05",
"selected_time": "[00,00,00]"
},
{
"Date": "Dec 22,2017",
"start_time": "00,13,33",
"selected_time": "[00,00,00]"
},
{
"Date": "Dec 23,2017",
"start_time": "14,48,34",
"selected_time": "[00,00,00]"
},
{
"Date": "Dec 27,2017",
"start_time": "19,21,34",
"selected_time": "[00,00,00]"
}
]
}
Below is code for what i'm doing. but it does not accepts start_time and selected_time values as gives error of mismatch. I have varchar datatypes for all these field in mysql db.
function callbackFuncWithData(json){
var data = new google.visualization.DataTable();
data.addColumn('string', 'Date');
data.addColumn('timeofday', 'start_time');
data.addColumn('timeofday', 'selected_time');
$.each(json, function (key, value) {
$.each(value, function (key, value) {
var temp = [];
temp = value;
alert([temp['Date']+" "+temp['start_time']+" "+temp['selected_time']]);
data.addRows([
[ temp['Date'],temp['start_time'],temp['selected_time']]
]);
});
});
var options = {
tooltip: {
isHtml: true
},
title: 'Trendlines with multiple lines',
hAxis: {
title: 'Date',
},
vAxis: {
title: 'Time'
},
pointSize: 5,
series: {
0: { pointShape: 'circle' },
}
};
var chart = new google.visualization.LineChart(document.getElementById('multipleTrendChart'));
chart.draw(data, options);
}
}).fail(function (jq, text, err) {
console.log(text + ' - ' + err);
});
}
</script>
</head>
<body>
<div id="multipleTrendChart"></div>
</body>
</html>
But it shows this error "Error: Type mismatch. Value 22,08,17 does not match type timeofday in column index 1". Someone please suggest me what is the problem. Thanks