I'm trying to loop through a list of objects (some measurements data) using JSTL forEach tag in javascript and display the data by using Google Charts API. The code is showing as following. But looks something wrong. As I double checked, the data in the list of measurements objects works fine to pass to html in ${listOfMeasurements}
, ${measurements.measTime}
, ${measurements.measS1raw}
and ${measurements.measS2raw}
. But in the javascript block, the forEach code is not working to execute data.addRow()
as expected. My guess is, I'm not using forEach correctly in my javascript code, so data.addRow()
was not executed as expected. How can I fix it?
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Date');
data.addColumn('number', 'measurement1');
data.addColumn('number', 'measurement2');
<c:forEach items="${listOfMeasurements}" var="measurements">
"data.addRow("
+"${measurements.measTime}"+","
+"${measurements.measS1raw}"+","
+"${measurements.measS2raw}"+");"
;
</c:forEach>
var options = {
title: 'Measurements'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>