How to show different data marker symbols based on condition in React Chart?
This article explains how to show different data marker symbols based on condition in React Chart.
Customize the different markers on single series
You can easily customize specific markers by using the pointRender event, which allows you to change the shape, color, and border of a point.
In the following code example, the marker can be customized based on the y-value by using pointRender event.
Index.js
import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, LineSeries, Category,
} from '@syncfusion/ej2-react-charts';
const Line = () => {
const pointRender = (args) => {
if (args.point.y < 45) {
args.fill = 'red';
args.shape = 'InvertedTriangle';
} else if (args.point.y > 45 && args.point.y < 65) {
args.fill = 'blue';
args.shape = 'Diamond';
} else {
args.fill = 'green';
args.shape = 'Triangle';
}
};
return (
<chartcomponent id="charts" pointrender="{pointRender.bind(this)}">
<inject services="{[LineSeries," category]}="">
<seriescollectiondirective>
<seriesdirective datasource="{data}" xname="x" yname="y" width="{2}" marker="{{" visible:="" true="" }}="" type="Line"></seriesdirective>
</seriescollectiondirective>
</inject></chartcomponent>
);
};
export default Line;
const root = createRoot(document.getElementById('sample'));
root.render(<line>);
The following screenshot illustrate the output of the above code snippet.
Screenshot:
Refer to the working sample for additional details and implementation: View Sample in Stackblitz
Conclusion
I hope you enjoyed learning how to show different data marker symbols based on condition in React Chart Component.
You can refer to our React Chart feature tour page to learn about its other groundbreaking feature representations and documentation, as well as how to quickly get started with 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, BoldDesk Support, or feedback portal. We are always happy to assist you!