Stack column chart Display Average of all values - Javascript highcharts

Javascript examples for highcharts:Column Chart

Description

Stack column chart Display Average of all values

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://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
      <script type="text/javascript">
$(function() {//from w  w  w .  j  a va  2s. c o m
    var chart;
    var seriesData =  [{
                name: 'Incomplete',
                data: [1, 3, 4, 7, 20]
            }, {
                name: 'Complete',
                data: [3, 4, 4, 2, 5]
            }];
  var total = 0;
   $.each(seriesData,function(item){
    $.each(seriesData[item].data,function() {
     total += this;
});
  });
  console.log("total is"+total);
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'column'
            },
            title: {
                text: 'Stacked bar chart'
            },
            xAxis: {
                categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
            },
            yAxis: {
                stackLabels: {
                    style: {
                        color: 'black'
                    },
                    enabled: true,
                    formatter: function() {
                        return ( this.total/ total * 100).toPrecision(2) + '%';
                    }
                }
            },
            tooltip: {
                formatter: function() {
                    return '' + this.series.name + ': ' + this.y + '';
                }
            },
            plotOptions: {
                series: {
                    stacking: 'normal'
                }
            },
                series:seriesData
        });
});

      </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: 400px; height: 400px; margin: 0 auto"></div>  
   </body>
</html>

Related Tutorials