Highcharts Tutorial
Chart Types
To create a basic bar chart using Highcharts, you can follow these steps:
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="chart-container"></div>
var data = [5, 3, 4, 7, 2];
Or, here's an array of objects with 'name' and 'y' properties:
var data = [ { name: 'Apples', y: 5 }, { name: 'Oranges', y: 3 }, { name: 'Bananas', y: 4 }, { name: 'Pears', y: 7 }, { name: 'Grapes', y: 2 } ];
Highcharts.chart('chart-container', { chart: { type: 'bar' }, title: { text: 'Basic Bar Chart' }, xAxis: { type: 'category' }, yAxis: { title: { text: 'Value' } }, series: [{ name: 'Data', data: data }] });
Note that we're using the 'data' option to specify the data for the chart, and the 'xAxis' option to set the type of the x-axis to 'category'.
#chart-container { width: 100%; height: 500px; max-width: 800px; margin: 0 auto; }
This will create a basic bar chart using the specified data and options, and render it in the 'chart-container' element on your web page. You can customize the chart further by adjusting the options and adding additional features, like tooltips, legends, and labels.
Customizing appearance in Highcharts Basic Bar Chart:
Highcharts.chart('container', { chart: { type: 'bar', backgroundColor: '#f2f2f2' }, plotOptions: { bar: { color: '#64b4dc', // Bar color borderWidth: 1, // Border width borderColor: '#3582c4', // Border color pointWidth: 20 // Bar width } }, series: [{ data: [10, 15, 7, 22, 11] }], // Other configuration options... });
Adding data to Highcharts Basic Bar Chart:
series
array to create a Basic Bar Chart.Highcharts.chart('container', { chart: { type: 'bar' }, series: [{ data: [10, 15, 7, 22, 11] }], // Other configuration options... });
Stacked Basic Bar Chart in Highcharts:
stacking
option.Highcharts.chart('container', { chart: { type: 'bar' }, plotOptions: { bar: { stacking: 'normal' // Stack bars on top of each other } }, series: [{ name: 'Series 1', data: [10, 15, 7, 22, 11] }, { name: 'Series 2', data: [5, 10, 5, 15, 7] }], // Other configuration options... });
Grouped Basic Bar Chart using Highcharts:
grouping
option.Highcharts.chart('container', { chart: { type: 'bar' }, plotOptions: { bar: { grouping: false // Display bars side by side } }, series: [{ name: 'Series 1', data: [10, 15, 7, 22, 11] }, { name: 'Series 2', data: [5, 10, 5, 15, 7] }], // Other configuration options... });
Interactive features in Highcharts Basic Bar Chart:
Highcharts.chart('container', { chart: { type: 'bar' }, plotOptions: { bar: { dataLabels: { enabled: true, // Show data labels format: '{y}' // Data label format } } }, series: [{ data: [10, 15, 7, 22, 11] }], // Other configuration options... });