javascript 我可以在 Highcharts 图表中添加一条“平均”线吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25372736/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 04:26:46  来源:igfitidea点击:

Can I add an "average" line to Highcharts Chart?

javascripthighcharts

提问by Ryan McClure

I'm trying to recreate a chart (the one below) using Highcharts. I'm using a basic bar chart, and I'm wondering if there is a way to get a vertical line showing the average of all the bars? I have the value calculated, I just need it to display as the picture shows. Can I do this using Highcharts?

我正在尝试使用Highcharts重新创建图表(下面的图表)。我使用的是基本条形图,我想知道是否有办法获得一条显示所有条形平均值的垂直线?我已经计算了值,我只需要它如图所示显示即可。我可以使用 Highcharts 做到这一点吗?

enter image description here

在此处输入图片说明

回答by Halvor Holsten Strand

Yes. You can add it as a plotline, like this:

是的。您可以将其添加为情节线,如下所示:

yAxis: {
    // ...Options
    plotLines: [{
        color: 'red',
        value: '15', // Insert your average here
        width: '1',
        zIndex: 2 // To not get stuck below the regular plot lines
    }]
}

See this JSFiddle demonstration.

请参阅此 JSFiddle 演示