Highcharts Demo

author(s): Oystein Moseng

by koh_edwin

HTML

<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>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<div id="container"></div>

CSS

#container {
    max-width: 800px;
    height: 400px;
    margin: 1em auto;
}

caption {
	padding-bottom: 15px;
	font-family: 'Verdana';
	font-size: 1.2em;
	color:#555;
}

table {
	font-family: 'Verdana';
	font-size: 12pt;          
	border-collapse: collapse;
	border: 1px solid #EBEBEB;
	margin: 10px auto;
    text-align: center;
    width: 100%;
}

table tr:nth-child(odd) {
  background-color: #fff;
}

table tr:nth-child(even) {
  background-color: #FCF9F9;
}

th {
	font-weight: 600;
    padding: 10px;
}

JavaScript

// Custom announce formatter - only report if there is a new point and it is
// above 10. Returning empty string stops announcement, returning false uses
// default announcement.
function onAnnounce(updatedSeries, newSeries, newPoint) {
    return newPoint && newPoint.y > 5 ? 'Alert: ' + newPoint.y : '';
}

// Create the chart
Highcharts.chart('container', {
    title: {
        text: 'Live updating data'
    },
    subtitle: {
        text: 'Points above 10 trigger alert by screen reader'
    },
    caption: {
        text: 'A test case for dynamic data in charts.'
    },
    accessibility: {
        announceNewData: {
            enabled: true,
            interruptUser: true,
            minAnnounceInterval: 0,
            announcementFormatter: onAnnounce
        }
    },
    chart: {
        type: 'spline',
        events: {
            load: function () {
                // Set up the updating of the chart each second
                var series = this.series[0];
                setInterval(function () {
                    series.addPoint(
                        Math.round(Math.random() * 110) / 10,
                        true,
                        series.points.length > 20
                    );
                }, 2000);
            }
        }
    },
    yAxis: {
        min: 0,
        max: 12,
        plotLines: [{
            value: 10,
            width: 2,
            color: '#e33'
        }]
    },
    series: [{
        name: 'Random data',
        dataLabels: {
            enabled: true
        },
        data: [1.1]
    }]
});