Javascript 如何在图表中显示图例中的打印线?
我不仅希望我的图例包含系列的名称,还希望它包含其他项目的名称,如绘图线。这是我的密码:Javascript 如何在图表中显示图例中的打印线?,javascript,jquery,charts,highcharts,Javascript,Jquery,Charts,Highcharts,我不仅希望我的图例包含系列的名称,还希望它包含其他项目的名称,如绘图线。这是我的密码: plotLines: [ { color: 'red', dashStyle: 'shortdash', value: response.AverageTime, width: 2, label: { text: response.PlotLineName, x: +10,
plotLines: [
{
color: 'red',
dashStyle: 'shortdash',
value: response.AverageTime,
width: 2,
label: {
text: response.PlotLineName,
x: +10,
y: +30,
rotation: 360,
color: 'red'
}
}
]
所以我想要我的绘图线的名称,即“平均速度偏差”,在下面的图例框中显示。我怎样才能做到这一点
您可以创建一个模拟打印线特征(颜色、虚线样式…)的空序列。然后,您可以选择使用
legendItemClick
事件将其“链接”到绘图线
例如,可以为ID和打印线选项预定义以下变量:
plotLineId = 'myPlotLine'; // To identify for removal
// Plot line options for adding
plotLineOptions = {
color: '#FF0000',
id: plotLineId,
width: 2,
value: 5.5,
dashStyle: 'shortdash'
};
轴绘制线:
xAxis: {
plotLines: [ plotLineOptions ]
}
您的模拟系列:
series: [
// ...
{
// Series that mimics the plot line
color: '#FF0000',
name: 'My plotline',
dashStyle: 'shortdash',
marker: {
enabled: false
},
events: {
// Event for showing/hiding plot line
legendItemClick: function(e) {
if(this.visible) {
this.chart.xAxis[0].removePlotLine(plotLineId);
}
else {
this.chart.xAxis[0].addPlotLine(plotLineOptions);
}
}
}
}
]
看看它是如何工作的(或者,在没有事件的情况下)。作为一种替代,如果你打算制作一个模拟情节所有方面的假系列 您只需将该系列用作您的
绘图线
,并跳过将所有内容绑定在一起的所有额外工作
比如:
例如:
{
name: 'Plot Line',
color: 'red',
type:'line',
dashStyle: 'shortdash',
lineWidth: 2,
data: [[minXvalue, plotLineValue], {x:maxXvalue, y:plotLineValue, dataLabels: { enabled: true }}]
}