customizing line series plot lines

Dec 5, 2012 at 1:40 PM

Hello everyone. I am using a LineSeries chart to compare 5 different plot lines. The user needs to be able to print out the chart in B&W and still be able to distinguish individual plot lines. How can I customize each plot line to be a different pattern? dashes, dots, etc, so they are each unique and distinguishable in print? Here is what my XAML looks like now.

Thanks! 

<toolkit:Chart x:Name="_uxChart"  Grid.Row="3" Margin="50, 0, 50, 0" >
            <toolkit:Chart.LegendStyle>
                <Style TargetType="datavis:Legend">
                    <Setter Property="Width" Value="0" />
                </Style>
            </toolkit:Chart.LegendStyle>

            <toolkit:LineSeries
                    ItemsSource="{Binding Path=Data1}"
                    IndependentValuePath="Number"
                    DependentValuePath="Value" Title="{Binding Path=TestRunName}">

                <toolkit:LineSeries.DataPointStyle>
                    <Style TargetType="toolkit:LineDataPoint">
                        <Setter Property="Opacity" Value="0" />
                        <Setter Property="Background" Value="Green" />
                       
                    </Style>
                </toolkit:LineSeries.DataPointStyle>
            </toolkit:LineSeries>

            <toolkit:LineSeries
                    ItemsSource="{Binding Path=Data2}"
                    IndependentValuePath="Number"
                    DependentValuePath="Value" Title="{Binding Path=TestRunName}">

                <toolkit:LineSeries.DataPointStyle>
                    <Style TargetType="toolkit:LineDataPoint">
                        <Setter Property="Opacity" Value="0" />
                        <Setter Property="Background" Value="Blue" />
                    </Style>
                </toolkit:LineSeries.DataPointStyle>
            </toolkit:LineSeries>

            <toolkit:LineSeries
                    ItemsSource="{Binding Path=Data3}"
                    IndependentValuePath="Number"
                    DependentValuePath="Value" Title="{Binding Path=TestRunName}">

                <toolkit:LineSeries.DataPointStyle>
                    <Style TargetType="toolkit:LineDataPoint">
                        <Setter Property="Opacity" Value="0" />
                        <Setter Property="Background" Value="Orange" />
                    </Style>
                </toolkit:LineSeries.DataPointStyle>
            </toolkit:LineSeries>

            <toolkit:LineSeries
                    ItemsSource="{Binding Path=Data4}"
                    IndependentValuePath="Number"
                    DependentValuePath="Value" Title="{Binding Path=TestRunName}">

                <toolkit:LineSeries.DataPointStyle>
                    <Style TargetType="toolkit:LineDataPoint">
                        <Setter Property="Opacity" Value="0" />
                        <Setter Property="Background" Value="Red" />
                    </Style>
                </toolkit:LineSeries.DataPointStyle>
            </toolkit:LineSeries>

            <toolkit:LineSeries
                    ItemsSource="{Binding Path=Data5}"
                    IndependentValuePath="Number"
                    DependentValuePath="Value" Title="{Binding Path=TestRunName}">

                <toolkit:LineSeries.DataPointStyle>
                    <Style TargetType="toolkit:LineDataPoint">
                        <Setter Property="Opacity" Value="0" />
                        <Setter Property="Background" Value="Gray" />
                    </Style>
                </toolkit:LineSeries.DataPointStyle>
            </toolkit:LineSeries>

 
        </toolkit:Chart>

 

Dec 8, 2012 at 4:03 PM

Ben,

I think you could provide some variation by adjusting the StrokeDashArrayProperty, StrokeThicknessProperty, and StrokeDashCapProperty like this:

var style = new Style(typeof(Polyline));
SetStyleProperty(style, Shape.StrokeDashArrayProperty, new DoubleCollection(new[] { 5.0 }));
SetStyleProperty(style, Shape.StrokeThicknessProperty, 4.0);
SetStyleProperty(style, Shape.StrokeDashCapProperty, PenLineCap.Triangle);
(Chart.Series[] as LineSeries).PolylineStyle = style;

private void SetStyleProperty(Style style, DependencyProperty property, object value)
{ 
     Setter setter = new Setter(property, value);
     style.Setters.Add(setter);
}

I hope this helps,

Glenn Thimmes

Dec 10, 2012 at 6:37 AM

Don't bother using this toolkit to plot graphs.  There is a massive memory leak when changing the series.itemsource data on the fly.  Printing will be the least of your worries.  After a continued use of your application and the graph changing over and over your application will become less and less responsive.  Don't spend time trying to customize an application around this.

If you don't believe me write an application using the line series chart.  Update the itemsource every second.  Open taskmanager and watch the memory usage continue to increase.