Highcharts Tutorial
Chart Types
To create a column chart using HTML table data with Highcharts, you can follow these steps:
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="chart-container"></div>
<table id="data-table"> <thead> <tr> <th>Month</th> <th>Apples</th> <th>Oranges</th> <th>Bananas</th> </tr> </thead> <tbody> <tr> <td>January</td> <td>5</td> <td>3</td> <td>4</td> </tr> <tr> <td>February</td> <td>7</td> <td>2</td> <td>6</td> </tr> <tr> <td>March</td> <td>3</td> <td>6</td> <td>5</td> </tr> </tbody> </table>
var categories = []; var seriesData = []; $('#data-table tbody tr').each(function(i) { var $row = $(this); var month = $row.find('td:first-child').text(); categories.push(month); $row.find('td:not(:first-child)').each(function(j) { var $cell = $(this); var value = parseInt($cell.text(), 10); if (seriesData.length <= j) { seriesData.push({ name: $cell.attr('data-name'), data: [] }); } seriesData[j].data.push(value); }); });
Note that we're using jQuery to select the table elements and iterate over the rows and columns. We're also using the 'data-name' attribute on the table cells to set the series names.
Highcharts.chart('chart-container', { chart: { type: 'column' }, title: { text: 'Column Chart with HTML Table Data' }, xAxis: { categories: categories }, yAxis: { title: { text: 'Value' } }, series: seriesData });
Note that we're using the extracted data to set the categories and series data for the chart.
#chart-container { width: 100%; height: 500px; max-width: 800px; margin: 0 auto; }
Highcharts Column Chart with dynamic HTML table data:
<div id="container"></div> <table id="dataTable"> <thead> <tr> <th>Category</th> <th>Data Point</th> </tr> </thead> <tbody> <tr> <td>Category 1</td> <td>10</td> </tr> <tr> <td>Category 2</td> <td>15</td> </tr> <!-- Additional rows... --> </tbody> </table> <script> // Fetch data from HTML table and create Highcharts Column Chart const tableData = []; $('#dataTable tbody tr').each(function () { const category = $(this).find('td:eq(0)').text(); const dataPoint = parseInt($(this).find('td:eq(1)').text(), 10); tableData.push([category, dataPoint]); }); Highcharts.chart('container', { chart: { type: 'column' }, title: { text: 'Column Chart from HTML Table Data' }, xAxis: { categories: tableData.map(item => item[0]) }, series: [{ name: 'Data Points', data: tableData.map(item => item[1]) }], // Other configuration options... }); </script>
Convert HTML table data to Highcharts Column Chart:
<!-- HTML table and container div --> <div id="container"></div> <table id="dataTable"> <!-- Table content... --> </table> <script> // JavaScript code to convert HTML table data to Highcharts Column Chart // Refer to the previous example for the conversion logic. </script>
Highcharts Column Chart with JSON data from HTML table:
<!-- HTML table and container div --> <div id="container"></div> <table id="dataTable"> <!-- Table content... --> </table> <script> // JavaScript code to convert HTML table data to JSON const jsonData = []; $('#dataTable tbody tr').each(function () { const category = $(this).find('td:eq(0)').text(); const dataPoint = parseInt($(this).find('td:eq(1)').text(), 10); jsonData.push({ category, dataPoint }); }); Highcharts.chart('container', { chart: { type: 'column' }, title: { text: 'Column Chart from JSON Data' }, xAxis: { categories: jsonData.map(item => item.category) }, series: [{ name: 'Data Points', data: jsonData.map(item => item.dataPoint) }], // Other configuration options... }); </script>
Interactive Highcharts Column Chart with HTML table integration:
<!-- HTML table and container div --> <div id="container"></div> <table id="dataTable"> <!-- Table content... --> </table> <script> // JavaScript code to create an interactive Highcharts Column Chart const tableData = []; $('#dataTable tbody tr').each(function () { const category = $(this).find('td:eq(0)').text(); const dataPoint = parseInt($(this).find('td:eq(1)').text(), 10); tableData.push([category, dataPoint]); }); Highcharts.chart('container', { chart: { type: 'column' }, title: { text: 'Interactive Column Chart from HTML Table Data' }, xAxis: { categories: tableData.map(item => item[0]) }, series: [{ name: 'Data Points', data: tableData.map(item => item[1]), point: { events: { click: function () { alert('Clicked on ' + this.category); } } } }], tooltip: { formatter: function () { return '<b>' + this.category + '</b><br>' + 'Data Point: ' + this.y; } }, // Other configuration options... }); </script>
Customizing appearance of Highcharts Column Chart from HTML table:
<!-- HTML table and container div --> <div id="container"></div> <table id="dataTable"> <!-- Table content... --> </table> <script> // JavaScript code to create a custom-styled Highcharts Column Chart const tableData = []; $('#dataTable tbody tr').each(function () { const category = $(this).find('td:eq(0)').text(); const dataPoint = parseInt($(this).find('td:eq(1)').text(), 10); tableData.push([category, dataPoint]); }); Highcharts.chart('container', { chart: { type: 'column', backgroundColor: '#f2f2f2' }, title: { text: 'Styled Column Chart from HTML Table Data' }, xAxis: { categories: tableData.map(item => item[0]) }, series: [{ name: 'Data Points', data: tableData.map(item => item[1]), color: '#64b4dc' // Column color }], // Other configuration options... }); </script>
Adding tooltips to Highcharts Column Chart from HTML table:
<!-- HTML table and container div --> <div id="container"></div> <table id="dataTable"> <!-- Table content... --> </table> <script> // JavaScript code to create Highcharts Column Chart with tooltips const tableData = []; $('#dataTable tbody tr').each(function () { const category = $(this).find('td:eq(0)').text(); const dataPoint = parseInt($(this).find('td:eq(1)').text(), 10); tableData.push([category, dataPoint]); }); Highcharts.chart('container', { chart: { type: 'column' }, title: { text: 'Column Chart with Tooltips from HTML Table Data' }, xAxis: { categories: tableData.map(item => item[0]) }, series: [{ name: 'Data Points', data: tableData.map(item => item[1]) }], tooltip: { formatter: function () { return '<b>' + this.category + '</b><br>' + 'Data Point: ' + this.y; } }, // Other configuration options... }); </script>
Updating Highcharts Column Chart dynamically with HTML table changes:
<!-- HTML table and container div --> <div id="container"></div> <table id="dataTable"> <!-- Table content... --> </table> <script> // JavaScript code to dynamically update Highcharts Column Chart function updateChart() { const updatedData = []; $('#dataTable tbody tr').each(function () { const category = $(this).find('td:eq(0)').text(); const dataPoint = parseInt($(this).find('td:eq(1)').text(), 10); updatedData.push([category, dataPoint]); }); chart.update({ xAxis: { categories: updatedData.map(item => item[0]) }, series: [{ data: updatedData.map(item => item[1]) }] }); } // Initial chart creation const tableData = []; $('#dataTable tbody tr').each(function () { const category = $(this).find('td:eq(0)').text(); const dataPoint = parseInt($(this).find('td:eq(1)').text(), 10); tableData.push([category, dataPoint]); }); const chart = Highcharts.chart('container', { chart: { type: 'column' }, title: { text: 'Dynamic Column Chart from HTML Table Data' }, xAxis: { categories: tableData.map(item => item[0]) }, series: [{ name: 'Data Points', data: tableData.map(item => item[1]) }], // Other configuration options... }); // Example: Trigger the update on button click $('#updateButton').click(function () { updateChart(); }); </script>
Highcharts Column Chart using tabular data in HTML:
<!-- HTML table and container div --> <div id="container"></div> <table id="dataTable"> <!-- Table content... --> </table> <script> // JavaScript code to create Highcharts Column Chart from HTML table Highcharts.chart('container', { chart: { type: 'column' }, title: { text: 'Column Chart from HTML Table' }, xAxis: { categories: $('#dataTable tbody tr').map(function () { return $(this).find('td:eq(0)').text(); }).get() }, series: [{ name: 'Data Points', data: $('#dataTable tbody tr').map(function () { return parseInt($(this).find('td:eq(1)').text(), 10); }).get() }], // Other configuration options... }); </script>