BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
I have a an sfChart based on a set of FastLineSeries which are generated programmatically from underlying data in the model. Where a series is the first or last I want a dotted line rather than solid. I've achieved this using FastLineSeries and setting the StrokeDashArray property:-
FastLineSeries series = new FastLineSeries()
{
Label = ColumnHeaders[col],
ItemsSource = points,
XBindingPath = "Timestamp",
YBindingPath = "Value"
};
if (mRiskResult is LevelRiskResult
&& (col == ColumnHeaders.Length - 1 //We wan't the min and max to be dashed lines
|| col == 0))
series.StrokeDashArray = new DoubleCollection() { 2, 2 };
This works great but I'm being asked to make the legend display a similar dotted line. I've found this article which explains how to do it in xaml but I can't seem to work out the syntax to do it when creating the series programatically.
Can you let me know how to do this from code?
Thanks
Hi Declan Hillier,
We have analyzed your query and would like to inform you that we can display the dashed line legend icon using the LegendIconTemplate. We can draw a polyline with a dashed style using the framework property in the code behind, as shown in the code snippet.
[C#]
PointCollection points = new PointCollection(); points.Add(new Point(0, 0)); points.Add(new Point(8, 0)); points.Add(new Point(40, 0));
DataTemplate legendIcon = new DataTemplate(); FrameworkElementFactory stackpanel = new FrameworkElementFactory(typeof(StackPanel)); stackpanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); stackpanel.SetValue(StackPanel.HorizontalAlignmentProperty,HorizontalAlignment.Center); stackpanel.SetValue(StackPanel.VerticalAlignmentProperty, VerticalAlignment.Center);
double thickness = 2; FrameworkElementFactory poliElement = new FrameworkElementFactory(typeof(Polyline)); poliElement.SetValue(Polyline.PointsProperty, points); poliElement.SetValue(Polyline.StrokeDashArrayProperty, new DoubleCollection() { 1, 1 }); poliElement.SetValue(Polyline.StrokeProperty, new SolidColorBrush(Colors.Blue)); poliElement.SetValue(Polyline.StrokeThicknessProperty,thickness );
stackpanel.AppendChild(poliElement); legendIcon.VisualTree = stackpanel;
FastLineSeries fastLineSeries = new FastLineSeries() { Name = "series", ItemsSource = vm.AccountData, XBindingPath = "Date", YBindingPath = "YValue", StrokeDashArray = new DoubleCollection() { 3, 2 }, Stroke = new SolidColorBrush(Colors.Blue), StrokeThickness = 1, LegendIconTemplate = legendIcon, Label = "Fast Chart" }; |
Output
Please refer to the following documentation:
https://help.syncfusion.com/wpf/charts/legend?cs-save-lang=1&cs-lang=xaml#legend-icon
Please let us know if you need further assistance.
Regards,
Nanthini Mahalingam.
Awesome, this worked. Thank you.
Hi Declan Hillier,
We are glad to know that the reported problem has been resolved. Please let us know if you have any further queries on this. We are happy to help.
Regards,
Sowndharya Selladurai.