JSFiddle - React, Tailwind, and code Playground

by mark47

HTML

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://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 class="cat">1</th>
              <th class="cat">2</th>
              <th class="cat">3</th>
              <th class="cat">4</th>
              <th class="cat">5</th>
              <th class="cat">6</th>
              <th class="cat">7</th>
              <th class="cat">8</th>
            </tr> 
          </thead> 
          <tbody>
            <tr class="data">
              <td>Suspected</td>
              <td>60</td>
              <td>70</td>
              <td>82</td>
              <td>55</td>
              <td>40</td>
              <td>47</td>
              <td>59</td>
              <td>47</td>
            </tr> 
            <tr>
              <td>Confirmed</td>
              <td>40</td>
              <td>22</td>
              <td>30</td>
              <td>16</td>
              <td>36</td>
              <td>20</td>
              <td>21</td>
              <td>30</td>
            </tr>
          </tbody>
        </table>

JavaScript

$(function() {
    // On document ready, call visualize on the datatable.
    $(document).ready(function() {
        /**
         * Visualize an HTML table using Highcharts. The top (horizontal) header
         * is used for series names, and the left (vertical) header is used
         * for category names. This function is based on jQuery.
         * @param {Object} table The reference to the HTML table to visualize
         * @param {Object} options Highcharts options
         */
        Highcharts.visualize = function(table, options) {
            // the categories
            options.xAxis.categories = [];
            $('thead tr th.cat', table).each(function(i, index) {
                //console.log('boog');
                options.xAxis.categories.push(index.innerHTML);
            });
            console.log(options.xAxis.categories);
            // the data series
            options.series = [];
            $('tbody tr', table).each(function(i) {
                $(this).children('td').each(function(j, item) {
                    if (j == 0) { // get the name and init the series
                        options.series[j] = {
                            name: item.innerHTML,
                            data: []
                        } else { // add values
                            options.series[j].data.push(parseFloat(item.innerHTML));
                        }
                    }
                                            console.log(options.series[j].name);
                });
            });
            var chart = new Highcharts.Chart(options);
        }

        var table = document.getElementById('datatable'),
            options = {
                chart: {
                    renderTo: 'container',
                    type: 'line'
                },
                title: {
                    text: 'Data extracted from a HTML table in the page'
                },
                xAxis: {},
                yAxis: {
                    title:...