Highcharts Demo

author(s): Torstein Hønsi

by koh_edwin

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>

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

CSS

#container {
  min-width: 310px;
  max-width: 800px;
  height: 400px;
  margin: 0 auto
}

JavaScript

let color = null,
  colorIndex = null,
  colors = ['rgba(200,150,168,0.5)', 'rgba(120,250,60,0.5)', 'rgba(40,250,208,0.5)', 'rgba(90,10,208,0.5)'];
Highcharts.chart('container', {
  title: {
    text: ''
  },

  colors: colors,
  yAxis: {
    title: {
      text: 'Number of Employees'
    }
  },
  legend: {
    align: 'center',
    verticalAlign: 'top'
  },

  plotOptions: {
    series: {
      pointStart: 2010,
      events: {
        mouseOver: function() {
          color = (colors[this.index]).replace('0.5', '1');
          colorIndex = this.index;
          this.chart.series[this.index].update({
            color: color
          });
        },
        mouseOut: function() {
          this.chart.series[this.index].update({
            color: colors[this.index]
          });
        }
      }
    }
  },

  series: [{
    name: 'Manufacturing',
    data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
  }, {
    name: 'Sales & Distribution',
    data: [11744, 17722, 16005, 29851, 20185, 24377, 32147, 39387]
  }, {
    name: 'Project Development',
    data: [null, null, 6988, 29851, 15112, 22452, 34400, 34227]
  }, {
    name: 'Other',
    data: [12908, 7948, 8405, 29851, 8989, 11816, 18274, 18111]
  }],
  tooltip: {
    useHTML: true,
    formatter: function() {
      s = '<b>' + this.points[0].key + '</b><br/>';

      this.points.forEach(function(point, index) {
        if (index !== colorIndex) {
          s += '<span style="color:' + point.color + ';margin-right:2px">\u25CF</span> <span style="color: #c6c6c6">' + point.series.name + ': <b>' + point.y + ' ' + '</b><br>';
        } else {
          s += '<span style="color:' + point.color + ';margin-right:2px">\u25CF</span> <span style="color: #000">' + point.series.name + ': <b>' + point.y + ' ' + '</b><br>';
        }
      });
      return s;
    },
    shared: true
  }

});