我正在比较每个月的贷方和借方,并使用这些数据创建高图表。这是我正在使用的代码
<html>
<head>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script src = "https://code.highcharts.com/highcharts.js"></script>
<script src = "https://code.highcharts.com/modules/data.js"></script>
</head>
<body>
<div id = "container" style = "width: 550px; height: 400px; margin: 0 auto"></div>
<table id="datatable">
<thead>
<tr>
<th></th>
<th>Credit</th>
<th>Debit</th>
</tr>
</thead>
<tbody>
<tr>
<th>2018-Feb</th>
<td>500</td>
<td>231</td>
</tr>
</tbody>
</table>
</body>
</html>
JavaScript:
<script language = "JavaScript">
$(document).ready(function() {
var data = {
table: 'datatable'
};
var chart = {
type: 'column'
};
var title = {
text: 'Credit Debit comparison'
};
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>
工具提示不适用于上述代码。但是一旦我从tbody
标签中删除th
数字,它将毫无问题地工作。在上面的代码中,如果我将行<th>2018-Feb</th>
更改为<th>Feb</th>
,它将起作用。如何在字段中使用日期格式或任何数字?
小提琴:工作代码 - 正文中没有数字 - 点击这里
不工作代码 - 更改为 2018 年 2 月 - 单击此处
您需要指定xAxis.type
(Highcharts Doc)才能使其像这样工作:
...
var xAxis = {
type:'category'
}
...
json.xAxis = xAxis;
小提琴