Table-generated Highcharts Graph

v2

by amenadiel

HTML

<script src="http://www.gingahmail.com/economics/highcharts.js"></script>
<table id="comparison" class="tablesorter">
<thead>
    <tr>
<th>Equipo</th>
<th>Single CPU</th>
<th>Multi CPU</th>
<th>OpenGL</th>
    </tr>
</thead>
<tbody>
<tr>
<th>DV6 6620G</th>
<td>1792</td>
<td>6651</td>
<td>3481</td>
</tr>
    <tr>
<th>DV6 6750M</th>
<td>1792</td>
<td>6651</td>
<td>3598</td>
</tr>
<tr>
<th>Samsung R580</th>
<td>2795</td>
<td>6268</td>
<td>3350</td>
</tr>
<tr>
<th>Asus G51J</th>
<td>2937</td>
<td>8430</td>
<td>5794</td>
</tr>
</tbody>
</table><div id="container-comparison"></div>

CSS

table.tablesorter {
    font-family: arial;
    background-color: #cdcdcd;
    margin: 10px 0pt 5px;
    font-size: 8pt;
    width: 560px;
    text-align: left;
    color: #000000;
}
table.tablesorter thead th {
    background-color: #e6eeee;
    border: 1px solid #ffffff;
    padding: 4px;
}
table.tablesorter tbody th {
    background-color: #dadede;
    border: 1px solid #ffffff;
    padding: 4px;
}
table.tablesorter tbody td {
    color: #3d3d3d;
    padding: 4px;
    background-color: #ffffff;
}
table.tablesorter tbody tr.odd td {background-color:#f0f0f6;}

JavaScript

var charts = [],
    defaultOptions, options;

Highcharts.visualize = function(table, options) {

    // the categories
    options.xAxis.categories = [];

    $('tbody th', table).each(function(i) {
        options.xAxis.categories.push(this.innerHTML);
    });

    // the data series
    options.series = [];
    $('tr', table).each(function(i) {
        var tr = this;
        $('th, td', tr).each(function(j) {
            if (j > 0) { // skip first column
                if (i === 0) { // get the name and init the series
                    options.series[j - 1] = {
                        name: '   '+this.innerHTML,
                        data: []
                    };
                } else { // add values
                    options.series[j - 1].data.push(parseFloat(this.innerHTML));
                }
            }
        });
    });

    charts[charts.length] = new Highcharts.Chart(options);
};

defaultOptions = {
    chart:{
        renderTo: 'container-comparison',
        defaultSeriesType: 'bar',
        width: 580
    }, credits: {
        enabled: 0
    },
          xAxis: {
         
         labels: {
            rotation: -15,
            align: 'right',
            style: {
                font: 'normal 10px Verdana, sans-serif'
            }
         }
      },
        title: {
        text: 'Cinebench R10'
    },
    yAxis: {
        title: {
            text: 'Puntaje (más es mejor)',
            margin: 30
        }
    },
     tooltip: {
        formatter: function() {
            return '<b>' + this.series.name + '</b><br/>' + this.y + ' ' + this.x.toLowerCase();
        }
    },
    symbols: 'circle'
};



$(document).ready(function() {     Highcharts.visualize($('table#comparison'), defaultOptions); });