Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在图表中显示图例中的打印线?_Javascript_Jquery_Charts_Highcharts - Fatal编程技术网

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);
                }
            }
        }
    }
]

看看它是如何工作的(或者,在没有事件的情况下)。

作为一种替代,如果你打算制作一个模拟情节所有方面的假系列

您只需将该系列用作您的
绘图线
,并跳过将所有内容绑定在一起的所有额外工作

比如:

例如:


终极解决方案,脱帽致敬!!很好的解决方案。有一点需要注意:我必须使假序列的类型不同于我的其他实际数据序列。我有一个专栏系列,当我添加假系列时,它将我的专栏缩小到其宽度的一半(我假设为假系列腾出空间)。但是,如果我指定了不同的类型(我使用了“line”),则实际数据系列的列宽保持不变。功能仍然运行良好。很棒的解决方案…更简洁
{  
  name: 'Plot Line',
  color: 'red',
  type:'line',
  dashStyle: 'shortdash',
  lineWidth: 2,
  data: [[minXvalue, plotLineValue], {x:maxXvalue, y:plotLineValue, dataLabels: { enabled: true }}]
}