Bar chart with Stacked bar - Javascript highcharts

Javascript examples for highcharts:Bar Chart

Description

Bar chart with Stacked bar

Demo Code

ResultView the demo in separate window

<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() {/*  w  w  w.j av  a  2s  .  c  o  m*/
  var selected = null;
  $('#container').highcharts({
    chart: {
      type: 'column'
    },
    xAxis: {
      min: 0,
      categories: ['60', '61', '62', '63', '64', '65', '66', '67', '68', '69',
        '70', '71', '72', '73', '74', '75'
      ],
      title: {
        text: 'leeftijd'
      }
    },
    yAxis: {
      min: 0,
      title: {
        text: 'Inkomen'
      },
      stackLabels: {
        enabled: false,
        style: {
          fontWeight: 'bold',
          color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
        }
      }
    },
    legend: {
      align: 'right',
      x: -30,
      verticalAlign: 'top',
      y: 25,
      floating: true,
      backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
      borderColor: '#CCC',
      borderWidth: 0,
      shadow: false
    },
    tooltip: {
      headerFormat: '<b>{point.x}</b><br/>',
      pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}',
      enabled: false
    },
    plotOptions: {
      series: {
        cursor: 'pointer',
        pointPadding: 0,
        groupPadding: 0.01,
        point: {
          events: {
            click: function() {
              var point = this;
              if (point.category <= 63) return false;
              point.select(true, false)
              Highcharts.each(this.series.chart.series, function(series, ind) {
                  Highcharts.each(series.data, function(p, i) {
                    if (p.category == point.category) {
                      p.select(true, true)
                    }
                  })
                })
            },
          }
        },
        states: {
          select: {
            color: null,
            borderWidth: 20,
            borderColor: 'Blue'
          }
        }
      },
      column: {
        stacking: 'normal',
        dataLabels: {
          enabled: false,
          color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
          style: {
            textShadow: '0 0 3px black'
          }
        }
      },
    },
    series: [{
      name: 'John',
      data: [400, 500, 300, 200, 100, 100, 100, 100, 100, 500, 600, 600, 600, 600, 600]
    }, {
      name: 'Jane',
      data: [400, 500, 100, 300, 100, 100, 200, 300, 200, 200, 600, 600, 600, 600, 600]
    }, {
      name: 'Joe',
      data: [400, 500, 100, 300, 100, 100, 200, 300, 200, 200, 600, 600, 600, 600, 600]
    }]
  });
});

      </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>

Related Tutorials