creating series for column chart - Javascript highcharts

Javascript examples for highcharts:Column Chart

Description

creating series for column 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">
    $(window).load(function(){/*from www .j  a va2  s  .c o  m*/
$(function (){
var objData =  {
    "1995":{
        "col1":300.75,
        "col2":1000,
        "col3":500},
    "1996":{
        "col1":300,
        "col2":400,
        "col3":900
    }
}
var series = [];
categories = [];
for (var key in objData) {
    var obj = objData[key];
    categories.push(key);
    for (var item in obj) {
        var targetSeries ;
        var bFound = false;
        for(var i=0; i< series.length; i++){
            if(item == series[i].name){
                bFound = true;
               targetSeries = series[i];
            }
        }
        if(!bFound) {
            targetSeries = {'name': item, 'data':[]};
            series.push(targetSeries);
        }
        var val = obj[item]
        targetSeries.data.push(val);
    }
}
console.log(series);
console.log(categories);
        $('#container').highcharts({
            chart: {
                type: 'column'
            },
            title: {
                text: 'Monthly Average Rainfall'
            },
            subtitle: {
                text: 'Source: WorldClimate.com'
            },
            xAxis: {
                categories: categories
            },
            yAxis: {
                min: 0,
                title: {
                    text: 'Years'
                }
            },
            tooltip: {
                headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                    '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
                footerFormat: '</table>',
                shared: true,
                useHTML: true
            },
            plotOptions: {
                column: {
                    pointPadding: 0.2,
                    borderWidth: 0
                }
            },
            series: series
        });
    });
    });

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