Pre loader

I can't get a second Y axis working with all code-behind

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 took your simple line chart quick start and am attempting to add a second series on a second Y axis. It works fine as long as both series are rendered on yAxis1 but as soon as I uncomment out the line chart1.YAxes.Add(yAxis2) I get a blank chart instead (doesn’t matter if lineSeries2.YAxis is set to yAxis1 or yAxis2 – same result). I can’t figure out what the problem is.

        var xAxis = new NumericAxis();
        chart1.XAxis = xAxis;

        var yAxis1 = new NumericAxis();
        yAxis1.AxisAlignment = AxisAlignment.Left;
        chart1.YAxes.Add(yAxis1);

        var yAxis2 = new NumericAxis();
        yAxis2.AxisAlignment = AxisAlignment.Right;
        //chart1.YAxes.Add(yAxis2);

        var series1 = new XyDataSeries<double, double>();
        series1.SeriesName = "Sinewave1";

        var series2 = new XyDataSeries<double, double>();
        series2.SeriesName = "Sinewave2";

        for (int i = 0; i < 1000; i++)
        {
            series1.Append(i, Math.Sin(2 * Math.PI * i / 1000));
            series2.Append(i, Math.Sin(2 * Math.PI * i / 500) * 2);
        }

        var lineSeries1 = new FastLineRenderableSeries();
        lineSeries1.DataSeries = series1;
        lineSeries1.YAxis = yAxis1;
        chart1.RenderableSeries.Add(lineSeries1);

        var lineSeries2 = new FastLineRenderableSeries();
        lineSeries2.DataSeries = series2;
        lineSeries2.YAxis = yAxis1;
        chart1.RenderableSeries.Add(lineSeries2);
  • You must to post comments
0
0

Ok, I figured it out. I have to set the YAxisId property on the line renderers instead of YAxis. Not sure why, I would expect either to work?

This code works:

        var xAxis = new NumericAxis();
        chart1.XAxis = xAxis;

        var yAxis1 = new NumericAxis();
        yAxis1.AxisAlignment = AxisAlignment.Left;
        yAxis1.Id = "yAxis1";
        chart1.YAxes.Add(yAxis1);

        var yAxis2 = new NumericAxis();
        yAxis2.AxisAlignment = AxisAlignment.Right;
        yAxis2.Id = "yAxis2";
        chart1.YAxes.Add(yAxis2);

        var series1 = new XyDataSeries<double, double>();
        series1.SeriesName = "Sinewave1";

        var series2 = new XyDataSeries<double, double>();
        series2.SeriesName = "Sinewave2";

        for (int i = 0; i < 1000; i++)
        {
            series1.Append(i, Math.Sin(2 * Math.PI * i / 1000));
            series2.Append(i, Math.Sin(2 * Math.PI * i / 500) * 2);
        }

        var lineSeries1 = new FastLineRenderableSeries();
        lineSeries1.DataSeries = series1;
        lineSeries1.YAxisId = "yAxis1";
        chart1.RenderableSeries.Add(lineSeries1);

        var lineSeries2 = new FastLineRenderableSeries();
        lineSeries2.DataSeries = series2;
        lineSeries2.YAxisId = "yAxis2";
        chart1.RenderableSeries.Add(lineSeries2);
  • 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