Skip to content

Instantly share code, notes, and snippets.

@amelieykw
Last active April 20, 2018 14:45
Show Gist options
  • Save amelieykw/6c8c09b4446ec8b5346ff030f3b3bb42 to your computer and use it in GitHub Desktop.
Save amelieykw/6c8c09b4446ec8b5346ff030f3b3bb42 to your computer and use it in GitHub Desktop.
[Highcharts - 02 - Chart Concepts] #Highcharts #ChartConcepts #Title&Subtitle #Axes #Series # Tooltip #Legend #RangeSelector #Navigator #Scrollbar #PlotBands&PlotLines #Zooming #Labels&StringFormatting #Drilldown #3Dcharts #Accessibility #Responsive

To get to grasp with how Highcharts works it is important to understand the various parts or concepts of a chart.

Below is an image and a description of the main concepts in a chart.

Title

Is the text that will be presented at the top of a chart. more information

Series

Is one or more series of data presented on a chart. more information

Tooltip

When hovering over a series or a point on the chart you can get a tooltip that describes the values on that perticular part of the chart. more information

Legend

The legend show the data series in the graph and allows for enabling and disabling one or more series. more information

Axes

The x and y-axis of the chart, can also use multiple axes for different dataseries.

Most chart types, like the typical cartesian types line and column, have axes.

Polar charts have an X axis that spans around the perimeter of the chart.

Even gauges have a single value axis.

Pie charts don't have axes.

more information

Highstock is based on Highcharts, meaning it has all the core functionality of Highcharts, plus some additional features.

Highstock also supports candlestick and OHLC charts.

NAVIGATOR

Allows you to fine tune the range of the chart which is displayed. more information

RANGE SELECTOR

Allows you to quickly select a range to be shown on the chart or specify the exact interval to be shown. more information

SCROLLBAR

Allows scrolling on the chart. more information

CROSSHAIR

Shows a line following the tooltip of a chart to better read results of the x-axis.

This functionality can be found in the Tooltip option.

Crosshairs can also be used in Highcharts, but are not enabled by default. more information

The title is by default displayed at the top of the chart, and an optional subtitle can be shown beneath it.

The title and subtitle can be set as shown in the example below.

title: {
    text: 'My custom title'
},
subtitle: {
    text: 'My custom subtitle'
}

The title and subtitle can also be moved around by the default attributes of the title and subtitle options (align, float, margin, verticalAlign, x, y).

1. Title Styling

For all available options, see options.title and options.subtitle.

2. Title Render Dynamically

Titles can be modified dynamically after render time by the Chart.setTitle method.

The chart's main title.

align: String

The horizontal alignment of the title. Can be one of "left", "center" and "right".

Defaults to center.

Aligned to the plot area (x = 70px = margin left - spacing left)

floating: Boolean

When the title is floating, the plot area will not move to make space for it.

Defaults to false.

margin: Number

The margin between the title and the plot area, or if a subtitle is present, the margin between the subtitle and the plot area.

Defaults to 15.

style: CSSObject

CSS styles for the title.

Use this for font styling, but use align, x and y for text alignment.

In styled mode, the title style is given in the .highcharts-title class.

Defaults to { "color": "#333333", "fontSize": "18px" }.

text: String

The title of the chart.

To disable the title, set the text to null.

Defaults to Chart title.

useHTML: Boolean

Whether to use HTML to render the text.

Defaults to false.

verticalAlign: String

The vertical alignment of the title. Can be one of "top", "middle" and "bottom".

When a value is given, the title behaves as if floating were true.

Defaults to undefined.

widthAdjust: Number

Adjustment made to the title width, normally to reserve space for the exporting burger menu.

Defaults to -44.

x: Number

The x position of the title relative to the alignment within chart.

spacingLeft and chart.spacingRight.

Defaults to 0.

y: Number

The y position of the title relative to the alignment within chart. spacingTop and chart.spacingBottom.

By default it depends on the font size.

Defaults to undefined.

setTitle(titleOptions, subtitleOptions, redraw)

Set a new title or subtitle for the chart.

Parameters:

