Highcharts删除x轴上的空间 [英] Highcharts Remove Space across the x-Axis
问题描述
我试图使用Highcharts库建立一个区域图。突然,我看到在我的实际数据开始之前在x轴上有一些间距。我想从[0,0]轴开始使用适当的数据绘制图形。
I am trying to build an Area Graph using Highcharts library. All of a sudden i see that there is some spacing on the x-axis before my actual data starts. I want to start the graph right from [0,0] axis with appropriate data.
<?php
$data1 = array(3300, 3000, 4300, 4200, 2900, 1900, 1800);
?>
<script type="text/javascript">$(function () {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'areachart',
type: 'area'
},
title: {
text: 'People'
},
credits: {
enabled: false
},
xAxis: {
startOnTick: false,
categories: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
},
yAxis: {
title: {
text: null
},
labels: {
formatter: function() {
return this.value;
}
}
},
plotOptions: {
area:{
dataLabels: {
enabled: true
}
}
},
series: [{
data: [<?php foreach($data1 as $da):
echo $da.', ';
endforeach;
?>
]
}]
});
});
</script>
推荐答案
这是不可能的,因为您使用类别 xAxis
。类别的标签和点始终设置在类别的中间。第一个和最后一个类别因此有你想要摆脱的差距。
但在这种情况下,它不是一个错误,它是一个功能。
This is not possible since you are using categories for the xAxis
. Labels and points for categories are always set in the middle of the category. The first and last category therefore have the gap you want to get rid of.
But in this case, it's not a bug, it's a feature.
您可以尝试修改 xAxis
以使用法线轴,并使用自定义标签格式化程序显示天数而不是数字。
You could try and modify your xAxis
to use a normal axis and use a custom label formatter to display the days instead of numbers.
这篇关于Highcharts删除x轴上的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!