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

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

1
0

Hi,

I created a custom point marker by deriving from CrossPointMarker and overwriting the DrawInternal function (when I derive from BasePointMaker the behaviour is the same):

   protected override void DrawInternal(IRenderContext2D context, double x, double y, IPen2D pen, IBrush2D brush)
    {
        double xOffset = Width * 0.5;
        double yOffset = Width * 0.5;
        context.DrawLine(pen, new Point(x - xOffset, y - yOffset), new Point(x + xOffset, y + yOffset));
        context.DrawLine(pen, new Point(x + xOffset, y - yOffset), new Point(x - xOffset, y + yOffset));
    }

When I set the PointMarker property of a FastLineRenderableSeries to an instance of this new Type I see the markers on the rendered line, but it does not show up in the legend (just a line with a small gap is drawn).
When I change the code to use a CrossPointMarker the marker is cross displayed on the line and in the legend.
What do I need to do to display the point marker in the legend as well?

Thanks in advance
Peter

Images
  • You must to post comments
1
0

Hi Peter,

Thanks for your inquiry. Concerning the issue, markers don’t appear because the default style for the custom marker isn’t defined.
So to make it working, you should either set

DefaultStyleKey = typeof(CrossPointMarker);

in the constructor (in this case the marker from the base type will appear) or define a style for this type. It has the PointMarkerTemplate property (of type ControlTemplate), which is responsible for what actually appears in legend.

And here is the example of how the default style for CrossPointsMarker looks like:

    <Style TargetType="pointMarkers:CrossPointMarker">
    <Setter Property="Width" Value="9" />
    <Setter Property="Height" Value="9" />
    <Setter Property="Fill" Value="{Binding SeriesColor}" />
    <Setter Property="Stroke" Value="{Binding SeriesColor}" />
    <Setter Property="PointMarkerTemplate">
        <Setter.Value>
            <ControlTemplate>
                <Grid>
                    <Grid.Resources>
                        <Style TargetType="Line">
                            <Setter Property="Stretch" Value="Fill" />
                            <Setter Property="Height" Value="{Binding DataContext.PointMarker.Height, RelativeSource={RelativeSource TemplatedParent}}" />
                            <Setter Property="Width" Value="{Binding DataContext.PointMarker.Width, RelativeSource={RelativeSource TemplatedParent}}" />
                            <Setter Property="Stroke" Value="{Binding DataContext.PointMarker.Stroke, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ColorToBrushConverter}}" />
                            <Setter Property="StrokeThickness" Value="{Binding DataContext.PointMarker.StrokeThickness, RelativeSource={RelativeSource TemplatedParent}}" />
                        </Style>
                    </Grid.Resources>

                    <Line Stretch="Fill"
                          X1="0"
                          X2="1"
                          Y1="0.4"
                          Y2="0.4" />
                    <Line Stretch="Fill"
                          X1="0.5"
                          X2="0.5"
                          Y1="0"
                          Y2="1" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Pretty straightforward, isn’t it? 🙂

Please try to create the desirable one for your marker type and let us know if it works as expected.

Best regards,
Yuriy

  • You must to post comments
0
0

Hi Yuriy,

thanks for your help.
The XAML way worked for me, whereas the ‘DefaultStyleKey = typeof(CrossPointMarker);’ just displayed the CrossPointMarker on my legend instead of my custom one.
Is there a reason for, or an advantage of this duplication? After all I configure and draw the marker in C# and the C# version is used only on the trace. To get the same marker on the legend it must be rewritten in XAML. This is slightly inconvenient 🙂

Cheers, Peter

    • Guest
    • 3 years ago
    Hi Peter, sorry for a late response! As I mentioned in the post above, the marker from the base type will appear if you set DefaultStyleKey. Set it if you don't want to redefine marker's look in Xaml. Redefining in Xaml is a bit inconvenient, I agree with you, but it's how things work for now. We hope to improve this in future releases.
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.