Jugal | Custom Tick Intervals | Highchart & Highstock

http://stackoverflow.com/questions/11826625/tickinterval-doesnt-work-properly-in-highchart-and-highstock/11827205#11827205 Jugal Thakkar http://jugal.me/

by Jugal Thakkar

HTML

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js" ></script>
<script type="text/javascript" src="http://code.jugal.me/js/jugalsLib.js" ></script>
<script type="text/javascript" src="http://code.highcharts.com/stock/highstock.src.js" ></script>
<script type="text/javascript" src="http://code.highcharts.com/stock/modules/exporting.src.js" ></script>

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

CSS

#container{
    min-width:500px;
}

JavaScript

//http://stackoverflow.com/questions/11826625/tickinterval-doesnt-work-properly-in-highchart-and-highstock/11827205#11827205
Highcharts.Axis.prototype.defaultOptions.units = [[
    'millisecond',
    [1, 2, 5, 10, 20, 25, 30, 40, 50, 100, 200, 500]
    ], [
    'second',
    [1, 2, 5, 10, 15, 30]
    ], [
    'minute',
    [1, 2, 5, 10, 15, 30]
    ], [
    'hour',
    [1, 2, 3, 4, 6, 8, 12]
    ], [
    'day',
    [1]
    ], [
    'week',
    [1]
    ], [
    'month',
    [1, 3, 6]
    ], [
    'year',
    null
    ]];

var chartingOptions = {
    chart: {
        renderTo: 'container'
    },
    xAxis: {
        tickInterval: 40, 
        // By default 40 would have been rounded off to 50
        // Hack allows using tick intervals like 40, etc
        gridLineWidth: 1
    }
};


chartingOptions = $.extend({}, jugalsLib.getBasicChartOptions(1,{
            sampleCount: 200,
            interval: 1
        }), chartingOptions);
var chart = new Highcharts.StockChart(chartingOptions);