Search Results for

    Show / Hide Table of Contents

    SciChart Android 3D Tutorial - Create a simple Scatter Chart 3D

    In this SciChart Android 3D tutorial, you’ll learn to:

    • create a 3D Chart
    • add X, Y and Z Axes to a Chart;
    • render a Simple Scatter 3D Series;
    Note

    This tutorial assumes that you’ve already know how to Link SciChart Android and Add SciChartSurface3D instance into your Fragment. If you need more information - please read the following articles:

    • Integrating SciChart.framework
    • The SciChartSurface3D Type

    Getting Started

    This tutorial is suitable for Java and Kotlin.

    Note

    Source code for this tutorial can be found at our Github Repository: Java and Kotlin Tutorials 3D Repository

    Adding 3D Axes to the SciChartSurface3D

    Once you have added a SciChartSurface3D into your Fragment, you will not see anything drawn because you need to add axes. This is important: that three axes X, Y and Z has to be added to your surface.This is a bare minimum to see drawn grid on your device.

    • Java
    • Java with Builders API
    • Kotlin
    • Xamarin.Android
    surface.setXAxis(new NumericAxis3D());
    surface.setYAxis(new NumericAxis3D());
    surface.setZAxis(new NumericAxis3D());
    
    surface.setXAxis(sciChartBuilder.newNumericAxis3D().build());
    surface.setYAxis(sciChartBuilder.newNumericAxis3D().build());
    surface.setZAxis(sciChartBuilder.newNumericAxis3D().build());
    
    surface.xAxis = NumericAxis3D()
    surface.yAxis = NumericAxis3D()
    surface.zAxis = NumericAxis3D()
    
    surface.XAxis = new NumericAxis3D();
    surface.YAxis = new NumericAxis3D();
    surface.ZAxis = new NumericAxis3D();
    

    Empty SciChartSurface3D

    Adding 3D Renderable Series

    Now, we would like to see something more than just empty grid, e.g. Scatter 3D Chart. To draw some data in chart we need to create 3D DataSeries and RenderableSeries. The DataSeries is a class which is responsible for storing data which should be displayed and RenderableSeries is a class that determines how data should be visualized by chart.

    First, let's declare the 3D DataSeries and generate some data for it:

    • Java
    • Java with Builders API
    • Kotlin
    • Xamarin.Android
    final XyzDataSeries3D dataSeries = new XyzDataSeries3D(Double.class, Double.class, Double.class);
    for (int i = 0; i < 200; i++) {
        final double x = getGaussianRandomNumber(5.0, 1.5);
        final double y = getGaussianRandomNumber(5.0, 1.5);
        final double z = getGaussianRandomNumber(5.0, 1.5);
        dataSeries.append(x, y, z);
    }
    
    final XyzDataSeries3D dataSeries = new XyzDataSeries3D(Double.class, Double.class, Double.class);
    for (int i = 0; i < 200; i++) {
        final double x = getGaussianRandomNumber(5.0, 1.5);
        final double y = getGaussianRandomNumber(5.0, 1.5);
        final double z = getGaussianRandomNumber(5.0, 1.5);
        dataSeries.append(x, y, z);
    }
    
    val dataSeries = XyzDataSeries3D(Double::class.javaObjectType, Double::class.javaObjectType, Double::class.javaObjectType)
    for (i in 0..200) {
        val x = getGaussianRandomNumber(5.0, 1.5)
        val y = getGaussianRandomNumber(5.0, 1.5)
        val z = getGaussianRandomNumber(5.0, 1.5)
        dataSeries.append(x, y, z)
    }
    
    var dataSeries = new XyzDataSeries3D<double, double, double>();
    for (int i = 0; i < 200; i++)
    {
        var x = GetGaussianRandomNumber(5.0, 1.5);
        var y = GetGaussianRandomNumber(5.0, 1.5);
        var z = GetGaussianRandomNumber(5.0, 1.5);
        dataSeries.Append(x, y, z);
    }
    

    The next step is to create 3D RenderableSeries. In our case we're going to display data as a point cloud using Scatter Series 3D, which is represented by the ScatterRenderableSeries3D:

    • Java
    • Java with Builders API
    • Kotlin
    • Xamarin.Android
    final SpherePointMarker3D pointMarker = new SpherePointMarker3D();
    pointMarker.setFill(0xFF32CD32);
    pointMarker.setSize(10.0f);
    
    final ScatterRenderableSeries3D rSeries = new ScatterRenderableSeries3D();
    rSeries.setDataSeries(dataSeries);
    rSeries.setPointMarker(pointMarker);
    
    final SpherePointMarker3D pointMarker = sciChartBuilder.newSpherePointMarker3D()
            .withFill(0xFF32CD32)
            .withSize(10.0f)
            .build();
    
    final ScatterRenderableSeries3D rSeries = sciChartBuilder.newScatterSeries3D()
            .withDataSeries(dataSeries)
            .withPointMarker(pointMarker)
            .build();
    
    val pointMarker = SpherePointMarker3D()
    pointMarker.fill = 0xFF32CD32.toInt()
    pointMarker.size = 10.0f
    
    val rSeries = ScatterRenderableSeries3D()
    rSeries.dataSeries = dataSeries
    rSeries.pointMarker = pointMarker
    
    var rSeries = new ScatterRenderableSeries3D()
    {
        DataSeries = dataSeries,
        PointMarker = new SpherePointMarker3D()
        {
            Fill = new Color(0x32, 0xCD, 0x32, 0xFF),
            Size = 10
        }
    };
    

    Finally, we need to add newly created series into the renderableSeries collection, like so:

    • Java
    • Java with Builders API
    • Kotlin
    • Xamarin.Android
    Collections.addAll(surface.getRenderableSeries(), rSeries);
    
    Collections.addAll(surface.getRenderableSeries(), rSeries);
    
    Collections.addAll(surface.renderableSeries, rSeries)
    
    surface.RenderableSeries.Add(rSeries);
    

    Which will render the following Scatter Chart 3D:

    3D Scatter Chart

    Note

    Please note that we've added axes and renderableSeries to SciChartSurface3D inside using(ISuspendable suspendable, Runnable runnable) block. This allows to suspend surface instance and refresh it only one time after you finished all needed operations. That's highly recommended technique, if you want to omit performance decrease due to triggering refreshes on every operation which could be performed in one batch.

    Where to Go From Here?

    You can download the final project from our Java and Kotlin Tutorials 3D Repository.

    Also, you can found next tutorial from this series here - SciChart Android 3D Tutorial - Zooming and Rotating

    Of course, this is not the limit of what you can achieve with the SciChart Android 3D. Our documentation contains lots of useful information, some of the articles you might want to read are listed below:

    • 3D Axis Types
    • 3D Chart Types
    • 3D Chart Modifiers

    Finally, start exploring. The SciChart Android library and functionality is quite extensive. You can look into our SciChart Android Examples Suite which are full of 2D and 3D examples, which are also available on our GitHub

    Back to top © 2011-2025 SciChart. All rights reserved. | sitemap.xml