Custom Funnel in scatter chart - Javascript highcharts

Javascript examples for highcharts:Scatter Chart

Description

Custom Funnel in scatter chart

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() {/*from w  ww  . j  a  v a 2s . c o m*/
  var rawData = [7, 14, 16, 5, 4],
    data = [
      [0, 100]
    ],
    overData = [
      [0, 0]
    ],
    underData = [
      [0, 0]
    ],
    zones = [],
    len = rawData.length,
    colors = Highcharts.getOptions().colors,
    maxColor = colors.length,
    i, val, sum = 0,
    pos = 0;
  for (i = 0; i < len; i++) {
    sum += rawData[i];
  }
  for (i = 0; i < len; i++) {
    pos += rawData[i];
    val = (sum - pos) / sum * 100;
    data.push([pos, val]);
    overData.push([pos, (100 - val) / 2]);
    underData.push([pos, (100 - val) / 2]);
    zones.push({
      value: pos,
      color: colors[i % maxColor]
    });
  }
  $('#container').highcharts({
    chart: {
      type: 'area'
    },
    yAxis: {
      title: {
        text: 'Percent'
      }
    },
    plotOptions: {
      area: {
        enableMouseTracking: false,
        showInLegend: false,
        stacking: 'percent',
        lineWidth: 0,
        marker: {
          enabled: false
        }
      }
    },
    series: [{
      name: 'over',
      color: 'none',
      data: overData
    }, {
      id: 's1',
      name: 'Series 1',
      data: data,
      showInLegend: true,
      zoneAxis: 'x',
      zones: zones
    }, {
      name: 'under',
      color: 'none',
      data: underData
    }, {
       type: 'scatter',
      lineWidth: 2,
      dashStyle: 'longDash',
      marker: {
         enabled: false
      },
      data: [[0,80],[7,80],[0,null],[0,30],[7,30]]
    }]
  });
});

      </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; max-width: 800px; margin: 0 auto"></div>  
   </body>
</html>

Related Tutorials