Name Type Description
titleOptions TitleOptions New title options. The title text itself is set by the titleOptions.text property.
subtitleOptions SubtitleOptions New subtitle options. The subtitle text itself is set by the subtitleOptions.text property.
redraw Boolean Whether to redraw the chart or wait for a later call to chart.redraw().

Try it

The x-axis and y-axis are shown by default in all charts but the pie chart.

Here is a quick overview of the axis elements:

1. AXIS LABELS, TICKMARKS AND GRIDLINES

The axis labels, tickmarks and gridlines are closely linked and all scale together. Their positioning is calculated to best fit the data present in a chart.

TICKS

Tick marks are the lines placed along an axis to show the units of measurement.

The spacing between ticks are mainly decided by the tickInterval and tickPixelInterval options.

Labels and grid lines are laid out on the same positions as the tick marks.

tickInterval

The tickInterval option decides the interval of the tick marks in axis units.

The tick interval defaults to null, which means it is computed to approximately follow the tickPixelInterval on linear and datetime axes.

  • On categorized axes, a null tickInterval will default to 1, one category.
  • datetime axes are based on milliseconds, so for example an interval of one day is expressed as 24 * 3600 * 1000.
  • On logarithmic axes, the tickInterval is based on powers, so :
    • a tickInterval of 1 means one tick on each of 0.1, 1, 10, 100 etc
    • a tickInterval of 2 means a tick of 0.1, 10, 1000 etc
    • a tickInterval of 0.2 puts a tick on 0.1, 0.2, 0.4, 0.6, 0.8, 1, 2, 4, 6, 8, 10, 20, 40 etc

tickPixelInterval

The "tickPixelInterval" sets an approximate pixel interval of the tick marks based on a pixel value (if "tickInterval" is null).

It doesn't apply to categorized axis. Defaults to 72 for the y-axis and 100 for the x-axis.

MINOR TICKS

If the minorTickInterval option is set, minor ticks are laid out between the major ones.

This includes minor tick marks, and minor grid lines, which have their own options for look and feel, but excludes labels.

LABELS

The axis labels can be found along the axis showing the value of the data it corresponds to.

Labels can also be customized using a formatter function:

yAxis: {
    labels: {
        formatter: function() {
            return this.value + ' %';
        }
    },
},

The above example takes the value of the y-axis label and adds a % symbol at the end of it.

GRID LINES

Grid lines are collections of horizontal (and/or vertical) lines that divide a chart into a grid, making it easier to read values of the chart.

To enable or disable gridlines for either the x or y-axis, set the gridLineWidth of the respective axis:

xAxis: {
    gridLineWidth: 1
},
yAxis: {
    gridLineWidth: 1
}

Grid lines :

  • for the y-axis are enabled by default (gridLineWidth: 1)
  • disabled by default for the x-axis (gridLineWidth: 0)

Other options for grid lines can be found in the API reference for the x and y-axis.

Minor grid lines are intermediary lines that can be enabled by setting the minorTickInterval option.

MULTIPLE AXES

It is possible to have multiple axes and linking them with different data series.

To do this several axes needs to be created, like this:

yAxis: [{ //--- Primary yAxis
    title: {
        text: 'Temperature'
    }
}, { //--- Secondary yAxis
    title: {
        text: 'Rainfall'
    },
    opposite: true
}],

series: [{
    yAxis: 0,
    data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
},{
    yAxis: 1,
    data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}]

Note that several axes are created using a list, so the first yAxis starts with index 0. And the "opposite: true" option puts the axis on the right side of the chart.

2. AXIS TITLE

The axis title, showing next to the axis line.

This title by default for the y-axis and hidden by default for the x-axis. See xAxis.title for the full set of options.

3. AXIS TYPES

An axis can be either, linear, logarithmic, datetime or categories.

The axis type is set like this:

// The types are 'linear', 'logarithmic' and 'datetime'
yAxis: {
    type: 'linear',
}

// Categories are set by using an array
xAxis: {
    categories: ['Apples', 'Bananas', 'Oranges']
}

LINEAR

The numbers along the axis are of linear scale.

This is the default axis type. If only y-values are present in a dataseries the x-axis is labeled from 0 to the number of y-values (shows the array index of the y-values):

