I have an array of objects which I've created by parsing a JSON string:
var measurementData = @Html.Raw(JsonConvert.SerializeObject(this.Model.Item1));
var stringifiedData = JSON.stringify(measurementData);
var parsedData = JSON.parse(stringifiedData);
This gives me a number of objects, depending on the model, looking like this:
Now my question is, how do I add these to a Google line chart without having to hardcode it into the datatable?
This is what I've got now, which works somewhat:
var data = new google.visualization.DataTable();
data.addColumn('string', 'TimeStamp');
data.addColumn('number', selectedMeasurements);
data.addRows([
[parsedData[index[0]].TimeStamp, parsedData[index[0]][selectedMeasurements]],
[parsedData[index[1]].TimeStamp, parsedData[index[1]][selectedMeasurements]]
]);
chart.draw(data, options, {
isStacked: true,
vAxis: {
viewWindowMode: 'explicit',
viewWindow: {
max: 100,
min: 0
}
}
});
Here I'm adding two arrays with data to the datatable, since there is two objects to add. But what if I only have one? Or 10? I imagine some kind of foreach inside the .addRows
but I'm not sure how to accomplish this.
Any help appreciated!