问题如图,x轴数据条数过多可能导致x轴显示不全,开始我使用下面方法
xAxis: {
type: "category",
min: min,
max: max,
data:time,
axisLabel: {
interval:num,//interval为x轴两相邻数据之间所包含数据条数,num为x轴总条数除以24所得结果
show: true,
textStyle: {
color: "#a9a9a9", //更改坐标轴文字颜色
fontSize: 10 //更改坐标轴文字大小
},
rotate: 40,
formatter: function(v) {
var date = new Date(v);
return `${('0' + date.getHours()).slice(-2)}:${('0' + date.getMinutes()).slice(-2)}`;
// return `${('0' + date.getHours()).slice(-2)}:${('0' + date.getMinutes()).slice(-2)}:${('0' + date.getSeconds()).slice(-2)}`;
},
},
开始我以为这样设置是可以的,但是出现的问题是后面有些数据没有显示完全,丢掉一部分数据,后来经过改进要在axisLabel设置最大值最小值属性,代码如下
xAxis: {
type: "category",
data:time,
axisLabel: {
interval:num,
show: true,
textStyle: {
color: "#a9a9a9", //更改坐标轴文字颜色
fontSize: 10 //更改坐标轴文字大小
},
rotate: 40,
formatter: function(v) {
var date = new Date(v);
return `${('0' + date.getHours()).slice(-2)}:${('0' + date.getMinutes()).slice(-2)}`;
// return `${('0' + date.getHours()).slice(-2)}:${('0' + date.getMinutes()).slice(-2)}:${('0' + date.getSeconds()).slice(-2)}`;
},
showMinLabel: true,//显示最小值
showMaxLabel: true,//显示最大值
},
这样设置两属性之后,图表就会绘制完全,所以数据都有显示。