var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'column'
        },
        title: {
            text: 'Fruit Consumption'
        },
        xAxis: {
            title: {
                text: 'Fruit Number'
            },
            tickInterval: 1
        },
        yAxis: {
            title: {
                text: 'Fruit eaten'
            },
            tickInterval: 1
        },
        series: [{
            name: 'Jane',
            data: [1, 0, 4]
        }, {
            name: 'John',
            data: [5, 7, 3]
        }]
    }});

LOGARITHMIC

On a logarithmic axis :

  • the numbers along the axis increase logarithmically
  • the axis adjusts itself to the data series present in the chart

Note that on logarithmic axes, the tickInterval option is based on powers, so :

  • a tickInterval of 1 means one tick on each of 0.1, 1, 10, 100 etc.
  • a tickInterval of 2 means a tick of 0.1, 10, 1000 etc.
  • a tickInterval of 0.2 puts a tick on 0.1, 0.2, 0.4, 0.6, 0.8, 1, 2, 4, 6, 8, 10, 20, 40 etc.

Another thing to note is that a logarithmic axis can never become negative, as each full axis unit is one tenth of the previous. As a consequence, Highcharts will remove 0 or negative points associated to the axis, and if you try to set the axis.min option to 0 or negative, it will fail with an error.

DATETIME

A datetime axis prints labels of round date values in appropriate intervals.

Internally, a datetime axis is a linear numeric axis based on milliseconds since midnight Jan 1, 1970, as specified by the JavaScript Date object.

Depending on the scale the datetime label will either be represented as time or a date.

Some useful functions are:

/* Get time in millis for UTC */
Date.UTC(year,month,day,hours,minutes,seconds,millisec)

/* Get time in millis for your local time */
Date.parse("Month day, year");

/* Built in Highcharts date formatter based on the PHP strftime (see API reference for usage) */
Highcharts.dateFormat("Month: %m Day: %d Year: %Y", 20, false);

Note that Unix based server timestamps are represented as seconds not milliseconds. This is useful to know since PHP time is based on a Unix timestamp, so to use it with Highcharts the value only needs to be multiplied by 1000.

In Highstock the x-axis is always a datetime axis.

CATEGORIES

If categories are present, the names of the categories are used instead of numbers or dates on the axis. See xAxis.categories.

WHAT AXIS TYPE SHOULD I USE?

Many of the examples in the Highcharts demo come with an xAxis with categories. However, it is important to understand when to use categories and when you are better off with a linear or datetime xAxis.

Categories are groups of items, like for example "Apples", "Pears" and "Oranges", or "Red", "Green", "Blue", "Yellow". These categories have that in common that there are no intermediate values. There's no sliding transition between apples and pears. Also, if you leave one category out, the user isn't able to understand what is left out. Say if you print every second color of "Red", "Green", "Blue" or "Yellow", the user won't know what colors are missing. Therefore, Highcharts doesn't have automatic methods to hide categories if they become to dense on the axis. If you have problems with overlapping axis labels, try either the xAxis.labels.staggerLines option, or give the labels a rotation. If you find that you can skip category labels by the xAxis.labels.step option, chances are that you are better off using a linear or datetime axis.

An xAxis of the linear or datetime type has the advantage that Highcharts is able to determine how close the data labels should be because it knows how to interpolate. The labels will by default be placed with approximately 100px between them, which can be changed in the tickPixelInterval option. If you have predictable categories like "Item1", "Item2", "Item3" or "2012-01-01", "2012-01-02", "2012-01-03" etc., linear or datetime axis types combined with an xAxis.labels.formatter would probably be a better choice.

DYNAMICALLY UPDATING AXES

Axes can be updated with new information after render time.

For more information about this look in the API.

Below is a list of the main topics regarding series.

  • What is series?
  • The data in a series
  • Point and marker
  • Series options:
    • Animation
    • Color
    • Point selection
    • Line width
    • Stacking
    • Cursor
    • Data labels
    • Dash style
    • Zones

What is series?

A series is a set of data (for example a line graph or one set of columns).

All data plotted on a chart comes from the series object.

The series object has the structure:

/* the series object = an array, meaning it can contain several series. */
series: [{
    name: ''  /* name attribut gives the series a name, which show up when hovering over the series in a chart and in the legend */
    data: []  /* the actual data (as an array) */
}]

