ElementStacks
HTML
<script src="http://highcharts.com/js/testing.js"></script>
<div id="container" style="height: 400px; width: 500px"></div>
<table id="datatable">
<thead>
<tr>
<th></th>
<th>Rainfall</th>
<th>Temperature</th>
</tr>
</thead>
<tbody><tr><td>Jan</td><td>49.9</td><td>7</td></tr><tr><td>Feb</td><td>71.5</td><td>6.9</td></tr><tr><td>Mar</td><td>106.4</td><td>9.5</td></tr><tr><td>Apr</td><td>129.2</td><td>14.5</td></tr><tr><td>May</td><td>144</td><td>18.2</td></tr><tr><td>Jun</td><td>176</td><td>21.5</td></tr><tr><td>Jul</td><td>135.6</td><td>25.2</td></tr><tr><td>Aug</td><td>148.5</td><td>26.5</td></tr><tr><td>Sep</td><td>216.4</td><td>23.3</td></tr><tr><td>Oct</td><td>194.1</td><td>18.3</td></tr><tr><td>Nov</td><td>95.6</td><td>13.9</td></tr><tr><td>Dec</td><td>54.4</td><td>9.6</td></tr></tbody>
</table>
JavaScript
/**
* Visualize an HTML table using Highcharts. The top (horizontal) header
* is used for series names, and the left (vertical) header is used
* for category names. This function is based on jQuery.
* @param {Object} table The reference to the HTML table to visualize
* @param {Object} options Highcharts options
*/
Highcharts.visualize = function(table, options) {
seriesTypes = ['column', 'spline'];
// the categories
options.xAxis.categories = [];
$('tbody th', table).each( function(i) {
options.xAxis.categories.push(this.innerHTML);
});
// the data series
options.series = [];
$('tr', table).each( function(i) {
var tr = this;
$('th, td', tr).each( function(j) {
if (j > 0) { // skip first column
if (i == 0) { // get the name and init the series
options.series[j - 1] = {
name: this.innerHTML,
type: seriesTypes[j-1],
yAxis: j-1,
data: []
};
} else { // add values
options.series[j - 1].data.push(parseFloat(this.innerHTML));
}
}
});
});
var chart = new Highcharts.Chart(options);
}
// On document ready, call visualize on the datatable.
$(document).ready(function() {
var table = document.getElementById('datatable'),
options = {
chart: {
renderTo: 'container'
},
title: {
text: 'Data extracted from a HTML table in the page'
},
xAxis: {
//categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: []
};
Highcharts.visualize(table, options);
});