Background: I develop an HTML/Javascript with AJAX for user to select UI and from there call via AJAX, POST to PHP script to perform an MySQL query. I get the response in the form of JSON (this.responseText) a string representation of the object or can further perform a JSON.parse(this.responseText) to get list of Objects within the JSON.
I want to graph my data, only selected fields as a column chart.
But, whenever it gets to the data.addRow() or data.addRows(), it would exit, no errors from the dev tool debugging console?
//general:
function drawchart(json) {
var rows = new Array();
let data = new google.visualization.DataTable();
for (var x in json) {
data.addColumn('string', "Test-ProcessName", "Test-ProcessName");
data.addColumn('string', "Start-Time", "Start-Time");
data.addColumn('string', "End-Time", "End-Time");
var testName = json[x]["Test-ProcessName"];
var startTime = json[x]["Start-Time"];
var endTime = json[x]["End-Time"];
rows.push([testName, startTime, endTime]);
console.log("Individual values: \'" + testName + " " + startTime + " " + endTime + "\n"); //This works!!!
}
data.addRows(rows); //This is the line that is not happy.
//NOTE: I tried data.addRow([..., ...., ....]); same issue
//Then tried data.addRows(1);
//data.setCell(x,0, json[x]['Test-ProcessName']);
//data.setCell(x,1, json[x]['Start-Time']);
//data.setCell(x,2, json[x]['End-Time']);
//Nothing seems to work.
var options = {
title: "TEST_DATA",
width: 900,
height: 700,
bar: {groupWidth: "60%"},
legend: {position: "none"},
hAxi: {
title: "Test-ProcessName"
},
vAxis: {
title: "Hours-Ran"
}
};
var chartDiv = document.getElementById('chart_area'); //chart_area');
var chart = new google.visualization.ColumnChart(chartDiv);
chart.draw(data, options);
Please advise, as I've spending lots of time trying to work past this addRow(s) issue.
Thanks In advance,
JN