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

1
0

Hello,

I have this app : https://i.ibb.co/sPXMbf1/screenshot-framed-1.png

I would like the graph below (the XyDataSeries) to be drawn from right to left (currently it is drawn from left to right)

I have this function to draw :

val audioDS = XyDataSeries<Int, Short>().apply { fifoCapacity = audioStreamBufferSize }
fun generateAudioStream(buffer: ShortValues) {
           val longs = IntegerValues(buffer.size())
           longs.setSize(buffer.size())
           for (i in 0 until buffer.size()) {
               longs[i] = time++
           }
           audioDS.append(longs, buffer)
        }

And my graph is initialized like this :

 @Override
public void initGraph(Context context) {
    Log.d(TAG, "initGraphs");
    SciChartSurface audioStreamSciChart = new SciChartSurface(context);
    mAudiostream.addView(audioStreamSciChart);
    xAxis = new NumericAxis(context);
    xAxis.setVisibleRange(new DoubleRange(startAudioStreamRange, endAudioStreamRange));
    xAxis.setDrawLabels(false);
    xAxis.setDrawMinorTicks(false);
    xAxis.setDrawMajorBands(false);
    xAxis.setDrawMinorGridLines(false);
    audioStreamSciChart.getXAxes().add(xAxis);

    NumericAxis yAxis = new NumericAxis(context);
    yAxis.setVisibleRange(new DoubleRange(new DoubleRange((double) Short.MIN_VALUE, (double) Short.MAX_VALUE)));
    yAxis.setDrawLabels(true);
    yAxis.setDrawMinorTicks(false);
    yAxis.setDrawMajorBands(false);
    yAxis.setDrawMinorGridLines(false);
    yAxis.setAxisAlignment(AxisAlignment.Left);

    audioStreamSciChart.getYAxes().add(yAxis);

    float lineThickness = SciChartExtensionsKt.dip(context, 1.0F);

    FastLineRenderableSeries f = new FastLineRenderableSeries();
    f.setDataSeries(scichartTools.getAudioDS());
    f.setStrokeStyle(new SolidPenStyle(ColorUtil.Grey, true, lineThickness, null));
    audioStreamSciChart.getRenderableSeries().add(f);
    scichartLayout = mAudiostream.getChildAt(0);
}

I understand that, currently it’s drawn from left to right because i append data on my audioDS, is it possible to make it draw from right to left instead ?

Best regards,
Wavely

Version
2.2.2.2424
  • You must to post comments
0
0

Hi Damien

In SciChart it is really easy to flip the chart from right to left, by setting the property XAxis.FlipCoordinates = true.

In Android, this looks like this

   xAxis.setFlipCoordinates(true); 

In iOS it looks like this (see related question)

// Obj-C
id<SCIAxis2D> yAxis = [[SCINumericAxis alloc] init];
yAxis.axisId = @"yAxis";
[yAxis setFlipCoordinates:YES];
[yAxis setAxisAlignment:SCIAxisAlignment_Top];
[surface attachAxis:yAxis IsXAxis:NO];

// Swift
weak var yAxis = SCINumericAxis() as? SCIAxis2D
yAxis?.axisId = "yAxis"
yAxis?.flipCoordinates = true
yAxis?.axisAlignment = SCIAxisAlignment_Top
surface.attachAxis(yAxis, isXAxis: false)

The result will be the entire XAxis starts at XAxis.VisibleRange.Max and draws to XAxis.VisibleRange.Min, and series on this axis will be reversed. There will be no loss in performance by doing this.

Does this answer your question?

Best regards
Andrew

  • You must to post comments
0
0

Yes, thank you, it works. On the other hand, a small question that is not at all in the theme of the post: if for the graph of the spectrogram (the one above), I decide to draw a horizontal line. Can i do that? Something like that:
https://i.ibb.co/617TmD2/screenshot-line.png

This line would have the value of the cursor at the bottom

Thanks,
Best regards

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.