Render a multicolored line chart using React Chart
This article explains how to render a multicolored line chart using the React Chart.
Customize the multicolored line chart
To render the multicolored line chart, you need to set the series type as MultiColoredLine. You can customize the multicolored line chart by using the pointColorMapping property to map colors from the data source to each point.
In the following code example, the multicolored line series achieves its colors through the pointColorMapping property.
Index.js
import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Tooltip, Category,
MultiColoredLineSeries } from '@syncfusion/ej2-react-charts';
const LineMultiLine = () => {
return (
<ChartComponent
id="charts"
primaryXAxis={{
valueType: 'Category',
interval: 5
}}
primaryYAxis={{
rangePadding: 'None',
minimum: 100,
maximum: 500,
interval: 100,
title: 'Particulate Matter(PM)'
}}
tooltip={{
enable: true
}}
title="Particulate Levels in Rainfall"
>
<Inject services={[MultiColoredLineSeries, Category, Tooltip]} />
<SeriesCollectionDirective>
<SeriesDirective
dataSource={data}
width={1.5}
xName="x"
yName="y"
type="MultiColoredLine"
pointColorMapping="color"
></SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default LineMultiLine;
const root = createRoot(document.getElementById('sample'));
root.render(<LineMultiLine />);
The following screenshot portrays the results of the code snippet mentioned above.
Screenshot:
Conclusion
I hope you enjoyed learning how to render a multicolored line chart using 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!