Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

enter image description here

like image 821
Ryan McClure Avatar asked Aug 18 '14 22:08

Ryan McClure


People also ask

Is it possible to pass multiple series in a chart in Highcharts?

Yes, you can. You could add more. If you get stack with implementing your project, please send us a minimal, verifiable demo in JSFiddle, so we could help you out with your code.

What is plotlines in Highcharts?

An array of lines stretching across the plot area, marking a specific value on one of the axes. In styled mode, the plot lines are styled by the . highcharts-plot-line class in addition to the className option.

How do I change the chart type dynamically in Highcharts?

Re: Change chart type dynamically? You can't change a series type like that, as they are entire different JavaScript classes. What you can do without regenerating the chart, is to get the data from the first series, destroy it, and add a new series of a different type with the same data.

Can we plot two Y axis on the same chart in Highcharts?

But from what I see, it's only possible in Highcharts to either have all lines on one y-axis or each line has its own y-axis.


1 Answers

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

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

See this JSFiddle demonstration.

like image 193
Halvor Holsten Strand Avatar answered Oct 09 '22 03:10

Halvor Holsten Strand