Articles in this section
Category / Section

How to create a dotted line chart in .NET MAUI Cartesian Chart?

4 mins read

A line chart with dots or dashes is commonly used to display forecast values. They are outstanding for visualizing estimates or uncertainty. This article will help you make a dotted or dashed line chart with the .NET MAUI Chart.

See this KB article to create a line chart with.NET MAUI Chart.

.NET MAUI Chart allows you to create a line chart with dashes by using the StrokeDashArray property of the LineSeries, as shown in the following code example. This property requires an array, where the odd value represents the rendering size, and the even value represents the gap.

xmlns:chart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts"
 
<chart:SfCartesianChart>
    
    <chart:SfCartesianChart.BindingContext>
        <local:ViewModel></local:ViewModel>
    </chart:SfCartesianChart.BindingContext>
    
    <chart:SfCartesianChart.XAxes>
        <chart:CategoryAxis></chart:CategoryAxis>
    </chart:SfCartesianChart.XAxes>
    
    <chart:SfCartesianChart.YAxes>
        <chart:NumericalAxis EdgeLabelsDrawingMode="Shift" Minimum="0">
            <chart:NumericalAxis.LabelStyle>
                <chart:ChartAxisLabelStyle LabelFormat="0B"></chart:ChartAxisLabelStyle>
            </chart:NumericalAxis.LabelStyle>
        </chart:NumericalAxis>
    </chart:SfCartesianChart.YAxes>
    
    <chart:SfCartesianChart.Legend>
        <chart:ChartLegend></chart:ChartLegend>
    </chart:SfCartesianChart.Legend>
 
    <chart:SfCartesianChart.Series>
        <chart:LineSeries ShowDataLabels="True" Label="Projected Revenue" StrokeWidth="2" 
                                        Fill="#512BD4" ItemsSource="{Binding Data}" 
                                        XBindingPath="Year" YBindingPath="Revenue">
            <chart:LineSeries.DataLabelSettings>
                <chart:CartesianDataLabelSettings>
                    <chart:CartesianDataLabelSettings.LabelStyle>
                        <chart:ChartDataLabelStyle FontSize="10" LabelFormat="0B">
                        </chart:ChartDataLabelStyle>
                    </chart:CartesianDataLabelSettings.LabelStyle>
                </chart:CartesianDataLabelSettings>
            </chart:LineSeries.DataLabelSettings>
 
            <chart:LineSeries.StrokeDashArray>
                <DoubleCollection>
                    <x:Double>2</x:Double>
                    <x:Double>2</x:Double>
                </DoubleCollection>
            </chart:LineSeries.StrokeDashArray>
 
        </chart:LineSeries>
    </chart:SfCartesianChart.Series>
 
</chart:SfCartesianChart>

 

using Syncfusion.Maui.Charts;
 
SfCartesianChart chart = new SfCartesianChart();
chart.BindingContext = new ViewModel();
CategoryAxis xAxis = new CategoryAxis();
NumericalAxis yAxis = new NumericalAxis();
yAxis.LabelStyle = new ChartAxisLabelStyle()
{
 LabelFormat = "0B"
};
 
chart.XAxes.Add(xAxis);
chart.YAxes.Add(yAxis);
 
LineSeries lineSeries = new LineSeries();
chart.Series.Add(lineSeries);
 
lineSeries.ItemsSource = new ViewModel().Data;
lineSeries.XBindingPath = "Year";
lineSeries.YBindingPath = "Revenue";
lineSeries.ShowDataLabels = true;
lineSeries.Fill = Color.FromArgb("#512BD4");
lineSeries.StrokeWidth = 2;
lineSeries.StrokeDashArray = new DoubleCollection() { 2, 2 };
 
CartesianDataLabelSettings dataLabelSettings = new CartesianDataLabelSettings();
dataLabelSettings.LabelStyle = new ChartDataLabelStyle()
{
 LabelFormat = "0B"
};
lineSeries.DataLabelSettings = dataLabelSettings;
 
Content = chart;

Output

Dash-styled line chart using .NET MAUI Chart control

Explore the runnable demo from this Github location.

See also

How to create a column chart in .NET MAUI Chart (SfCartesianChart)?

How to create a spline chart in .NET MAUI Chart (SfCartesianChart)?

How to customize the segment color based on the y-value in .NET MAUI Chart (SfCartesianChart)?

Fast line chart in .NET MAUI Chart control


Conclusion

I hope you enjoyed learning on how to create a dotted line chart in .NET MAUI Cartesian Chart.
You can refer to our .NET MAUI Cartesian Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
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