Highcharts Stock Demo

author(s): Torstein Hønsi

by Torstein Hønsi

HTML

<div id="container" style="height: 400px; min-width: 600px"></div>
<div class="info">Weekends should appear as gaps in the graph.</div>

<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<script type="text/javascript" src="https://www.highcharts.com/samples/data/usdeur.js"></script>

CSS

.info {
    font: 0.7em sans-serif;
    padding: 0.5em;
    margin: 0.5em;
    background: #FCFFC5;
    border-radius: 0.5em;
    border: 1px solid gray;
}
.info:before {
    content: 'i';
    margin: 0.5em;
    font: 1.5em serif bold;
    font-style: italic;
    color: green;
}

JavaScript

$(function () {
	// Make the gapSize option use absolute X values instead of relative
	Highcharts.wrap(Highcharts.Series.prototype, 'getSegments', function (proceed) {
    	var closestPointRange = this.xAxis.closestPointRange;
        this.xAxis.closestPointRange = 1;
        proceed.call(this);
        this.xAxis.closestPointRange = closestPointRange;
    });
    $('#container').highcharts('StockChart', {

        rangeSelector: {
            selected: 1
        },

        plotOptions: {
            line: {
                gapSize: 24 * 36e5 // one day
            }
        },

        series: [{
            name: 'USD to EUR',
            data: usdeur
        }]
    });
});