This is a migrated thread and some comments may be shown as answers.

Creating a dashed CustomLine on a chart

2 Answers 102 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 14 Nov 2013, 10:10 AM
Hi,

I'm trying to draw a CustomLine on a add, I want it styled so it appears dashed.

I am creating the line in code here....
CustomLine line = new CustomLine();
line.Style = (Style)Application.Current.FindResource("DashedCustomLine");
line.Stroke = Brushes.Black;
line.StrokeThickness = 1;
line.YIntercept = 0;
line.Slope = 1;

The style is then....
<Style x:Key="DashedCustomLine" TargetType="telerikCharting:CustomLine">
    <Setter Property="StrokeDashArray" Value="5,2" />
</Style>

However it seems there isn't a StrokeDashArray property on CustomLine, what property should I be using, or how should I be achieving this.

I only wish to draw a simple line of identity on the chart, ie. x = y.

Thanks

2 Answers, 1 is accepted

Sort by
0
Rob
Top achievements
Rank 1
answered on 18 Nov 2013, 10:06 AM
Anyone?
0
Evgenia
Telerik team
answered on 19 Nov 2013, 03:16 PM
Hello Craig,

Indeed there is no DashArray property for Custom Line annotations. What I can suggest is that you create a dummy (fake) line series with custom style like this:
public partial class MainPage : UserControl
 
{
 
    public MainPage()
 
    {
 
        InitializeComponent();
 
  
 
        List<ChartData> data = new List<ChartData>();
 
        data.Add(new ChartData() { YValue = 1 });
 
        data.Add(new ChartData() { YValue = 2 });
 
  
 
        Style pathStyle1 = new Style(typeof(Path));
 
        pathStyle1.Setters.Add(new Setter(Shape.StrokeDashArrayProperty, "1"));
 
        pathStyle1.Setters.Add(new Setter(Shape.StrokeProperty, new SolidColorBrush(Colors.Cyan)));
 
        pathStyle1.Setters.Add(new Setter(Shape.StrokeThicknessProperty, 3));
 
  
 
        Style lineStyle1 = new Style(typeof(Telerik.Windows.Controls.Charting.SelfDrawingSeries));
 
        lineStyle1.Setters.Add(new Setter(SelfDrawingSeries.BorderLineStyleProperty, pathStyle1));
 
  
 
        SeriesMapping seriesMapping = new SeriesMapping { LegendLabel = "TEST" };
 
        seriesMapping.ItemMappings.Add(new ItemMapping("YValue", DataPointMember.YValue));
 
        seriesMapping.SeriesDefinition = new LineSeriesDefinition() { SeriesStyle = lineStyle1, ShowItemLabels = false, ShowPointMarks = false };
 
  
 
        RadChart1.SeriesMappings.Add(seriesMapping);
 
        RadChart1.ItemsSource = data;
 
    }
 
}
 
  
 
public class ChartData
 
{
 
    public double YValue
 
    {
 
        get;
 
        set;
 
    }
 
}

Here's the lineStyle1 applied above:
<Style x:Name="lineStyle1" TargetType="telerikCharting:SelfDrawingSeries">
                <Setter Property="BorderLineStyle">
                    <Setter.Value>
                        <Style TargetType="Path">
                            <Setter Property="StrokeDashArray" Value="1"/>
                            <Setter Property="Stroke" Value="Black" />
                            <Setter Property="StrokeThickness" Value="3" />
                        </Style>
                    </Setter.Value>
                </Setter>
            </Style>

Regards,
Evgenia
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
Chart
Asked by
Rob
Top achievements
Rank 1
Answers by
Rob
Top achievements
Rank 1
Evgenia
Telerik team
Share this question
or