read series names from data table for the legend - Javascript highcharts

Javascript examples for highcharts:Chart Series

Description

read series names from data table for the legend

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <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  ww. j  a  va  2  s.co  m
var series = [{name: 'Car 1',data: [[1, 3],[4, 6],[7, 9]]},
              {name: 'Car 2',data: [[2, 3],[8, 10],[12, 18]]},
              {name: 'Car 3',data: [[5, 9],[1, 2]]}];
var data = [];
for(var i=0;i<series.length;i++) {
    for(var j=0;j<series[i].data.length;j++) {
         data.push({
             x: i,
             low: series[i].data[j][0],
             high: series[i].data[j][1],
             name: series[i].name
         });
    }
}
$('#container').highcharts({
    chart: {
        type: 'columnrange',
        inverted: true
    },
    plotOptions: {
        columnrange: {
            dataLabels: {
                enabled: false
            },
            grouping: false
        }
    },
    legend: {
        enabled: true
    },
    series: series
});
});

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/stock/highcharts-more.js"></script> 
      <div id="container" style="height: 400px"></div>  
   </body>
</html>

Related Tutorials