我在向下钻取折线图中显示绘图线时遇到问题。
一切工作正常,但当我深入研究 2015 年时(每行只有 1 个值),情节线不会显示。
我在 this post 中读到过有关此问题的信息但所有解决方案都 Not Acceptable ,因为它们禁用 yAxis 上的自动缩放。
这是发生的事情:
正常图表(向下钻取之前)。它运行完美:
该图表对 2014 年进行了深入分析(每行有 4 个值)。它运行完美:
对 2015 年进行深入分析的图表(每行有 1 个值)。绘图线不显示,并且两点位于同一位置:
这是我初始化图表的方法:
/*Initialisation du chart*/
chart = new Highcharts.Chart({
chart: {
renderTo: instanceData.id,
type: 'line',
alignTicks: false
},
title: {
text: titre_drill
},
subtitle: {
text: soustitre_drill
},
legend:{
enabled:true
},
xAxis: {
type: 'category'
},
yAxis: [{
title: {
text: texte_ordonee_expedie,
style: {
color: color_expedie
}
},
plotLines : [{
value : seuil_expedie,
color : color_expedie,
dashStyle : 'shortdash',
width : 2,
label : {
text : ''
}
}],
labels: {
format: '{value} €',
style: {
color: color_expedie
}
},
gridLineColor: 'transparent'
},
{
title: {
text: texte_ordonee_packee,
style: {
color: color_packee
}
},
plotLines : [{
value : seuil_packee,
color : color_packee,
dashStyle : 'shortdash',
width : 2,
label : {
text : ''
}
}],
labels: {
format: '{value} €',
style: {
color: color_packee
}
},
gridLineColor: 'transparent',
opposite: true //Pour que le deuxième axe soit à l'opposé du premier
}],
plotOptions: {
line: {
cursor: 'pointer',
marker: {
symbol: 'triangle'
},
dataLabels: {
enabled: false
}
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.y +'</b> €<br/>';
}
},
series: main_data,
drilldown: {
series: drilldown_series,
drillUpButton: {
relativeTo: 'spacingBox',
position: {
y: 0,
x: 0
}
}
},
exporting: {
enabled: true
}
});
我知道 Highcharts 中没有任何 native 函数可以“始终显示”绘图线。有没有人有建议,以便我可以在 2015 年的深入分析中显示我的两条情节线?
最佳答案
如果您想在自动缩放不会显示的点上显示情节线...您必须中断自动缩放。没有办法用情节线来解决这个问题。
要使用自动轴缩放,您可以做的是使用线系列而不是绘图线。
如果您希望它表现得像情节线而不是系列,您可以禁用图例条目、工具提示等。
这样,轴将始终自动缩放以包含您的线条。
示例
:
关于javascript - 仅存在一个值时如何显示绘图线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30936331/