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

Answered
1
0

I spent all day on this one and was reluctant to ask but despite all my efforts here I am asking this question in the forum. This started with an undesirable behavior when showing/hiding the point markers on my series. When my series is being displayed on the legend AFTER the legend is already visible the point marker is “sort of displayed”, meaning you can see a small missing piece of the series line in the legend as if a point marker is there. But, it is not. If I select another series on my chart after I have elected to show the legend and point markers this problem doesn’t exist. I’d prefer not to get into the depths of the view model for which I am binding my series to the SciChart and instead focus on why I am unable to access information in the s:SeriesInfo that I assume should be available.

Basically I want to build my own custom legend and it’s simply not working as I would expect. The only thing that is binding with success is the SeriesName. See the following example.

<s:LegendModifier.LegendItemTemplate>
<DataTemplate DataType="{x:Type s:SeriesInfo}">
    <StackPanel Orientation="Horizontal">

        <Rectangle Height="2" Width="120" Fill="{Binding RenderableSeries.Stroke}" />

        <Ellipse Width="10" Height="10">
            <Ellipse.Style>
                <Style TargetType="{x:Type Ellipse}">
                    <Setter Property="Stroke" Value="{Binding RenderableSeries.Stroke}" />
                    <Setter Property="Fill" Value="{Binding RenderableSeries.PointMarker.Fill}" />
                    <Setter Property="StrokeThickness" Value="1" />
                    <Setter Property="Margin" Value="10,0,10,0" />
                    <Setter Property="Visibility" Value="Visible" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=ShowPoints, Mode=TwoWay}" Value="True">
                            <Setter Property="Visibility" Value="Visible" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Ellipse.Style>
        </Ellipse>

        <TextBlock Text="{Binding RenderableSeries.DataSeries.SeriesName}" />
    </StackPanel>
</DataTemplate>

</s:LegendModifier.LegendItemTemplate>

Nothing. Despite reading pages and articles/posts on SciChart’s website I have run into a wall and decided to ask for help.

Version
6.6.0.26367-beta
  • You must to post comments
Best Answer
1
0

Hi Chris,

I think this might be a converter issue.

I can share with you our LegendItemTemplate in the SciChart library to explain why.

<DataTemplate x:Key="SciChartLegendItemTemplate" DataType="chartData:SeriesInfo">
    <StackPanel Orientation="Horizontal">
        <CheckBox Margin="5,0,0,0"
                  HorizontalAlignment="Left"
                  VerticalAlignment="Center"
                  IsChecked="{Binding RenderableSeries.IsVisible, Mode=TwoWay}"
                  Visibility="{Binding LegendData.ShowVisibilityCheckboxes, RelativeSource={RelativeSource AncestorType=visuals:SciChartLegend}, Converter={StaticResource BooleanToVisibilityConverter}}" />

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

        <TextBlock Margin="5,0,5,0"
                   HorizontalAlignment="Left"
                   Text="{Binding SeriesName}" 
                   Foreground="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=r:LegendPlaceholder}, Path=Foreground}"/>
    </StackPanel>
</DataTemplate>

Notice PointMarker above. The LegendMarkerTemplate is defined on the series itself which is why PointMarker.DataContext is set to the RenderableSeries.

The standard template is

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

RenderableSeries.Stroke is Color whereas Line.Stroke expects Brush. So we are using ColorToBrushConverter. This is defined in the SciChart.Charting.Common.Databinding namespace.

Perhaps try that?

Second suggestion is check for binding errors in the output window.

Best regards,
Andrew

  • Chris Kirkman
    I’m trying this right now.
  • Chris Kirkman
    I kept getting an exception in the output window indicating that it was an unauthorized class. I just created my own value converter class and it works now. :) Thanks for the help.
  • Andrew Burnett-Thompson
    nice! Glad to be of help!
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.