我有一个固定宽度和固定条形宽度的柱状图。当数据较少时,条之间的空间会增加。我想减少空间,我不介意条形图是从图表的开始还是在中间显示,但是应减小条形图的空间。一个10px的空间看起来不错。任何帮助深表感谢。这是一个演示-
Highcharts.chart('container', {
chart: {
type: 'column',
width:1200
},
title: {
text: 'Monthly Average Rainfall'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
categories: [
'Jan',
'Feb'
],
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Rainfall (mm)'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointWidth:30
}
},
series: [{
name: 'Tokyo',
data: [49.9, 71.5]
}]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
答案 0 :(得分:0)
我唯一想到的就是添加一堆伪造的列,以占用额外的空间。 Highcharts似乎不像这样工作。根据{{3}},使用pointWidth
或pointPadding
取决于您提供的是哪一种,但不能同时使用两者。
Highcharts.chart('container', {
chart: {
type: 'column',
width:1200
},
title: {
text: 'Monthly Average Rainfall'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
categories: [
'Jan',
'Feb',
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''
],
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Rainfall (mm)'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointWidth: 30,
},
},
series: [{
name: 'Tokyo',
data: [49.9, 71.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
}]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>