Switched rows and columns

Description

The following code shows how to switched rows and columns.

Example


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript'>
$(function () {<!--from w w w .j av a 2s . c  o  m-->
    var options = {
        data: {
            table: document.getElementById('datatable'),
            switchRowsAndColumns: true
        },
        chart: {
            type: 'column'
        },
        yAxis: {
            allowDecimals: false,
            title: {
                text: 'Units'
            }
        }
    };

    $('#container').highcharts(Highcharts.merge(options));
    $('#toggle').click(function () {
        options.data.switchRowsAndColumns = !options.data.switchRowsAndColumns;
        $('#container').highcharts(Highcharts.merge(options));
    });
});
</script>
</head>
<body>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/data.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; max-width: 800px; margin: 0 auto"></div>

<div style="max-width: 800px; margin: 0 auto">
  <button id="toggle" style="margin: 10px">Toggle rows and columns</button>

  <table id="datatable">
    <thead>
      <tr>
        <th>Item</th>
        <th>A</th>
        <th>B</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th>CSS</th>
        <td>3</td>
        <td>4</td>
      </tr>
      <tr>
        <th>HTML</th>
        <td>2</td>
        <td>0</td>
      </tr>
      <tr>
        <th>XML</th>
        <td>5</td>
        <td>11</td>
      </tr>
      <tr>
        <th>Javascript</th>
        <td>1</td>
        <td>1</td>
      </tr>
      <tr>
        <th>SQL</th>
        <td>2</td>
        <td>4</td>
      </tr>
    </tbody>
  </table>
</div>
</body>
</html>

Click to view the demo





















Home »
  highcharts »
    Chart Setup »




3D Chart
Chart
Chart Style
Data
Event
Export
Legend
Title
Tooltip
Tooltip Format