Sunday, 18 August 2013

Get InnerText in html table cell and shape it to fit Google Chart API

Get InnerText in html table cell and shape it to fit Google Chart API

I try to get the cellvalue of a table with a varying number of rows
(generated from a 'while' loop in php) and shape them in order to fit in
the Google Chart API.
Here is the table :
<thead>
<tr>
<th>Sport/Month</th>
<th>January</th>
<th>February</th>
<th>March</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tennis</td>
<td>Value Tennis.Jan</td>
<td>Value Tennis.Feb</td>
<td>Value Tennis.Mar</td>
</tr>
<tr>
<td>Football</td>
<td>Value Football.Jan</td>
<td>Value Football.Feb</td>
<td>Value Football.Mar</td>
</tr>
<tr>
<td>Sport_n</td>
<td>Value Sport_n.Jan</td>
<td>Value Sport_n.Feb</td>
<td>Value sport_n.Mar</td>
</tr>
</tbody>
I would like to shape it that way:
[
['Sport/Month','Tennis','Football','Sport_n'],
['Jan',Value Tennis.Jan, Value Football.Jan, Value Sport_n.Jan],
['Feb',Value Tennis.Feb, Value Football.Feb, Value Sport_n.Feb],
['Mar',Value Tennis.Mar, Value Football.Mar, Value Sport_n.Mar]
]
In order to integrate it in that script :
https://code.google.com/apis/ajax/playground/?type=visualization#line_chart
I've tried to pick some code from here, using innerText, etc : How to grab
the values from an HTML table's cells using JavaScript
But my JS knowledge is limited so I couldn't get to what I'd like...
Thanks for any help.

No comments:

Post a Comment