specify a range of data with <table> to create column chart - Javascript highcharts

Javascript examples for highcharts:Column Chart

Description

specify a range of data with <table> to create 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">
$(function () {//from  w w  w. j ava2s.c o  m
    $('#container').highcharts({
        data: {
            table: document.getElementById('datatable'),
            startColumn:0,
            endColumn:2
        },
        chart: {
            type: 'column'
        },
        title: {
            text: 'Data extracted from a HTML table in the page'
        },
        yAxis: {
            allowDecimals: false,
            title: {
                text: 'Units'
            }
        },
        tooltip: {
            formatter: function() {
                return '<b>'+ this.series.name +'</b><br/>'+
                    this.y +' '+ this.x.toLowerCase();
            }
        }
    });
});

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/modules/data.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> 
      <table id="datatable"> 
         <thead> 
            <tr> 
               <th></th> 
               <th>Jane</th> 
               <th>John</th> 
               <th>Jason</th> 
               <th>Mark</th> 
            </tr> 
         </thead> 
         <tbody> 
            <tr> 
               <th>Apples</th> 
               <td>3</td> 
               <td>4</td> 
               <td>5</td> 
               <td>6</td> 
            </tr> 
            <tr> 
               <th>Pears</th> 
               <td>2</td> 
               <td>0</td> 
               <td>5</td> 
               <td>6</td> 
            </tr> 
            <tr> 
               <th>Plums</th> 
               <td>5</td> 
               <td>11</td> 
               <td>5</td> 
               <td>6</td> 
            </tr> 
            <tr> 
               <th>Bananas</th> 
               <td>1</td> 
               <td>1</td> 
               <td>5</td> 
               <td>6</td> 
            </tr> 
            <tr> 
               <th>Oranges</th> 
               <td>2</td> 
               <td>4</td> 
               <td>5</td> 
               <td>6</td> 
            </tr> 
         </tbody> 
      </table>  
   </body>
</html>

Related Tutorials