The data in a series

The data: [] attribut presents the actual data in 3 ways :

1. A list of numerical values

data: [0, 5, 3, 5] /* will be interpreted as y value */
/* then the x value will be automatically calculated(0~1 | pointStart~pointInterval | categories)*/

Example :

<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px"></div>
Highcharts.chart('container', {
    title: {
        text: 'Chart reflow is set to true'
    },

    subtitle: {
        text: 'When resizing the window or the frame, the chart should resize'
    },


    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }]
});

2. A list of arrays with 2 values

data: [[5, 2], [6, 3], [8, 2]]
/* the 1st value : x value */
/* the 2nd value : y value */

/* when the 1st value is string : the name of the point,
the 2nd value is incremented following the above rules.*/

Example :

<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px"></div>
Highcharts.chart('container', {
    xAxis: {
        minPadding: 0.05,
        maxPadding: 0.05
    },

    series: [{
        data: [
            [0, 29.9],
            [1, 71.5],
            [3, 106.4]
        ]
    }]
});

3. A list of object with named values

/* In this case the objects are point configuration objects as seen under options.point. */
data: [{
    name: 'Point 1',
    color: '#00FF00',
    y: 0
}, {
    name: 'Point 2',
    color: '#FF00FF',
    y: 5
}]

Example:

<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px"></div>
Highcharts.chart('container', {
    chart: {
        type: 'column'
    },

    xAxis: {
        categories: ['Green', 'Pink']
    },

    series: [{
        data: [{
            name: 'Point 1',
            color: '#00FF00',
            y: 1
        }, {
            name: 'Point 2',
            color: '#FF00FF',
            y: 5
        }]
    }]
});

Point and marker

Point

  • For cartesian charts :

    • a point represents a (x, y) pair on the chart
    • Points can be given separate options inside the series data
  • For other chart types :

    • the point represents other values than (x, y).
    • For instance,
      • in a range chart -> the point represents (x, low, high).
      • in an OHLC chart -> the point represents (x, open, high, low, close).
      • in a pie chart or gauge -> the point represents a single value.

Point option

The point option can be applied to all charts.

"how to edit the color of a specific point" :

series: [{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5,
          { y: 216.4, color: '#BF0B23'}, 194.1, 95.6, 54.4]
}]

Point marker

  • slightly different from the point option (because they enable altering the style and shape of the point marker)
  • for Line, spline, area and areaspline charts

"How to alter the color and size of a marker on a specific point?" :

series: [{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5,
    {y: 216.4, marker: { fillColor: '#BF0B23', radius: 10 } }, 194.1, 95.6, 54.4]
}]

Series options:

  • Animation
  • Color
  • Point selection
  • Line width
  • Stacking
  • Cursor
  • Data labels
  • Dash style
  • Zones

The series options can be defined in 2 places within the Highcharts options structure :

  1. General options : apply to multiple series --> defined in the plotOptions
    • to set general options for all series in the chart, use plotOptions.series
    • to set general options for a specific chart type, use plotOptions.series for each chart type
  2. Specific options : apply for each series --> defined in the series options structure
    • All options listed for the plotOptions structure, can also be set in the specific series definition.
    • Some options (like data, id or name, only make sense for specific series*

Animation

Allows disabling or altering the characteristics of the initial animation of a series.

Animation is enabled by default.

Color

Allows changing the color of a series.

Point selection / Highlight

Allows the selection and highlighting of a single point.

Can be used to remove, edit or display information about a point.

/* Code to enable point selection: */
plotOptions: {
    series: {
        allowPointSelect: true
    }
}
/* Code to get the selected points: */
var selectedPoints = chart.getSelectedPoints();

Example :

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px"></div>
<button id="button" class="autocompare">Get selected points</button>
var chart = Highcharts.chart('container', {
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },
    plotOptions: {
        series: {
            allowPointSelect: true
        }
    },
    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }]
});


