How to add benchmark line in React Chart?
This article explains how to add a benchmark line in the React Chart.
Customize to include a benchmark line
The React chart supports strip lines in both horizontal and vertical orientations, and it allows for customization of the strip line in both directions.
To create a horizontal stripline, add it to the vertical axis and set the visible option to true. For a vertical stripline, add it to the horizontal axis and also set the visible option to true. Striplines are rendered within the specified start to end range, and multiple striplines can be added to an axis.
You can easily represent a benchmark line in a chart using the annotation and stripline and set the target value to the stripline start range.
In the following code example, the chart includes a benchmark line annotated at 62%.
Index.js
import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Category, ColumnSeries, StripLine, ChartAnnotation,
AnnotationsDirective, AnnotationDirective, DataLabel } from '@syncfusion/ej2-react-charts';
let content =
'<div style="font-weight: bold; color: #24748b; font-size: 12px;">Benchmark</div>';
const Column = () => {
return (
<ChartComponent
id="charts"
primaryXAxis={{
valueType: 'Category',
interval: 1
}}
primaryYAxis={{
maximum: 80,
interval: 10,
labelFormat: '{value}%',
stripLines: [
{
start: 62,
size: 1,
color: '#f8a509',
visible: true,
horizontalAlignment: 'Start',
zIndex: 'Over'
}
]
}}
>
<Inject
services={[ ColumnSeries, Category, StripLine, ChartAnnotation, DataLabel ]}
/>
<AnnotationsDirective>
<AnnotationDirective
content={content}
region="Series"
x="12%"
y="25%"
></AnnotationDirective>
</AnnotationsDirective>
<SeriesCollectionDirective>
<SeriesDirective
dataSource={data}
xName="x"
yName="y"
type="Column"
marker={{
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' }
},
}}
/>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default Column;
const root = createRoot(document.getElementById('sample'));
root.render(<Column />);
The following screenshot illustrate the output of the above code snippet.
Screenshot:
Conclusion
I hope you enjoyed learning how to add a benchmark line in the React Chart Component.
You can refer to our React Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our React Chart example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!