How to always show the plotLine in HighCharts?

后端 未结 4 790
北恋
北恋 2020-12-16 11:01

I am creating a HighChart with a plotLine in it. The plotLine has a fixed value, while the data can vary between charts.

HighChart scales the y-axis automatically ba

相关标签:
4条回答
  • 2020-12-16 11:42

    You could simply set the max attribute to the max value you will have:

    yAxis: {
    
                max:650 //HERE
                plotLines...
    
            },
    
    0 讨论(0)
  • 2020-12-16 11:50

    In some cases, wergeld's solution would be preferable than jank's solution, especially when you are not sure about min and minRange. But wergeld's solution has a minor issue. If you point your mouse over the plot line, it will show a point and tooltip on the point. To avoid this, I have modified his solution and added enableMouseTracking to get rid of the problem.

    {
         name: 'Goal',
         type: 'scatter',
         marker: {
              enabled: false
         },
         data: [450],
         enableMouseTracking: false
    }
    

    See updated jsFiddle: http://jsfiddle.net/4R5HH/570/

    0 讨论(0)
  • 2020-12-16 12:02

    You need to add in a point to you chart but disable the marker. I added a new series with scatter plot type and its value equal to the goal value:

    {
         name: 'Goal',
         type: 'scatter',
         marker: {
              enabled: false
         },
         data: [450]
    }
    

    See updated jsFiddle: http://jsfiddle.net/wergeld/4R5HH/4/

    0 讨论(0)
  • 2020-12-16 12:04

    One other option that does not introduce data points:

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

    This sets the minimum for the yAxis to 0 (this is unlikely to be false in this case) and the minimum Range to 450.

    See updated fiddle.

    0 讨论(0)
提交回复
热议问题