How to create a dotted forecast line chart in React Chart?
This article explains how to create a dotted forecast line chart in the React Chart.
Customize to create a dotted forecast line chart
You can easily create a dotted forecast line chart by using the dashArray property. The dash array defines the pattern of dashes and gaps to stroke the lines in line type series. By default, it’s an empty string ’ '.
In the following code example, the dash array is set to 5 for the chart series.
Index.js
import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, SplineSeries, Category,
Tooltip, Highlight, Legend } from '@syncfusion/ej2-react-charts';
const DashedLine = () => {
return (
<ChartComponent
id="charts"
primaryXAxis={{
valueType: 'Category',
interval: 1,
labelRotation: -45
}}
primaryYAxis={{
labelFormat: '{value}k',
minimum: 0,
maximum: 300,
interval: 50
}}
title="Fruits Production Statistics"
>
<Inject
services={[SplineSeries, Category, Tooltip, Legend, Highlight]}
/>
<SeriesCollectionDirective>
<SeriesDirective
dataSource={data1}
xName="x"
yName="y"
type="Spline"
name="Actual"
></SeriesDirective>
<SeriesDirective
dataSource={data2}
xName="x"
yName="y"
dashArray="5"
type="Spline"
name="Forecast"
></SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default DashedLine;
const root = createRoot(document.getElementById('sample'));
root.render(<DashedLine />);
The following screenshot portrays the results of the code snippet mentioned above.
Screenshot:
Conclusion
I hope you enjoyed learning how to create a dotted forecast line chart 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!