use html table as data source - Javascript highcharts

Javascript examples for highcharts:Chart Data

Description

use html table as data source

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </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> 
      <script src="https://code.highcharts.com/modules/export-data.js"></script> 
      <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div> 
      <table id="datatable"> 
         <thead> 
            <tr> 
               <th></th> 
               <th>Jane</th> 
            </tr> 
         </thead> 
         <tbody> 
            <tr> 
               <th>Apples</th> 
               <td>3</td> 
            </tr> 
            <tr> 
               <th>Pears</th> 
               <td>2</td> 
            </tr> 
            <tr> 
               <th>Plums</th> 
               <td>5</td> 
            </tr> 
            <tr> 
               <th>Bananas</th> 
               <td>1</td> 
            </tr> 
            <tr> 
               <th>Oranges</th> 
               <td>2</td> 
            </tr> 
         </tbody> 
      </table> 
      <script type="text/javascript">
Highcharts.chart('container', {
  data: {/*from w w  w.j av a2 s.  com*/
    table: document.getElementById('datatable')
  },
  chart: {
    type: 'pie',
    plotBackgroundColor: null,
    plotBorderWidth: null,
    plotShadow: false
  },
  legend: {
  },
  title: {
    text: 'Subject Breakdown'
  },
  tooltip: {
    pointFormat: '{point.name}: <b>{point.y}</b>',
    percentageDecimals: 1
  },
  plotOptions: {
    pie: {
      allowPointSelect: true,
      cursor: 'pointer',
      dataLabels: {
        enabled: false,
        color: '#000000',
        connectorColor: '#000000',
        formatter: function() {
          return '<b>' + this.point.name + '</b>: ' + this.y;
        },
      },
      showInLegend: true
    }
  }
});

      </script>  
   </body>
</html>

Related Tutorials