I'm trying to convert a MySQL result-set written in a Java Server Page (.jsp), into a Javascript array that I can graph.
My current MYSQL result-set returns this in the web browser:
I want to return this in Javascript. It must be in this format so I can graph it with d3 or Highcharts :
var ValueArray = [ {x:0, y:110}, {x:15, y:113}, {x:30, y:90} ]
After my MYSQL query is run, I create a table using the following java server tags...
<script>
var ValueArray= [
<c:forEach var="row" items="${meanvalue.rowsByIndex}">
<c:forEach var="column" items="${row}">,
{<c:out value= "${column}"/>}
</c:forEach>
</c:forEach>
]
</script>
This is the corresponding HTML code that is generated and is the current output of my MYSQL query:
<table border="1" id = "meanvalue">
<!-- column headers -->
<tr>
<th>timestamp</th>
<th>Value</th>
<tr>
<td> 0</td>
<td> 110</td>
</tr>
<tr>
<td> 15 </td>
<td> 113</td>
</tr>
<tr>
<td> 30</td>
<td> 90</td>
</tr>
I've searched around stackoverflow and have found similar questions, but none of them have the formatting constraint that I'm looking for; converting a raw number array into a .js array with the format
var Array = [{x: val1, y: val2}, {x: val3, y: val4} ]