show categorized Chart using csv file - Javascript highcharts

Javascript examples for highcharts:Chart CSV Data

Description

show categorized Chart using csv file

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> 
      <style id="compiled-css" type="text/css">

pre {/*from   w ww.j  a v  a  2s. c  om*/
   display: none;
}


      </style> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div> 
      <pre id="csv">x, y, categories
2, 2, 0,
3, 2, 1
4, 3, 0,
1, 4, 2
3, 2, 1,
1, 3, 2</pre> 
      <script type="text/javascript">
var csv = document.getElementById('csv').innerText;
var rows = csv.split('\n');
var series = [];
rows.forEach(row => {
  var cells = row.split(',').map(Number);
  var serie = series[cells[2]];
  if (!serie) {
    serie = series[cells[2]] = {data: []};
  }
  serie.data.push([cells[0], cells[1]]);
})
Highcharts.chart('container', {
  chart: {
    type: 'scatter'
  },
  series: series
});

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

Related Tutorials