Pre loader

Multiple X Axes

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

Answered
0
0

I’m trying to create a chart with a single FastLineRenderableSeries, that will have one Y axis, and two X axes.
The first X axis will be a simple NumericAxis, but I want the second X axis to show a string value plotted for each point in the series.

For example, if I have a line series with 3 points
[x:0, y:10]
[x:10, y:20]
[x:20, y:10]

I want the first X axis to show a simple 0-20 range, but I want the second X axis to have “Point1” at x=0, “Point2” at x=10 and “Point3” at x=20.

I have tried with AxisMarkerAnnotation, but this appears to always rotate the text vertically (I need the text horizontal like on a normal Axis)

The second problem is that when you zoom out, the axes go out of sync? I have tried to resolved this using

 private void XNumericAxis_VisibleRangeChanged(object sender, Charting.Visuals.Events.VisibleRangeChangedEventArgs e)
    {
        XNameAxis.VisibleRange = XNumericAxis.VisibleRange;
        XNameAxis.GrowBy = XNumericAxis.GrowBy;
        XNameAxis.MajorDelta = XNumericAxis.MajorDelta;
    }

but it still goes out of sync (see attached images).

Full code :

 <s:SciChartSurface x:Name="sciChart"
                   GridLinesPanelStyle="{StaticResource GridLinesPanelStyle}"
                   Style="{StaticResource SciChartSurfaceStyle}">

    <s:SciChartSurface.RenderableSeries>
        <s:FastLineRenderableSeries x:Name="lineSeries"
                                    Stroke="Plum"
                                    StrokeThickness="3">
            <s:FastLineRenderableSeries.SeriesAnimation>
                <s:FadeAnimation AnimationDelay="0:0:0.2"
                                 Duration="0:0:1" />
            </s:FastLineRenderableSeries.SeriesAnimation>
        </s:FastLineRenderableSeries>
    </s:SciChartSurface.RenderableSeries>

    <s:SciChartSurface.XAxes>
        <s:NumericAxis Style="{StaticResource XAxisStyle}"
                       AxisBandsProvider="{Binding XAxisBands}"
                       VisibleRangeChanged="XNumericAxis_VisibleRangeChanged"
                       x:Name="XNumericAxis" />
        <s:NumericAxis Style="{StaticResource XAxisStyle}"
                       LabelProvider="{Binding XAxisLabels}"
                       AutoRange="Never"
                       x:Name="XNameAxis"
                       Id="NameAxis" />
    </s:SciChartSurface.XAxes>

    <s:SciChartSurface.YAxes>
        <s:NumericAxis Style="{StaticResource YAxisStyle}"
                       AxisAlignment="Left" />
    </s:SciChartSurface.YAxes>
    <s:SciChartSurface.ChartModifier>
        <s:ModifierGroup>
            <s:ZoomPanModifier />
            <s:ZoomExtentsModifier />
            <s:MouseWheelZoomModifier />
        </s:ModifierGroup>
    </s:SciChartSurface.ChartModifier>

    <s:SciChartSurface.Annotations>

        <s:AxisMarkerAnnotation X1="0"
                                XAxisId="NameAxis"
                                AnnotationCanvas="XAxis">
            <s:AxisMarkerAnnotation.PointerTemplate>
                <DataTemplate  DataType="{x:Type s:AxisInfo}">

                </DataTemplate>
            </s:AxisMarkerAnnotation.PointerTemplate>
            <s:AxisMarkerAnnotation.LabelTemplate>
                <DataTemplate  DataType="{x:Type s:AxisInfo}">
                    <TextBlock Text="Point 1"
                               Foreground="Black"
                               FontWeight="Normal" />
                </DataTemplate>
            </s:AxisMarkerAnnotation.LabelTemplate>
        </s:AxisMarkerAnnotation>

        <s:AxisMarkerAnnotation X1="10"
                                XAxisId="NameAxis"
                                AnnotationCanvas="XAxis">
            <s:AxisMarkerAnnotation.PointerTemplate>
                <DataTemplate  DataType="{x:Type s:AxisInfo}">

                </DataTemplate>
            </s:AxisMarkerAnnotation.PointerTemplate>
            <s:AxisMarkerAnnotation.LabelTemplate>
                <DataTemplate  DataType="{x:Type s:AxisInfo}">
                    <TextBlock Text="Point 2" />
                </DataTemplate>
            </s:AxisMarkerAnnotation.LabelTemplate>
        </s:AxisMarkerAnnotation>

        <s:AxisMarkerAnnotation X1="20"
                                XAxisId="NameAxis"
                                AnnotationCanvas="XAxis">
            <s:AxisMarkerAnnotation.PointerTemplate>
                <DataTemplate  DataType="{x:Type s:AxisInfo}">

                </DataTemplate>
            </s:AxisMarkerAnnotation.PointerTemplate>
            <s:AxisMarkerAnnotation.LabelTemplate>
                <DataTemplate  DataType="{x:Type s:AxisInfo}">
                    <TextBlock Text="P3" />
                </DataTemplate>
            </s:AxisMarkerAnnotation.LabelTemplate>
        </s:AxisMarkerAnnotation>

    </s:SciChartSurface.Annotations>
</s:SciChartSurface>
Version
7
Images
  • You must to post comments
Best Answer
1
0

Hi there,

Thanks for your response.

You can use LabelsProvider API to customize appearance of axis labels. In your use-case, it can be used to transform default numerical values into strings according to a mapping.

Also, you could use TickProvider API to make sure labels appear only at specific locations.

Please take a look at the attached example. This is a modified Column Series Demo example from our Demo App. It demontrates how to use abovementioned APIs to satisfy your requirements. There you can find the CustomNumericTickProvider and StringLabelProvider classes, which are applied to the second X-Axis in the code-behind (ColumnChartExampleView.xaml.cs).

Also, please notice how both X-Axes are synchronized via Binding to VisibleRange in the view (ColumnChartExampleView.xaml).

Hope this helps! Please let me know if you have any questions,

Best Regards,
Joeri

  • You must to post comments
1
0

Hi there

Is the LabelProvider API a better choice for this requirement?

In this documentation page – Axis Styling – Styling Axis Labels with LabelProvider – we show an advanced use-case of the LabelProvider API to create a custom ViewModel for axis labels.

You can also template axis labels to add extra elements.

There’s an example in our WPF Examples Suite which shows how to create a custom labelprovider with label viewmodels. You can find the code for this here.

Best regards
Andrew

  • You must to post comments
0
0

Thank you for the suggestion, but I am not sure that helps.

What I essentially want is a 2nd xAxis (that doesn’t display range values) but that allows me to add labels (strings) at particular x values.

In pseudo code

var secondXAxis = new NumericAxis();
secondXAxis.Range = firstXAxis.Range; // range should sync with the first xAxis
secondXAxis.AddLabelAtXLocation(0, “Point1”);
secondXAxis.AddLabelAtXLocation(10, “Point2”);
secondXAxis.AddLabelAtXLocation(20, “Point3”);

does that make sense?

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.