I want to create a graph similar to below in react apllication. But not getting option
to move text on left an right in highchart.
- Parameter avaialble in highchart (align) either left or right.
- Customize legend to appear on left and right based on requriement.
Anyone aware how can we achieve below chart in highchart?
[![Chart to be created][1]][1]
const options: Highcharts.Options = {
chart: {
type: 'bar',
height: 125,
},
title: {
text: '',
},
xAxis: {
categories: ['basket compostion'],
visible: false,
},
yAxis: {
labels: {
enabled: false,
},
visible: false,
min: 0,
title: {
text: null,
},
},
tooltip: {
pointFormat:
'<span style="color:{series.color}">{series.name}</span>: <b>' + '{point.percentage:.0f}%</b><br/>',
shared: true,
},
legend: {
align: 'right',
verticalAlign: 'bottom',
labelFormatter() {
const alignment = this.index === this.chart.series.length - 1 ? 'Right Aligned' : 'Left Aligned';
return `<div>${this.name} (${alignment})<div>`;
},
itemStyle: {
fontSize: '14px',
},
},
plotOptions: {
bar: {
stacking: 'percent',
dataLabels: {
enabled: true,
align: 'left',
},
borderRadius: 5,
},
},
series: [
{
name: 'other products',
color: '#5041af',
type: 'bar',
data: [
{
y: 81.2,
custom: { info: 47.29 },
},
],
},
{
name: 'focus',
index: 0,
color: '#21145f',
type: 'bar',
className: 'series-data-label',
data: [
{
y: 18.2,
custom: { info: 10.14 },
},
],
},
],
};
return (
<div>
<HighchartsReact highcharts={Highcharts} options={options} />
</div>
);
[1]: https://i.sstatic.net/9bTeAFKN.png
2
Answers
I was able to achive it by formatting datalabel
There isn’t a direct API option to achieve this, but you can simulate the alignment by translating the legend items.
Demo:
https://jsfiddle.net/BlackLabel/pm5wotu6/