Highcharts Demo

author(s): Torstein Hønsi

HTML

<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 300px"></div>
<button id="title">Set title</button>
<button id="subtitle">Set subtitle</button>
<button id="color">New color</button>

JavaScript

$(function () {
    var chart = new Highcharts.Chart({
    
        chart: {
            renderTo: 'container'
        },
        
        subtitle: {
            text: 'Subtitle'
        },
    
        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]
        }]
    
    });
    
    var i = 1;
    $('#title').click(function() {
        chart.setTitle({ text: 'New title '+ i++ });
    });
    $('#subtitle').click(function() {
        var newTitle = 'New title '+ i++;
        if (i == 10)
            newTitle = ''; // error cause !!
        chart.setTitle(null, { text: newTitle });
    });
    $('#color').click(function() {
        chart.setTitle(
            { style: { color: 'red' }},
            { style: { color: 'green' }}
        );
    });
});