Articles in this section
Category / Section

How to create dash pattern line chart in Flutter using cartesianCharts widget?

3 mins read

Description

This article explains how to create a dash pattern line chart in Flutter using the SfCartesianChart widget.

Solution

Cartesian chart provides dash array support for chart series. You can customize the chart series with dashed lines by using the dashArray property. To learn more about dash array in our charts, refer to the user guide.

Follow these steps to render a dashed pattern line chart using the SfCartesianChart widget:

Step 1: Declare and initialize the chartData with the required data source.

//Initialize the data source
List<_ChartData> chartData = <_ChartData>[
   _ChartData(2010, 6.6),
   _ChartData(2011, 6.3),
   _ChartData(2012, 6.7),
   _ChartData(2013, 6.7),
   _ChartData(2014, 6.4),
   _ChartData(2015, 6.8),
   _ChartData(2016, 7.7),
];

 

Step 2: Initialize the SfCartesianChart widget with required properties. Here, we have initialized the line type series.

SfCartesianChart(
 series: <LineSeries<_ChartData, num>>[
  LineSeries<_ChartData, num>(
   // Binding the chartData to the dataSource of the line series.
  dataSource: chartData,
  xValueMapper: (_ChartData sales, _) => sales.x,
  yValueMapper: (_ChartData sales, _) => sales.y,
  ),
 ],
),

 

Step 3: Assign the value list of double values to the dashArray, in which the odd value in the list refers to the dash size and the even value in the list refers to the offset gap between the dashes.

SfCartesianChart(
 series: <LineSeries<_ChartData, num>>[
    LineSeries<_ChartData, num>(
    // Dash array value in which 15 refers to size of the dashes and 3 refers to the offset gap between     the dashes.
    dashArray: <double>[15, 3],
    ),
  ],
),

 

Thus, the dash pattern line chart is achieved using the SfCartesianChart widget.

Screenshot

 

Dash pattern line chart in Flutter CartesianChart

 

 

View the Github Sample here.

 

Conclusion

I hope you enjoyed learning about how to create dash pattern line chart in Flutter using cartesianCharts widget.

You can refer to our  Flutter CartesianChart feature tour page to learn about its other groundbreaking feature representations. You can also explore our Flutter CartesianChart documentation 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 forumsDirect-Trac, or feedback portal. We are always happy to assist you! 


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied