Highcharts test tool

by Sajeetharan Sinnathurai

HTML

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container"></div>

CSS

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

JavaScript

var UNDEFINED;

Highcharts.Axis.prototype.defaultLabelFormatter = function () {
    var axis = this.axis,
        value = this.value,
        categories = axis.categories,
        dateTimeLabelFormat = this.dateTimeLabelFormat,
        numericSymbols = Highcharts.getOptions().lang.numericSymbols,
        i = numericSymbols && numericSymbols.length,
        multi,
        ret,
        formatOption = axis.options.labels.format,

        // make sure the same symbol is added for all labels on a linear axis
        numericSymbolDetector = axis.isLog ? value : axis.tickInterval;

    if (formatOption) {
        ret = Highcharts.format(formatOption, this);

    } else if (categories) {
        ret = value;

    } else if (dateTimeLabelFormat) { // datetime axis
        ret = Highcharts.dateFormat(dateTimeLabelFormat, value);

    } else if (i && numericSymbolDetector >= 1000) {
        // Decide whether we should add a numeric symbol like k (thousands) or M (millions).
        // If we are to enable this in tooltip or other places as well, we can move this
        // logic to the numberFormatter and enable it by a parameter.
        while (i-- && ret === UNDEFINED) {
            multi = Math.pow(1000, i + 1);
            if (numericSymbolDetector >= multi / 10 && numericSymbols[i] !== null) {
                ret = Highcharts.numberFormat(value / multi, -1) + numericSymbols[i];
            }
        }
    }

    if (ret === UNDEFINED) {
        if (mathAbs(value) >= 10000) { // add thousands separators
            ret = numberFormat(value, 0);

        } else { // small numbers
            ret = numberFormat(value, -1, UNDEFINED, ''); // #2466
        }
    }

    return ret;
},

$('#container').highcharts({

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

    series: [{
        data: [9500000, 9000000]
    }]

});