Javascript examples for highcharts:Column Chart
Proper x-axis for stack group column chart
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> <script type="text/javascript"> $(function () {// ww w . jav a 2s . co m var options = { chart: { type: 'column' }, title: { text: 'Total fruit consumtion, grouped by year' }, xAxis: [{ categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas'] }, { categories: ['2014', '2015', '2014', '2015', '2014', '2015','2014', '2015', '2014', '2015'], opposite: true }], yAxis: { allowDecimals: false, min: 0, title: { text: 'Number of fruits' } }, tooltip: { formatter: function () { return '<b>' + this.x + ' ' + this.series.options.stack + '</b><br/>' + this.series.name + ': ' + this.y + '<br/>' + 'Total: ' + this.point.stackTotal; } }, plotOptions: { column: { stacking: 'normal' } }, series: [{ name: 'John', color: '#ff4400', data: [5, 3, 4, 7, 2], stack: '2014', }, { name: 'Joe', color: '#44ff00', data: [3, 4, 4, 2, 5], stack: '2014', }, { name: 'John', color: '#ff4400', data: [2, 5, 6, 2, 1], showInLegend: false, stack: '2015' }, { name: 'Joe', data: [3, 0, 4, 4, 3], color: '#44ff00', showInLegend: false, stack: '2015' }, { name: '', data: [0, 0, 0,0, 0, 0,0, 0, 0,0], showInLegend: false, stack: '2015', xAxis: 1 }] }; var onLegendClick= function (event) { var myname = this.name; var myvis = !this.visible; this.chart.series.forEach( function (elem) { if (elem.name == myname) { elem.setVisible(myvis); } }); return false; } options.series.forEach(function (serie) { serie.events = { legendItemClick : onLegendClick} ; }); $('#container').highcharts(options); }); </script> </head> <body> <script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/modules/exporting.js"></script> <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div> </body> </html>