/* the button action */
$('#button').click(function () {
    var selectedPoints = chart.getSelectedPoints();

    if (chart.lbl) {
        chart.lbl.destroy();
    }
    chart.lbl = chart.renderer.label('You selected ' + selectedPoints.length + ' points', 100, 60)
        .attr({
            padding: 10,
            r: 5,
            fill: Highcharts.getOptions().colors[1],
            zIndex: 5
        })
        .css({
            color: 'white'
        })
        .add();
});

Line width

/* Code to alter line width: */
series: [{
    data: [216.4, 194.1, 95.6],
    lineWidth: 5}],

Example :

<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px">
Highcharts.chart('container', {
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }, {
        data: [216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5],
        lineWidth: 5,
        color: 'red',
    }]
});

Stacking

Stacking allows series to be placed on top of each other without overlapping. (only for column and area type series)

See Stacking charts for more information.

Cursor

Allows the cursor to change appearence to indicate that points and series are clickable.

Data labels

Allows data labels to be displayed for each point of data in a series on the chart.

/* Code example showing how to enable datalabels: */
plotOptions: {
    line: {
        dataLabels: {
            enabled: true
        }
    }
},

The text displayed on datalabels may also be be customized by using the formatter option. (See API reference for more options.)

Note: You may wish to disable mouse tracking (highlights the series and points the mouse hovers over) (tooltips will not show if mouse tracking is disabled).

Example

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
Highcharts.chart('container', {
    chart: {
        type: 'line'
    },
    title: {
        text: 'Monthly Average Temperature'
    },
    subtitle: {
        text: 'Source: WorldClimate.com'
    },
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },
    yAxis: {
        title: {
            text: 'Temperature (°C)'
        }
    },
    plotOptions: {
        line: {
            dataLabels: {
                enabled: true
            },
            enableMouseTracking: false
        }
    },
    series: [{
        name: 'Tokyo',
        data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
    }, {
        name: 'London',
        data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
    }]
});

Dash style

Allows to use dashed lines instead of solid, there are several different dash options available.

/* Code to set dashed lines for a individual series (the dashStyle can also be set in plotOptions): */
series: [{
    data: [1, 3, 2, 4, 5, 4, 6, 2, 3, 5, 6],
    dashStyle: 'longdash'
}]

Example

Zones

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<div id="container" style="height: 400px"></div>
Highcharts.chart('container', {
    series: [{
        data: [-10, -5, 0, 5, 10, 15, 10, 10, 5, 0, -5],
        zones: [{
            value: 0,
            color: '#f7a35c'
        }, {
            value: 10,
            color: '#7cb5ec'
        }, {
            color: '#90ed7d'
        }]
    }]
});

There are two major approaches to scrollbars in Highcharts.

1. NATIVE SCROLLBARS FOR MOBILE

These scrollbars are applied by setting a scrollablePlotArea with a minWidth.

Chart.scrollablePlotArea

Options for a scrollable plot area.

provides a minimum width for the plot area of the chart.

  • if the width gets smaller than this, typically on mobile devices, a native browser scrollbar is presented below the chart.
  • this scrollbar is presented below the chart
  • this scrollbar provides smooth scrolling for the contents of the plot area, whereas the title, legend and axes are fixed.

minWidth : Number - The minimum width for the plot area. (default : undefined) scrollPositionX : Number - The initial scrolling position of the scrollable plot area. (default : undefined) (Ranges from 0 to 1 - 0 aligns to left, 1 aligns to right. Typically use 1 if the chart has right aligned Y axes.)

When the width of the plot area becomes less than this, it is applied to a separate div in the page, where native, smooth scrolling is applied, while the axes, titles, legend and other elements stay fixed.

This provides a great way to support long data series in a narrow mobile view.

See the effect below in a mobile browser or just a small desktop browser window.

<meta name="viewport" content="width=device-width, initial-scale=1" />

