Chart 3D Builders Helper Classes

Like 2D Chart SciChart Android 3D provides Builder API for creation and configuring of a SciChartSurface3D. They follow the XXXBuilder naming pattern and allow to initialize virtually anything in an easier and more convenient way. Different property of classes can be preset via the withXXX(…) methods of the helpers, a.k.a. "chart builders".

Referencing SciChart Builders

SciChart builders for 3D charts provided as seperate library which is called 'extensions3d'. If you want to use then you'll need to add it into your project as dependency. This is available from our Maven feed, or in the Android Charts SDK at www.scichart.com/downloads.

Adding extension library
Copy Code
dependencies {        
     // Declare SciChart3D libraries as module dependencies
     implementation (name:'charting-release', ext:'aar')
     implementation (name:'charting3d-release', ext:'aar')
     implementation (name:'drawing-release', ext:'aar')
     implementation (name:'data-release', ext:'aar')
     implementation (name:'core-release', ext:'aar'
     // Declare SciChart extension library as module dependency
     implementation (name:'extensions-release', ext:'aar')
     // Declare SciChart3D extension library as module dependency
     implementation (name:'extensions3d-release', ext:'aar')
}

Using Chart Builders in Code

The main chart builder class is called SciChart3DBuilder. It acts as a factory of builders of other types, representing different chart aspects.

Using chart builders, the code snippet for chart initialization from the section above can be rewritten as follows:

Example
Copy Code
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout from “base_scichart_layout.xml”
    View view = inflater.inflate(R.layout.base_scichart_layout, container, false);

    // find the surface by id
    SciChartSurface3D surface3d = view.findViewById(R.id.chart);
    // need to init SciChart3DBuilder class with application context before using
    SciChart3DBuilder.init(this);
    // obtain the SciChart3DBuilder instance
    final SciChart3DBuilder sciChart3dBuilder = SciChart3DBuilder.instance();

    // create numeric X axis
    final IAxis3D xAxis = sciChart3dBuilder.newNumericAxis3D()
            .withVisibleRange(-5, 15)
            .build();

    // create a numeric Y axis
    final IAxis3D yAxis = sciChart3dBuilder.newNumericAxis3D()
            .withVisibleRange(0, 100)
            .build();
    // create a numeric Z axis
    final IAxis3D zAxis = sciChart3dBuilder.newNumericAxis3D()
            .withVisibleRange(0, 100)
            .build();

    // create interactivity modifiers
    ModifierGroup3D chartModifiers = sciChart3dBuilder.newModifierGroupWithDefaultModifiers().build();
    // set axes for 3D chart
    surface3d.setXAxis(xAxis);
    surface3d.setYAxis(yAxis);
    surface3d.setZAxis(zAxis);
    // add the interactions to the ChartModifiers collection of the surface
    Collections.addAll(surface3d.getChartModifiers(), chartModifiers);

    return view;
}

Usually this approach to chart initialization results in more concise and elegent code. It is preferred for the vast majority of examples from the Android Examples Suite. We would recommend using it in applications too. However, it doesn't give any other benefits except those stated above, so the standard way of objects initialization is equally fine.