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

Charts for WPF Forum

Posted 10 years ago by Erez Anzel
Version: 13.2.0591
Avatar

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">
            <charts:LineSeries.LineStyle>
              <Style TargetType="Shape">
                <Setter Property="Stroke" Value="#ff0000" />
                <Setter Property="StrokeThickness" Value="1" />
              </Style>
            </charts:LineSeries.LineStyle>
          </charts:LineSeries>

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?

Thanks!

Comments (2)

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

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:

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

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

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


Actipro Software Support

Posted 10 years ago by Erez Anzel
Avatar

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 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.