How do I get the legend to display the desired shape for each of different series?

Charts for WPF Forum

Posted 11 years ago by Erez Anzel
Version: 13.2.0591

How do I get a line, rather than a marker, to be used as the symbol in a legend? And a filled square to represent the area series and a marker to represent the points?

I have a chart which contains two line series, two area series, and three scatter series. The legend displays seven items, each with a marker as the symbol. I want the seven items, but each with the correct shape. I already figured out that charts:LineSeries Description will determine the text in the legend, and the Stroke property determines the color. For instance, one line series is defined as follows:

          <charts:LineSeries Description="Direct Invis" ItemsSource="{Binding DirectInVisPolylineCoords}" XPath="Item1" YPath="Item2">
              <Style TargetType="Shape">
                <Setter Property="Stroke" Value="#ff0000" />
                <Setter Property="StrokeThickness" Value="1" />

My guess is LegendItemTemplate, but I don't yet get how to set it up or use it. I'm fairly new to WPF and Actipro. If LegendItemTemplate is the way to go, then what should the DataTemplate consist of? Can it be in the same XAML file? How should I use it?


Comments (2)

Answer - Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Erez,

Thanks for your post, it appears like the XYSeriesBase.LegendItemTemplate property isn't being used at the moment and was likely incorrectly copied when porting from Micro Charts.  We will be removing it in the upcoming maintenance release.  You can use the LegendMarkerStyle and LegendStringFormat properties instead to customize legend items.

Your series could do this for instance to have the series use a triangle in the legend:

	<Style TargetType="charts:ChartMarker">
		<Setter Property="ShapeKind" Value="Triangle" />

We don't have a built-in option for lines but you could retemplate the ChartMarker for a series like this to achieve that:

	<Style TargetType="charts:ChartMarker">
		<Setter Property="Template">
				<ControlTemplate TargetType="charts:ChartMarker">
					<Rectangle x:Name="PART_Path" Fill="{TemplateBinding Background}" Height="2" />

Actipro Software Support

Posted 11 years ago by Erez Anzel

Yes, both the triangle and the line worked for me, so I'm a happy camper. Thanks!

The latest build of this product (v24.1.2) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.