Here on the Total bars i want to have default cursor but on tires bars i want to have cursor: pointer.
Is there a way to do that programatically not using css? Because there can be 100s of column groups.
2
Why wouldn’t you use CSS?
const colors = ['#648DE6', '#BBA8F6', '#19DCEA']; document.addEventListener('DOMContentLoaded', function() { const chart = Highcharts.chart('container', { chart: { type: 'column', }, plotOptions: { column: { borderRadius: 8 } }, colors: colors, title: { text: 'Car Parts' }, xAxis: { categories: ['Total', 'Tires'] }, yAxis: { title: { text: 'Cost' } }, series: [{ name: 'One', data: [8, 9], color: colors[0] }, { name: 'Two', data: [1, 6], color: colors[1] }, { name: 'Three', data: [11, 5], color: colors[2] }] }); });
.highcharts-series-group .highcharts-series .highcharts-point:nth-child(2) { cursor: pointer; }
<link href="https://cdnjs.cloudflare.com/ajax/libs/highcharts/10.3.3/css/highcharts.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/10.3.3/highcharts.min.js"></script> <div id="container" style="width:100%; height:400px;"></div>
If you want to make this dynamic, you could use JavaScript.
const colors = ['#648DE6', '#BBA8F6', '#19DCEA']; function setCursorForChart(chart, seriesLabel) { const categoryIndex = [...chart.container .querySelectorAll('.highcharts-xaxis-labels text')] .map(textEl => textEl.textContent).findIndex(text => text === seriesLabel); document.querySelectorAll('.highcharts-series-group .highcharts-series') .forEach((series) => { series.querySelectorAll('.highcharts-point') .forEach((point, index) => { if (index === categoryIndex) { point.style.cursor = 'pointer'; } }); }) } document.addEventListener('DOMContentLoaded', function() { const chart = Highcharts.chart('container', { chart: { type: 'column', }, plotOptions: { column: { borderRadius: 8 } }, colors: colors, title: { text: 'Car Parts' }, xAxis: { categories: ['Total', 'Tires'] }, yAxis: { title: { text: 'Cost' } }, series: [{ name: 'One', data: [8, 9], color: colors[0] }, { name: 'Two', data: [1, 6], color: colors[1] }, { name: 'Three', data: [11, 5], color: colors[2] }] }); setCursorForChart(chart, 'Tires'); // Pass in the chart ref });
You can set cursor style for points with a specific x value. For example:
cursor
x
chart.series.forEach(s => { s.points.forEach(point => { if (point.x === 1) { point.graphic.css({ cursor: 'pointer' }); } }); });
Live demo: http://jsfiddle.net/BlackLabel/vw06d5yL/
API Reference: https://api.highcharts.com/class-reference/Highcharts.SVGElement#css
Click here to cancel reply.
2
Answers
Why wouldn’t you use CSS?
If you want to make this dynamic, you could use JavaScript.
You can set
cursor
style for points with a specificx
value. For example:Live demo: http://jsfiddle.net/BlackLabel/vw06d5yL/
API Reference: https://api.highcharts.com/class-reference/Highcharts.SVGElement#css