一 代码
<html>
<head>
<meta charset="UTF-8"/>
<title>Highcharts 使用 HTML 表格数据的柱形图</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/data.js"></script>
</head>
<body>
<div id="container" style="width: 550px; height: 400px; margin: 0 auto"></div>
<script language="JavaScript">
$(document).ready(function() {
// 数据
var data = {
table: 'datatable'
};
var chart = {
type: 'column'
};
// 标题
var title = {
text: '从网页中的 HTML 表格中读取数据'
};
// Y 轴
var yAxis = {
allowDecimals: false,
title: {
text: 'Units'
}
};
var tooltip = {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
this.point.y + ' ' + this.point.name.toLowerCase();
}
};
var credits = {
enabled: false
};
var json = {};
json.chart = chart;
json.title = title;
json.data = data;
json.yAxis = yAxis;
json.credits = credits;
json.tooltip = tooltip;
$('#container').highcharts(json);
});
</script>
<table id="datatable">
<thead>
<tr><th></th><th>小明</th><th>小红</th></tr>
</thead>
<tbody>
<tr><th>苹果</th><td>3</td><td>4</td></tr>
<tr><th>梨子</th><td>2</td><td>0</td></tr>
<tr><th>栗子</th><td>5</td><td>11</td></tr>
<tr><th>香蕉</th><td>1</td><td>1</td></tr>
<tr><th>橘子</th><td>2</td><td>4</td></tr>
</tbody>
</table>
</body>
</html>
二 运行结果