SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Answered
0
0

Hello,
I would like to allow user click on Legend and highlight the corresponding Series on the chart but I don’t know if this feature is supported or not.

I tried to add mouse events to the Legend Modified but it seems like mouse events are not triggered

This is the simple code that I am using

<s:LegendModifier x:Name="chlLegend" ShowLegend="True" LegendPlacement="Top" Orientation="Horizontal" MouseDown="chlLegend_MouseDown" ScrollViewer.HorizontalScrollBarVisibility="Auto" />

Before investigating more I would like to ask you if you have any hints which is the correct way to implement this behavior.
Is the LegendModifier suitable for this or should I override instead the Legend Control Template?

Thank you in advance for the support

  • You must to post comments
Best Answer
0
0

Yes the property you want to change is BaseRenderableSeries.LegendMarkerTemplate

Here is the default for line:

<DataTemplate x:Key="DefaultLegendMarkerTemplate" DataType="r:BaseRenderableSeries">
    <Line VerticalAlignment="Center"
          Stretch="Fill"
          Stroke="{Binding SeriesColor,
                           Converter={StaticResource ColorToBrushConverter}}"
          StrokeThickness="2"
          X1="0"
          X2="1"
          Y1="0.5"
          Y2="0.5" />
</DataTemplate>

and for Scatter:

<DataTemplate x:Key="ScatterSeriesLegendMarkerTemplate" DataType="r:XyScatterRenderableSeries">
    <Grid>
        <Viewbox HorizontalAlignment="Center" Stretch="Uniform">
            <r:TemplatableControl Template="{Binding PointMarker.PointMarkerTemplate}" />
        </Viewbox>
    </Grid>
</DataTemplate>

and for Mountain:

<DataTemplate x:Key="MountainSeriesLegendMarkerTemplate" DataType="r:FastMountainRenderableSeries">
    <Border BorderBrush="{Binding SeriesColor, Converter={StaticResource ColorToBrushConverter}}" BorderThickness="{Binding StrokeThickness, Converter={StaticResource DoubleToThicknessConverter}}">
        <Rectangle Fill="{Binding AreaBrush}" Stretch="Fill" />
    </Border>
</DataTemplate>

I suggest binding something in there to BaseRenderableSeries.StrokeThickness.

Was there anything else you needed to know?

  • You must to post comments
0
0

Hi Marco,

Take a look at our tutorial on Custom Legend with Color Picker and Custom Point Markers. This shows you how to proide a LegendItemTemplate with a number of options.

Each Row in the Legend binds to a SeriesInfo derived type. SeriesInfo lets you access the RenderableSeries that the legend row represents.

So, using the above tutorial, you should be able to modify the template to have a checkbox to manipulate SeriesInfo.RenderableSeries.IsVisible.

Let me know if this helps!

Best regards,
Andrew

  • You must to post comments
0
0

Thank you Andrew the link was helpful, I ovveride the default template and added a MouseEvent on the PointMarker that I can use to change the Stroke property of linked RenderableSeries.

                            <s:PointMarker Margin="5,0,0,0"
                                       Width="40"
                                       Height="10"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Center"
                                       DataContext="{Binding RenderableSeries}"
                                       DeferredContent="{Binding LegendMarkerTemplate}"
                                       MouseDoubleClick="PointMarker_MouseDoubleClick"
                                       Visibility="{Binding ShowSeriesMarkers, RelativeSource={RelativeSource AncestorType=s:SciChartLegend}, Converter={StaticResource BooleanToVisibilityConverter}}" />

What I did not understand yet is how to increase the thickness also on the line in the Legend.

Can you please share the PointMarker default WPF template so that I can override also that?
I don’t want to add or change the point marker but only increase the thickness of the line. (screenshot)

Thank you in advance.

Images
  • You must to post comments
0
0

Thank you Andrew for the support all clear now.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.