<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container"></div>
Highcharts.chart('container', {
    chart: {
        type: 'spline',
        scrollablePlotArea: {
            minWidth: 700,
            scrollPositionX: 1
        }
    },
    title: {
        text: 'Scrollable plot area'
    },
    subtitle: {
        text: 'Open on mobile and scroll sideways'
    },
    xAxis: {
        type: 'datetime',
        labels: {
            overflow: 'justify'
        }
    },
    yAxis: {
        tickWidth: 1,
        title: {
            text: 'Wind speed (m/s)'
        },
        lineWidth: 1,
        opposite: true
    },
    tooltip: {
        valueSuffix: ' m/s'
    },

    plotOptions: {
        spline: {
            lineWidth: 4,
            states: {
                hover: {
                    lineWidth: 5
                }
            },
            marker: {
                enabled: false
            },
            pointInterval: 3600000, // one hour
            pointStart: Date.UTC(2015, 4, 31, 0, 0, 0)
        }
    },
    series: [{
        name: 'Hestavollane',
        data: [0.2, 0.8, 0.8, 0.8, 1, 1.3, 1.5, 2.9, 1.9, 2.6, 1.6, 3, 4, 3.6,
            5.5, 6.2, 5.5, 4.5, 4, 3.1, 2.7, 4, 2.7, 2.3, 2.3, 4.1, 7.7, 7.1,
            5.6, 6.1, 5.8, 8.6, 7.2, 9, 10.9, 11.5, 11.6, 11.1, 12, 12.3, 10.7,
            9.4, 9.8, 9.6, 9.8, 9.5, 8.5, 7.4, 7.6]

    }, {
        name: 'Vik',
        data: [0, 0, 0.6, 0.9, 0.8, 0.2, 0, 0, 0, 0.1, 0.6, 0.7, 0.8, 0.6, 0.2,
            0, 0.1, 0.3, 0.3, 0, 0.1, 0, 0, 0, 0.2, 0.1, 0, 0.3, 0, 0.1, 0.2,
            0.1, 0.3, 0.3, 0, 3.1, 3.1, 2.5, 1.5, 1.9, 2.1, 1, 2.3, 1.9, 1.2,
            0.7, 1.3, 0.4, 0.3]
    }]
});
#container {
    max-width: 800px;
    min-width: 320px;
    height: 400px;
}

Result

2. AXIS SCROLLBARS THROUGH AN API OPTION

These scrollbars are enabled per axis and appear next to the axis. Scrollbars can be applied to any axis in Highstock.

The full documentation and available options can be seen in our API docs for Highstock.

Scrollbars are not limited to stock charts or Y axis. Using the highstock.js file, it can be applied to regular Highcharts axes too. See examples of:

Example

<div id="container" style="height: 400px; min-width: 320px; max-width: 600px; margin: 0 auto"></div>

<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
Highcharts.chart('container', {
    chart: {
        type: 'bar',
        marginLeft: 150
    },
    title: {
        text: 'Most popular ideas by April 2016'
    },
    subtitle: {
        text: 'Source: <a href="https://highcharts.uservoice.com/forums/55896-highcharts-javascript-api">UserVoice</a>'
    },
    xAxis: {
        type: 'category',
        title: {
            text: null
        },
        min: 0,
        max: 4,
        scrollbar: {
            enabled: true
        },
        tickLength: 0
    },
    yAxis: {
        min: 0,
        max: 1200,
        title: {
            text: 'Votes',
            align: 'high'
        }
    },
    plotOptions: {
        bar: {
            dataLabels: {
                enabled: true
            }
        }
    },
    legend: {
        enabled: false
    },
    credits: {
        enabled: false
    },
    series: [{
        name: 'Votes',
        data: [
            ["Gantt chart", 1000],
            ["Autocalculation and plotting of trend lines", 575],
            ["Allow navigator to have multiple data series", 523],
            ["Implement dynamic font size", 427],
            ["Multiple axis alignment control", 399],
            ["Stacked area (spline etc) in irregular datetime series", 309],
            ["Adapt chart height to legend height", 278],
            ["Export charts in excel sheet", 239],
            ["Toggle legend box", 235],
            ["Venn Diagram", 203],
            ["Add ability to change Rangeselector position", 182],
            ["Draggable legend box", 157],
            ["Sankey Diagram", 149],
            ["Add Navigation bar for Y-Axis in Highstock", 144],
            ["Grouped x-axis", 143],
            ["ReactJS plugin", 137],
            ["3D surface charts", 134],
            ["Draw lines over a stock chart, for analysis purpose", 118],
            ["Data module for database tables", 118],
            ["Draggable points", 117]
        ]
    }]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment