Highcharts Tutorial
Chart Types
To create a basic area 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 'x' and 'y' properties:
var data = [ { x: 1, y: 5 }, { x: 2, y: 3 }, { x: 3, y: 4 }, { x: 4, y: 7 }, { x: 5, y: 2 } ];
Highcharts.chart('chart-container', { chart: { type: 'area' }, title: { text: 'Basic Area 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 area 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 Area Chart:
Highcharts.chart('container', { chart: { type: 'area', backgroundColor: '#f2f2f2' }, plotOptions: { area: { fillColor: 'rgba(100, 180, 220, 0.5)', // Area color with opacity lineColor: '#64b4dc', // Line color lineWidth: 2 // Line width } }, series: [{ data: [10, 15, 7, 22, 11] }], // Other configuration options... });
Adding data to Highcharts Basic Area Chart:
series
array to create a Basic Area Chart.Highcharts.chart('container', { chart: { type: 'area' }, series: [{ data: [10, 15, 7, 22, 11] }], // Other configuration options... });
Stacked Basic Area Chart in Highcharts:
stacking
option.Highcharts.chart('container', { chart: { type: 'area' }, plotOptions: { area: { stacking: 'normal' // Stack areas 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 Area Chart using Highcharts:
grouping
option.Highcharts.chart('container', { chart: { type: 'area' }, plotOptions: { area: { grouping: false // Display areas 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 Area Chart:
Highcharts.chart('container', { chart: { type: 'area' }, plotOptions: { area: { marker: { enabled: true, // Show markers at data points radius: 4 // Marker size } } }, series: [{ data: [10, 15, 7, 22, 11] }], // Other configuration options... });