Highcharts Tutorial
Chart Types
To create a curve chart with data labels in Highcharts, you can follow these steps:
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="chart-container"></div>
Highcharts.chart('chart-container', { chart: { type: 'spline' }, title: { text: 'Curve Chart with Data Labels' }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] }, yAxis: { title: { text: 'Temperature (��C)' } }, series: [{ name: 'Tokyo', data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6], marker: { enabled: true, radius: 4 }, dataLabels: { enabled: true, format: '{y}��C', style: { fontSize: '12px', color: '#000000', textOutline: false } } }] });
In this example, we're creating a spline chart with the Highcharts chart
function and passing in a set of options:
chart.type
is set to 'spline'
to create a curve charttitle.text
is set to 'Curve Chart with Data Labels'
to set the main titlexAxis.categories
is set to an array of month names to set the x-axis labelsyAxis.title.text
is set to 'Temperature (��C)'
to set the y-axis labelseries
is set to an array with one object containing name
, data
, and marker
and dataLabels
properties to set the chart data and styling optionsmarker
is set to enable data point markers with a radius of 4dataLabels
is set to enable data labels with a custom format and styling options, including font size, color, and text outlineNote that you can customize many other options to further customize your curve chart, such as the line color, thickness, and style, the chart background color, and the legend position and styling. You can find more details and examples in the Highcharts documentation.
Customizing Data Labels in Highcharts Curve Chart:
Highcharts.chart('container', { chart: { type: 'spline' }, title: { text: 'Customizing Data Labels in Highcharts Curve Chart' }, series: [{ name: 'Series 1', data: [5, 10, 15, 20, 25], dataLabels: { enabled: true, color: '#333333', borderRadius: 5, backgroundColor: 'rgba(255, 255, 255, 0.7)', padding: 5, formatter: function () { return this.y; } } }], // Additional configuration options... });
Adding and formatting Data Labels in Highcharts Curve Chart:
series: [{ name: 'Series 1', data: [5, 10, 15, 20, 25], dataLabels: { enabled: true, formatter: function () { return '<b>' + this.y + '</b>'; }, style: { color: '#ffffff', textOutline: '1px contrast' } } }],
Highcharts Curve Chart with dynamic Data Labels:
series: [{ name: 'Series 1', data: [5, 10, 15, 20, 25], dataLabels: { enabled: true, formatter: function () { if (this.y > 15) { return 'High'; } else { return 'Low'; } }, style: { color: '#333333' } } }],
Interactive features in Highcharts Curve Chart with Data Labels:
series: [{ name: 'Series 1', data: [5, 10, 15, 20, 25], dataLabels: { enabled: true, formatter: function () { return this.y; }, style: { color: '#333333' }, events: { click: function () { alert('Data label clicked: ' + this.y); } } } }],
Configuring position and style of Data Labels in Highcharts:
series: [{ name: 'Series 1', data: [5, 10, 15, 20, 25], dataLabels: { enabled: true, formatter: function () { return this.y; }, style: { color: '#ffffff', textOutline: '1px contrast' }, y: -10 // Adjust the vertical position } }],
Handling overlapping Data Labels in Highcharts Curve Chart:
crop
and overflow
options.series: [{ name: 'Series 1', data: [5, 10, 15, 20, 25], dataLabels: { enabled: true, formatter: function () { return this.y; }, crop: false, overflow: 'none' } }],
Highcharts Curve Chart with conditional Data Labels display:
series: [{ name: 'Series 1', data: [5, 10, 15, 20, 25], dataLabels: { enabled: function () { return this.y > 15; // Display labels for values greater than 15 }, formatter: function () { return this.y; }, style: { color: '#333333' } } }],