Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dual x-axis on same line with Highcharts. Possible?

Tags:

highcharts

Can we create multiple x-axis chart like this using Highcharts? If yes, can someone please provide some pointers?

There are three year data displayed. i.e. 2010,2011, 2012

https://www.adr.com/DRDetails/CorporateActions?cusip=055622104

like image 594
hbthanki Avatar asked Oct 31 '25 20:10

hbthanki


2 Answers

The older answers didn't run for me in JSFiddle. Here is a working example, if it helps anyone:

http://jsfiddle.net/kPqKW/

$(function () {
    $('#container').highcharts({

        chart: {
            renderTo: 'container'
        },
        xAxis: [{
            type: 'datetime'
        }, {
            type: 'datetime',
            opposite: true
        }],

        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],
            pointStart: Date.UTC(2010, 0, 1),
            pointInterval: 24 * 3600 * 1000 // one day
        }, {
            data: [176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0],
            pointStart: Date.UTC(2010, 0, 10),
            pointInterval: 24 * 3600 * 1000, // one day
            xAxis: 1
        }]

    });
});
like image 183
omer schleifer Avatar answered Nov 04 '25 05:11

omer schleifer


Using highstocks (highcharts lesser known sibling), you can do something like what you're looking for. Check out this fiddle

$(function() {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?', function(data) {

    // split the data set into ohlc and volume
    var ohlc = [],
        volume = [],
        dataLength = data.length;

    for (i = 0; i < dataLength; i++) {
        ohlc.push([
            data[i][0], // the date
            data[i][1], // open
            data[i][2], // high
            data[i][3], // low
            data[i][4] // close
        ]);

        volume.push([
            data[i][0], // the date
            data[i][5] // the volume
        ])
    }

    // set the allowed units for data grouping
    var groupingUnits = [[
        'week',                         // unit name
        [1]                             // allowed multiples
    ], [
        'month',
        [1, 2, 3, 4, 6]
    ]];

    // create the chart
    $('#container').highcharts('StockChart', {

        rangeSelector: {
            selected: 1
        },

        title: {
            text: 'AAPL Historical'
        },

        yAxis: [{
            title: {
                text: 'OHLC'
            },
            height: 200,
            lineWidth: 2
        }, {
            title: {
                text: 'Volume'
            },
            top: 300,
            height: 100,
            offset: 0,
            lineWidth: 2
        }],

        series: [{
            type: 'area',
            name: 'AAPL',
            data: ohlc,
            dataGrouping: {
                units: groupingUnits
            }
        }, {
            type: 'area',
            name: 'Volume',
            data: volume,
            yAxis: 1,
            dataGrouping: {
                units: groupingUnits
            }
        }]
    });
});

});

like image 21
dardenfall Avatar answered Nov 04 '25 07:11

dardenfall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!