Highcharts Tutorial
Chart Types
To create a basic pie chart using Highcharts, you can follow these steps:
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="chart-container"></div>
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: 'pie' }, title: { text: 'Basic Pie Chart' }, series: [{ name: 'Data', data: data }] });
Note that we're using the 'data' option to specify the data for the chart.
#chart-container { width: 100%; height: 500px; max-width: 800px; margin: 0 auto; }
This will create a basic pie 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 Pie Chart:
Highcharts.chart('container', { chart: { type: 'pie', backgroundColor: '#f2f2f2', plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: true, format: '<b>{point.name}</b>: {point.percentage:.1f}%' } } }, series: [{ data: [{ name: 'Category 1', y: 45.0 }, { name: 'Category 2', y: 26.8 }, { name: 'Category 3', y: 12.8 }] }], // Other configuration options... });
Adding data to Highcharts Basic Pie Chart:
series
array to create a Basic Pie Chart.Highcharts.chart('container', { chart: { type: 'pie' }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: true, format: '<b>{point.name}</b>: {point.percentage:.1f}%' } } }, series: [{ data: [{ name: 'Category 1', y: 45.0 }, { name: 'Category 2', y: 26.8 }, { name: 'Category 3', y: 12.8 }] }], // Other configuration options... });
Nested Basic Pie Chart in Highcharts:
Highcharts.chart('container', { chart: { type: 'pie' }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: true, format: '<b>{point.name}</b>: {point.percentage:.1f}%' } } }, series: [{ name: 'Category 1', data: [{ name: 'Subcategory 1.1', y: 25.0 }, { name: 'Subcategory 1.2', y: 20.0 }] }, { name: 'Category 2', data: [{ name: 'Subcategory 2.1', y: 15.0 }, { name: 'Subcategory 2.2', y: 10.0 }] }], // Other configuration options... });
Exploded Basic Pie Chart using Highcharts:
Highcharts.chart('container', { chart: { type: 'pie' }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: true, format: '<b>{point.name}</b>: {point.percentage:.1f}%' }, slicedOffset: 10 // Explode slices by a specified offset } }, series: [{ data: [{ name: 'Category 1', y: 45.0, sliced: true }, { name: 'Category 2', y: 26.8 }, { name: 'Category 3', y: 12.8 }] }], // Other configuration options... });
Interactive features in Highcharts Basic Pie Chart:
Highcharts.chart('container', { chart: { type: 'pie' }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: true, format: '<b>{point.name}</b>: {point.percentage:.1f}%' } } }, series: [{ data: [{ name: 'Category 1', y: 45.0 }, { name: 'Category 2', y: 26.8 }, { name: 'Category 3', y: 12.8 }] }], // Other configuration options... });