gpt4 book ai didi

highcharts - 如何始终在 HighCharts 中显示 plotLine?

转载 作者:行者123 更新时间:2023-12-03 08:23:39 28 4
gpt4 key购买 nike

我正在创建一个带有 plotLine 的 HighChart。 plotLine 具有固定值,而图表之间的数据可能会有所不同。
HighChart 根据数据的最大值自动缩放 y 轴,但它在计算中不考虑 plotLine 的值。
因此,如果数据范围包含 plotLine 值,则会显示 plotLine,但如果不是,则会从视口(viewport)中裁剪出来。
例子:

    $(function () {
$(document).ready(function() {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column'
},
title: {
text: 'Dummy Data by Region'
},
xAxis: {
categories: ['Africa', 'America', 'Asia']
},
yAxis: {
plotLines:[{
value:450,
color: '#ff0000',
width:2,
zIndex:4,
label:{text:'goal'}
}]
},
series: [{
name: 'Year 1800',
data: [107, 31, 650]
}]
});
});

});​
上述代码的 JSFiddle: http://jsfiddle.net/4R5HH/3/
目标线(红色)显示为默认数据,但如果我将数据更改为 [107, 31, 250],则 plotLine 会超出图形视口(viewport),因此变得不可见。

最佳答案

另一种不引入数据点的选项:

yAxis: {
minRange:450,
min:0,
plotLines:[{
value:450,
color: '#ff0000',
width:2,
zIndex:4,
label:{text:'goal'}
}]
},

这会将 yAxis 的最小值设置为 0(在这种情况下这不太可能是错误的),并将最小范围设置为 450。

updated fiddle .

关于highcharts - 如何始终在 HighCharts 中显示 plotLine?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13084849/

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