Highcharts Tutorial
Chart Types
To create an area chart using intervals and lines in Highcharts, you can follow these steps:
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="chart-container"></div>
var data = [ { x: 1, y: 5 }, { x: 2, y: 3, line: true }, { x: 3, y: 4 }, { x: 4, y: 7, line: true }, { x: 5, y: 2 } ];
Highcharts.chart('chart-container', { chart: { type: 'area' }, title: { text: 'Interval and Line Area Chart' }, xAxis: { type: 'category' }, yAxis: { title: { text: 'Value' } }, plotOptions: { area: { fillOpacity: 0.5, lineWidth: 2, marker: { enabled: false } } }, series: [{ name: 'Data', data: data, zones: data.map(item => item.line ? { dashStyle: 'solid' } : {}), color: 'blue' }], plotLines: [{ value: 2.5, color: 'red', dashStyle: 'solid', width: 2, label: { text: 'Interval' } }], plotBands: [{ from: 2.5, to: 4.5, color: 'lightgray', label: { text: 'Interval' } }] });
Note that we're using the 'zones' option to specify that the data points with 'line' set to true should be displayed as lines, and the 'plotLines' and 'plotBands' options to create the intervals and lines.
#chart-container { width: 100%; height: 500px; max-width: 800px; margin: 0 auto; }
This will create an area chart with intervals and lines 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 intervals in Highcharts Area Chart:
pointInterval
and pointStart
properties in the series configuration.Highcharts.chart('container', { chart: { type: 'area' }, series: [{ data: [1, 2, 3, 4, 5], pointStart: 10, // Start interval pointInterval: 2 // Interval between points }], // Other configuration options... });
Adding lines to Highcharts Area Chart:
lineWidth
property in the plotOptions.Highcharts.chart('container', { chart: { type: 'area' }, plotOptions: { area: { lineWidth: 2 // Width of the lines } }, series: [{ data: [1, 2, 3, 4, 5] }], // Other configuration options... });
Highcharts Area Chart with multiple series and lines:
Highcharts.chart('container', { chart: { type: 'area' }, series: [{ data: [1, 2, 3, 4, 5] }, { data: [5, 4, 3, 2, 1] }], // Other configuration options... });
Highcharts Area Chart interval styling:
zoneAxis
property in the series configuration.Highcharts.chart('container', { chart: { type: 'area' }, series: [{ data: [1, 2, 3, 4, 5], zoneAxis: 'x', zones: [{ value: 3, fillColor: 'rgba(255, 0, 0, 0.5)' // Styling for the interval }] }], // Other configuration options... });
Handling data points in Highcharts Area Chart with lines:
marker
property in the plotOptions.Highcharts.chart('container', { chart: { type: 'area' }, plotOptions: { area: { marker: { enabled: true, // Show markers radius: 5 // Marker size } } }, series: [{ data: [1, 2, 3, 4, 5] }], // Other configuration options... });
Configuring axis for Area Chart with intervals in Highcharts:
Highcharts.chart('container', { chart: { type: 'area' }, xAxis: { type: 'datetime', // Specify axis type tickInterval: 3600 * 1000 // Set tick interval for datetime axis }, series: [{ data: [[Date.UTC(2023, 0, 1), 1], [Date.UTC(2023, 0, 2), 2], [Date.UTC(2023, 0, 3), 3]] }], // Other configuration options... });
Interactive features in Highcharts Area Chart with lines:
Highcharts.chart('container', { chart: { type: 'area' }, plotOptions: { area: { dataLabels: { enabled: true // Show data labels } } }, series: [{ data: [1, 2, 3, 4, 5] }], // Other configuration options... });