Highcharts Stock Demo

author(s): Torstein Hønsi

by lizozomi

HTML

<div id="container"></div>

<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<script src="https://www.highcharts.com/samples/data/three-series-1000-points.js"></script>

CSS

#container {
    height: 400px;
    min-width: 600px;
}

JavaScript

Highcharts.stockChart('container', {

    chart: {
        width: 800
    },

    rangeSelector: {
        selected: 4
    },

    plotOptions: {
        series: {
            dataGrouping: {
                forced: true,
                units: [
                    ['week', [1]]
                ]
            }
        }
    },

    series: [{
        name: 'ADBE',
        data: ADBE,
        dataGrouping: {
            type: 'column'
        },
        tooltip: {
            valueDecimals: 2
        }
    }, {
        name: 'Data point count (confidence)',
        data: ADBE,
        dataGrouping: {
            approximation: function () {
                const start = this.dataGroupInfo.start;

                console.log(
                    'dataGroupInfo:',
                    this.dataGroupInfo,
                    'Raw data:',
                    this.options.data.slice(
                        start,
                        start + this.dataGroupInfo.length
                    )
                );

                // Individual point options can be applied to the grouped points
                if (this.dataGroupInfo.length < 5) {
                    this.dataGroupInfo.options = {
                        color: '#FF0000'
                    };
                }

                // We want the number of points to represent the value
                return this.dataGroupInfo.length;
            },
            forced: true
        },
        type: 'column'
    }]
});