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!

0
0

How can I append a float array to an XYDataSeries?

I’m developing an app with scichart. I receive buffers of 20 floats in a float[] type. How can I append this buffer to an XYDataSeries? The chart is updated in real time each time one Buffer is received with FIFO capacity.

What I need is something similar to:

void updateChart(final float[] a, final float[] b) {
    UpdateSuspender.using(surface, new Runnable() {
            @Override
            public void run() {
                // Append the new data received
                lineData.append(a,b);
                // Zoom series to fit the viewport to the x variable
                surface.zoomExtentsX();
            }
        });
}

Is this possible?
Thank you in advance

Version
Using Maven repository
  • You must to post comments
1
0

Hi Eduardo,

Thanks for your enquiry.

I would suggest you to use next code which uses FloatValues :

private IXyDataSeries<Float, Float> dataSeries;

void updateChart(final float[] a, final float[] b) {
    UpdateSuspender.using(surface, new Runnable() {
        @Override
        public void run() {
            // wrap primitive arrays into FloatValues
            final FloatValues xValues = new FloatValues(a);
            final FloatValues yValues = new FloatValues(b);

            // Append the new data received
            dataSeries.append(xValues, yValues);

            // Zoom series to fit the viewport to the x variable
            surface.zoomExtentsX();
        }
    });
}

We use similar approach in our real-time demos because it allows to avoid boxing/unboxing of primitive types caused by using generic TX/TY params in data series.

Is this suitable for you?

Best regards,
Yura

  • Eduardo Santamaría Vázquez
    It works like a charm, thank you very much! I didn’t know about the existence of these type of wrappers
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.