gpt4 book ai didi

javascript - Highcharts 中最后一列宽度的问题

转载 作者:行者123 更新时间:2023-11-30 16:15:47 25 4
gpt4 key购买 nike

我在使用 Datatable 动态加载表格数据后呈现 Highcharts。

我遇到了图表中柱状图的问题。请检查下面的代码。

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/data.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/4.1.5/modules/broken-axis.js">
</script>
</head>

<body>
<div id="advertiser_chart"></div>
<table id="datatable">
<thead>
<tr role="row">
<th class="sorting_disabled" rowspan="1" colspan="1">Month</th>
<th class="sorting_disabled" rowspan="1" colspan="1">Order</th>
<th class="sorting_disabled" rowspan="1" colspan="1">Revenue</th>
</tr>
</thead>
<tbody>
<tr role="row" class="odd">
<td>2016</td>
<td>3</td>
<td>11</td>
</tr>
<tr role="row" class="even">
<td>2015</td>
<td>1</td>
<td>3</td>
</tr>
<tr role="row" class="odd">
<td>2014</td>
<td>0</td>
<td>0</td>
</tr>
<tr role="row" class="even">
<td>2013</td>
<td>0</td>
<td>0</td>
</tr>
<tr role="row" class="odd">
<td>2012</td>
<td>0</td>
<td>0</td>
</tr>
</tbody>
</table>
</body>
<script type="text/javascript">
$('#advertiser_chart').highcharts({
data: {
table: 'datatable'
},
chart: {
type: 'column'
},
title: {
text: ''
},
yAxis: {
allowDecimals: false,
title: {
text: ''
}
},
xAxis: {
allowDecimals: false,
title: {
text: ''
}
},
tooltip: {
formatter: function () {
//return '<b>' + this.series.name + '</b><br/>' + this.point.y + ' ' + this.point.name.toLowerCase();
return '<b>' + this.series.name + '</b><br/>' + this.y;
}
},
plotOptions: {
series: {
//pointWidth: 40,// Remove padding between olumns
}
}
});
</script>
</html>

我能得到什么解决方案?

这也是 fiddle

https://fiddle.jshell.net/ra527ee8/

最佳答案

当您动态呈现表格数据时,请尝试按升序加载数据,以防它是降序的。

您的表格应如下所示,并替换表格主体:

<tbody>
<tr role="row" class="odd">
<td>2012</td>
<td>0</td>
<td>0</td>
</tr>
<tr role="row" class="even">
<td>2013</td>
<td>0</td>
<td>0</td>
</tr>
<tr role="row" class="odd">
<td>2014</td>
<td>0</td>
<td>0</td>
</tr>
<tr role="row" class="even">
<td>2015</td>
<td>1</td>
<td>3</td>
</tr>
<tr role="row" class="odd">
<td>2016</td>
<td>3</td>
<td>11</td>
</tr>
</tbody>

关于javascript - Highcharts 中最后一列宽度的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35551807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com