Waterfall

author(s): Torstein Hønsi

by Mukesh Kumar

HTML

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; max-width: 600px; height: 400px; margin: 0 auto"></div>

CSS

.flex-parent {
  display: flex;
  width: 300px;
  height: 20px;
  align-items: center;
}

.flex-child-edge {
  flex-grow: 2;
  height: 1px;
  background-color: #000;
  border: 0px #000 solid;
}

.flex-child-text {
  flex-basis: auto;
  flex-grow: 0;
  margin: 0px 5px 0px 5px;
  text-align: center;
}

JavaScript

var htmlContent = `<div class="flex-parent">
<div class="flex-child-edge"></div>
<div class="flex-child-text">Aggregate Value</div>
<div class="flex-child-edge"></div>
</div>`;

Highcharts.chart('container', {
  chart: {
    type: 'waterfall'
  },

  title: {
    text: 'Highcharts Waterfall'
  },

  xAxis: {
    type: 'category',
    tickWidth: 1,
    tickLength: 30,
    title: {
      enabled: true,
      useHTML: true,
      text: htmlContent,

    }
  },

  yAxis: {
    title: {
      text: 'USD'
    }
  },

  legend: {
    enabled: false
  },

  tooltip: {
    pointFormat: '<b>${point.y:,.2f}</b> USD'
  },

  series: [{
    upColor: 'green',
    color: 'red',
    data: [{
      name: 'a',
      y: 60
    }, {
      name: 'b',
      y: 100
    }, {
      name: 'c',
      y: 50
    }, {
      name: 'd',
      isIntermediateSum: true,
      color: 'blue'
    }, {
      name: 'e',
      y: -20
    }, {
      name: 'f',
      y: -80
    }, {
      name: 'h',
      isSum: true,
      color: 'yellow'
    }],
    dataLabels: {
      enabled: true
    },
    pointPadding: 0
  }]
});