live chart

36 views
Skip to first unread message

njhelloworld

unread,
Sep 2, 2017, 11:28:56 PM9/2/17
to Google Visualization API

I have my livedata.php(the time_stamp(named ts),ph,moist are data values in my database) in json format showing:


[{"ts":"12","ph":736,"moist":92},{"ts":"27","ph":0,"moist":0},{"ts":"21","ph":192,"moist":24},{"ts":"15","ph":0,"moist":0}]

That is "ts"(time stamp('d')) shows specific day of a month(this example the month is august)."ph" and "moisture" are the overall value of that specific day. Obviously I am making charts here and I know I am a dumb full of ambitions I am trying to create a live chart that looks like this  .


Now my problem is with this code below I found which is working to their example but trying to my php json fails.


function drawChart() {

var jsonData = $.ajax({
url: 'livedata.php',
dataType: 'json',
async: false
}).done(function (results) {
var data = new google.visualization.DataTable(jsonData);
data.addColumn('datetime', 'time_stamp');
data.addColumn('number', 'ph');
data.addColumn('number', 'moist');
$.each(results, function (i, row) {
data.addRow([
(new Date(row.time_stamp)),
parseFloat(row.ph),
parseFloat(row.moist)
]);
});
var chart = new google.visualization.LineChart($('#chart').get(0));
chart.draw(data, {
title: 'Soil Analysis'
});
});
}
// load chart lib
google.load('visualization', '1', {
packages: ['corechart']
});
// call drawChart once google charts is loaded
google.setOnLoadCallback(drawChart);






Reply all
Reply to author
Forward
0 new messages