Pre loader

Trouble Adding 2nd Y-Axis

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

0
0

I’ve been using this chart for a few months now and yesterday ran into a problem with the Y-axis. I’m sure this is nothing more than my lack of understanding on multiple axes.

I have a need to add a 2nd Y axis and I’m not doing something right. My application is using MVVM to bind series to my chart. So far I have been adding data to my chart using the methods described here…

https://www.scichart.com/documentation/v5.x/webframe.html#Tutorial%2003b%20-%20Adding%20Series%20to%20a%20Chart%20with%20MVVM.html

I’ve read the documentation for adding data on multiple axes and have run into a wall. I have cases where I will need to have data only on one axis and other times when I will have data on both. For now I’m just setting up my 2 series in the XAML but not adding data to the 2nd Y axis yet. When I do this my series doesn’t show on the chart anymore.

Here is what I had when it worked…

            <s:SciChartSurface.YAxes>

            <!-- Dose Axis -->
            <s:NumericAxis AxisTitle="Dose (%)" AutoRange="{Binding Path=YAutoRange}"
                           AxisAlignment="Left"
                           FontFamily="Arial"
                           GrowBy="0.05, 0.05" 
                           Style="{DynamicResource ResourceKey=DoseAxisStyle}"
                           s:CursorModifier.AxisLabelContainerStyle="{StaticResource CursorModAxisLabelStyle}"
                           s:CursorModifier.AxisLabelTemplate="{StaticResource CursorModAxisLabelTemplate}" />


        </s:SciChartSurface.YAxes>

And here is what I have now…

            <s:SciChartSurface.YAxes>

            <!-- Dose Axis -->
            <s:NumericAxis AxisTitle="Dose (%)" AutoRange="{Binding Path=YAutoRange}"
                           AxisAlignment="Left"
                           FontFamily="Arial"
                           GrowBy="0.05, 0.05" 
                           Style="{DynamicResource ResourceKey=DoseAxisStyle}"
                           s:CursorModifier.AxisLabelContainerStyle="{StaticResource CursorModAxisLabelStyle}"
                           s:CursorModifier.AxisLabelTemplate="{StaticResource CursorModAxisLabelTemplate}" />

            <!-- 2nd Y Axis -->
            <s:NumericAxis AxisTitle="{Binding Path=RightAxisTitle}" 
                           Id="YAxis2"
                           AxisAlignment="Right"
                           Visibility="{Binding Path=RightAxisVisibility}"
                           AutoRange="{Binding Path=YAutoRange}"
                           FontFamily="Arial"
                           GrowBy="0.05, 0.05" 
                           Style="{DynamicResource ResourceKey=DoseAxisStyle}"
                           s:CursorModifier.AxisLabelContainerStyle="{StaticResource CursorModAxisLabelStyle}"
                           s:CursorModifier.AxisLabelTemplate="{StaticResource CursorModAxisLabelTemplate}" />

        </s:SciChartSurface.YAxes>

My model includes code such as…

        // data context for the series(s) on the chart
        public ObservableCollection<IRenderableSeriesViewModel> Measurements
        {
            get { return _measurements; }
            set { SetProperty(ref _measurements, value); }
        }

        private void AddMeasurementSync(MeasurementViewModel measurement, bool clear = false)
        {
        if (clear)
            // clear the profiles, we're only showing one at a time.
            Measurements.Clear();

        // add profile points to the data series
        var xyProfile = new XyDataSeries<double, double>();
        var xyLeft = new XyDataSeries<double, double>();
        var xyRight = new XyDataSeries<double, double>();

        xyProfile.AcceptsUnsortedData = true;
        xyLeft.AcceptsUnsortedData = true;
        xyRight.AcceptsUnsortedData = true;

        // loop the measurement points and fill the series
        foreach (MeasurementPointViewModel point in measurement.Points)
        {
            if (null != point)
                // add the point to the series and add IPointMetaData
                // which says whether or not we are in the penumbra
                xyProfile.Append(
                    point.Distance,
                    point.Dose);
        }

        // create series for profile          
        LineRenderableSeriesViewModel series = new LineRenderableSeriesViewModel()
        {
            StrokeThickness = 2,
            Stroke = measurement.MeasurementColor,
            AntiAliasing = true,
            DataSeries = xyProfile,
        };

        // should be showing points?
        if (ShowPoints)
        {
            series.PointMarker = new EllipsePointMarker()
            {
                Stroke = Colors.Black,
                Fill = Colors.White,
                Width = 6,
                Height = 6,
            };
        }

        // bind to the collection
        Measurements.Add(series);
    }
Version
5.2.2.11833
  • You must to post comments
0
0

Hi Chris,

I can’t see anything immediately wrong in the code you’ve posted, but it’s not a complete sample (there are parts of the code we can’t see such as styles etc…)

Also you’ve said ‘does not work’ but not described what that means.

Some things to check when adding multiple axis:

  • Ensure that each YAxis has an ID or the ID field is left blank (in which case it defaults to AxisCore.DefaultAxisId)
  • Ensure that for a series to appear on a YAxis, the RenderableSeries.YAxisId property is set to the YAxis.Id
  • Ensure that for a series to appear on a default axis (A YAxis without an ID), the RenderableSeries.YAxisId is not set
  • Check the Visual Studio output window when the application is run, as errors are reported there
  • Use the DebugWhySciChartDoesntRender flag to check for additional output
  • Don’t forget that annotations must also be registered on an axis.

Let me know if this helps you find the problem.

Best regards,
Andrew

  • Chris Kirkman
    Sorry Andrew, I wasn’t clear. What I meant was that the entire chart was blank under those circumstances. I’ll look at your suggestions and get back to you. Thanks.
  • Andrew Burnett-Thompson
    DebugWhySciChartDoesntRender is the place to start. That will tell you any warnings or errors. Second thing is to remove things like styles or properties one by one and strip the application down to the minimum which reproduces the problem. Sometimes it’s possible to find or isolate a mistake that way. If not, you have a good bug repro :)
  • Chris Kirkman
    thanks. naming the 2nd axis and then making sure I set the AxisId to that name took care of it.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies