SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
SciChart Android ships with ~90Â Android Chart Examples which you can browse, play with, view the source-code and even export each SciChart Android Chart Example to a stand-alone Android Studio project. All of this is possible with the new and improved SciChart Android Examples Suite, which ships as part of our Android Charts SDK.
This example demonstrates how to create a 3D Ellipsoid Chart for Android applications with SciChart. An Ellipsoid 3D Android Charts are rendered by the EllipsoidDataSeries3D and FreeSurfaceRenderableSeries3D. Flexible SciChart API lets you define the Cylindroid location and size, as well as set different palette modes (Radial, Axial, Polar and Azimuthal).
You may find out more in the SciChart Android Documentation for The Android Ellipsoid 3D Chart Type.
See also, other examples of different kind of shapes possible with the FreeSurfaceRenderableSeries3D, including Sphere, Cylinder, Disc and free-form mesh shapes:
The full source code for the Android 3D Simple Cylindroid Chart example is included below (Scroll down!).
Did you know you can also view the source code from one of the following sources as well?
<?xml version="1.0" encoding="utf-8"?>
<!--*************************************************************************-->
<!-- SCICHART® Copyright SciChart Ltd. 2011-2018. All rights reserved. -->
<!-- -->
<!-- Web: http://www.scichart.com -->
<!-- Support: support@scichart.com -->
<!-- Sales: sales@scichart.com -->
<!-- -->
<!-- example_create_free_surface_3d_fragmentent.xml is part of the SCICHART® Examples. Permission is hereby granted -->
<!-- to modify, create derivative works, distribute and publish any part of this source -->
<!-- code whether for commercial, private or personal use. -->
<!-- -->
<!-- The SCICHART® examples are distributed in the hope that they will be useful, but -->
<!-- without any warranty. It is provided "AS IS" without warranty of any kind, either -->
<!-- expressed or implied. -->
<!--*************************************************************************-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:gravity="center"
android:text="@string/palette_mode" />
<Spinner
android:id="@+id/paletteModeSelector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="5dp"
android:background="@android:color/transparent" />
</LinearLayout>
<com.scichart.charting3d.visuals.SciChartSurface3D
android:id="@+id/chart3d"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2021. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// EllipsoidMesh3DChartFragment.kt is part of SCICHART®, High Performance Scientific Charts
// For full terms and conditions of the license, see http://www.scichart.com/scichart-eula/
//
// This source code is protected by international copyright law. Unauthorized
// reproduction, reverse-engineering, or distribution of all or any portion of
// this source code is strictly prohibited.
//
// This source code contains confidential and proprietary trade secrets of
// SciChart Ltd., and should at no time be copied, transferred, sold,
// distributed or made available without express written permission.
//******************************************************************************
package com.scichart.examples.fragments.examples3d.basicChartTypes.kt
import android.view.LayoutInflater
import android.view.View
import android.widget.AdapterView
import com.scichart.charting.visuals.axes.AutoRange.Never
import com.scichart.charting3d.common.math.Vector3
import com.scichart.charting3d.visuals.renderableSeries.data.DrawMeshAs
import com.scichart.charting3d.visuals.renderableSeries.data.GradientColorPalette
import com.scichart.charting3d.visuals.renderableSeries.freeSurface.FreeSurfacePaletteMinMaxMode
import com.scichart.charting3d.visuals.renderableSeries.freeSurface.FreeSurfaceRenderableSeries3D
import com.scichart.data.model.DoubleRange
import com.scichart.drawing.utility.ColorUtil
import com.scichart.examples.R
import com.scichart.examples.components.SpinnerStringAdapter
import com.scichart.examples.databinding.ExampleCreateFreeSurface3dFragmentBinding
import com.scichart.examples.fragments.base.ExampleBaseFragment
import com.scichart.examples.utils.ItemSelectedListenerBase
import com.scichart.examples.utils.scichartExtensions.*
import java.util.*
import kotlin.math.abs
class EllipsoidMesh3DChartFragment : ExampleBaseFragment<ExampleCreateFreeSurface3dFragmentBinding>() {
override fun inflateBinding(inflater: LayoutInflater): ExampleCreateFreeSurface3dFragmentBinding {
return ExampleCreateFreeSurface3dFragmentBinding.inflate(inflater)
}
override fun initExample(binding: ExampleCreateFreeSurface3dFragmentBinding) {
binding.surface3d.suspendUpdates {
xAxis = numericAxis3D { visibleRange = DoubleRange(-7.0, 7.0); autoRange = Never }
yAxis = numericAxis3D { visibleRange = DoubleRange(-7.0, 7.0); autoRange = Never }
zAxis = numericAxis3D { visibleRange = DoubleRange(-7.0, 7.0); autoRange = Never }
renderableSeries {
freeSurfaceRenderableSeries3D {
val random = Random()
ellipsoidDataSeries3D<Double>(sizeU, sizeV) {
a = 6.0
b = 6.0
c = 6.0
for (u in 0 until sizeU) {
for (v in 0 until sizeV) {
val weight = 1.0 - abs(2.0 * v / sizeV - 1.0)
val offset = random.nextDouble()
setDisplacement(u, v, offset * weight)
}
}
}
drawMeshAs = DrawMeshAs.SolidWireframe
stroke = 0x77228B22
contourInterval = 0.1f
contourStroke = 0x77228B22
strokeThickness = 1f
lightingFactor = 0.8f
drawBackSide = true
meshColorPalette = GradientColorPalette(
intArrayOf(0xFF1D2C6B.toInt(), ColorUtil.Blue, ColorUtil.Cyan, ColorUtil.GreenYellow, ColorUtil.Yellow, ColorUtil.Red, ColorUtil.DarkRed),
floatArrayOf(0f, .1f, .3f, .5f, .7f, .9f, 1f)
)
binding.paletteModeSelector.run {
adapter = SpinnerStringAdapter(activity, R.array.palette_mode_list)
setSelection(0)
onItemSelectedListener = object : ItemSelectedListenerBase() {
override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
switchPaletteMode(this@freeSurfaceRenderableSeries3D, position)
}
}
}
}
}
chartModifiers { defaultModifiers3D() }
worldDimensions.assign(200f, 200f, 200f)
}
}
private fun switchPaletteMode(rs: FreeSurfaceRenderableSeries3D, paletteMode: Int) {
when (paletteMode) {
0 -> {
rs.paletteMinMaxMode = FreeSurfacePaletteMinMaxMode.Relative
rs.paletteMinimum = Vector3(0f, 6f, 0f)
rs.paletteMaximum = Vector3(0f, 7f, 0f)
rs.paletteRadialFactor = 1f
rs.paletteAxialFactor = Vector3(0f, 0f, 0f)
rs.paletteAzimuthalFactor = 0f
rs.palettePolarFactor = 0f
}
1 -> {
rs.paletteMinMaxMode = FreeSurfacePaletteMinMaxMode.Absolute
rs.paletteMinimum = Vector3(0f, -4f, 0f)
rs.paletteMaximum = Vector3(0f, 4f, 0f)
rs.paletteRadialFactor = 0f
rs.paletteAxialFactor = Vector3(0f, 1f, 0f)
rs.paletteAzimuthalFactor = 0f
rs.palettePolarFactor = 0f
}
2 -> {
rs.paletteRadialFactor = 0f
rs.paletteAxialFactor = Vector3(0f, 0f, 0f)
rs.paletteAzimuthalFactor = 1f
rs.palettePolarFactor = 0f
}
3 -> {
rs.paletteRadialFactor = 0f
rs.paletteAxialFactor = Vector3(0f, 0f, 0f)
rs.paletteAzimuthalFactor = 0f
rs.palettePolarFactor = 1f
}
else -> throw UnsupportedOperationException()
}
}
companion object {
const val sizeU = 40
const val sizeV = 20
}
}
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2021. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// CreateEllipsoidMesh3DChartFragment.java is part of SCICHART®, High Performance Scientific Charts
// For full terms and conditions of the license, see http://www.scichart.com/scichart-eula/
//
// This source code is protected by international copyright law. Unauthorized
// reproduction, reverse-engineering, or distribution of all or any portion of
// this source code is strictly prohibited.
//
// This source code contains confidential and proprietary trade secrets of
// SciChart Ltd., and should at no time be copied, transferred, sold,
// distributed or made available without express written permission.
//******************************************************************************
package com.scichart.examples.fragments.examples3d.basicChartTypes;
import static com.scichart.charting.visuals.axes.AutoRange.Never;
import static com.scichart.charting3d.visuals.renderableSeries.data.DrawMeshAs.SolidWireframe;
import static com.scichart.drawing.utility.ColorUtil.Blue;
import static com.scichart.drawing.utility.ColorUtil.Cyan;
import static com.scichart.drawing.utility.ColorUtil.DarkRed;
import static com.scichart.drawing.utility.ColorUtil.GreenYellow;
import static com.scichart.drawing.utility.ColorUtil.Red;
import static com.scichart.drawing.utility.ColorUtil.Yellow;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import androidx.annotation.NonNull;
import com.scichart.charting3d.common.math.Vector3;
import com.scichart.charting3d.model.dataSeries.freeSurface.EllipsoidDataSeries3D;
import com.scichart.charting3d.visuals.SciChartSurface3D;
import com.scichart.charting3d.visuals.axes.NumericAxis3D;
import com.scichart.charting3d.visuals.renderableSeries.data.GradientColorPalette;
import com.scichart.charting3d.visuals.renderableSeries.freeSurface.FreeSurfacePaletteMinMaxMode;
import com.scichart.charting3d.visuals.renderableSeries.freeSurface.FreeSurfaceRenderableSeries3D;
import com.scichart.core.framework.UpdateSuspender;
import com.scichart.examples.R;
import com.scichart.examples.components.SpinnerStringAdapter;
import com.scichart.examples.databinding.ExampleCreateFreeSurface3dFragmentBinding;
import com.scichart.examples.fragments.base.ExampleBaseFragment;
import com.scichart.examples.utils.ItemSelectedListenerBase;
import java.util.Random;
public class EllipsoidMesh3DChartFragment extends ExampleBaseFragment<ExampleCreateFreeSurface3dFragmentBinding> {
@NonNull
@Override
protected ExampleCreateFreeSurface3dFragmentBinding inflateBinding(@NonNull LayoutInflater inflater) {
return ExampleCreateFreeSurface3dFragmentBinding.inflate(inflater);
}
@Override
protected void initExample(@NonNull ExampleCreateFreeSurface3dFragmentBinding binding) {
final NumericAxis3D xAxis = sciChart3DBuilder.newNumericAxis3D().withVisibleRange(-7, 7).withAutoRangeMode(Never).build();
final NumericAxis3D yAxis = sciChart3DBuilder.newNumericAxis3D().withVisibleRange(-7, 7).withAutoRangeMode(Never).build();
final NumericAxis3D zAxis = sciChart3DBuilder.newNumericAxis3D().withVisibleRange(-7, 7).withAutoRangeMode(Never).build();
final int sizeU = 40, sizeV = 20;
final EllipsoidDataSeries3D<Double> meshDataSeries = new EllipsoidDataSeries3D<>(Double.class, sizeU, sizeV);
meshDataSeries.setA(6d);
meshDataSeries.setB(6d);
meshDataSeries.setC(6d);
final Random random = new Random();
for (int u = 0; u < sizeU; u++) {
for (int v = 0; v < sizeV; v++) {
final double weight = 1d - Math.abs(2d * v / sizeV - 1d);
final double offset = random.nextDouble();
meshDataSeries.setDisplacement(u, v, offset * weight);
}
}
final FreeSurfaceRenderableSeries3D rs = sciChart3DBuilder.newFreeSurfaceSeries3D()
.withDataSeries(meshDataSeries)
.withDrawMeshAs(SolidWireframe)
.withStroke(0x77228B22)
.withContourInterval(0.1f)
.withContourStroke(0x77228B22)
.withStrokeThicknes(1f)
.withLightingFactor(0.8f)
.withMeshColorPalette(new GradientColorPalette(
new int[]{0xFF1D2C6B, Blue, Cyan, GreenYellow, Yellow, Red, DarkRed},
new float[]{0, .1f, .3f, .5f, .7f, .9f, 1})
)
.build();
final SciChartSurface3D surface3d = binding.surface3d;
UpdateSuspender.using(surface3d, () -> {
surface3d.setXAxis(xAxis);
surface3d.setYAxis(yAxis);
surface3d.setZAxis(zAxis);
surface3d.getRenderableSeries().add(rs);
surface3d.getChartModifiers().add(sciChart3DBuilder.newModifierGroupWithDefaultModifiers().build());
surface3d.getWorldDimensions().assign(200, 200, 200);
});
final Spinner paletteModeSelector = binding.paletteModeSelector;
paletteModeSelector.setAdapter(new SpinnerStringAdapter(getActivity(), R.array.palette_mode_list));
paletteModeSelector.setSelection(0);
paletteModeSelector.setOnItemSelectedListener(new ItemSelectedListenerBase() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switchPaletteMode(rs, position);
}
});
}
private void switchPaletteMode(FreeSurfaceRenderableSeries3D rs, int paletteMode) {
switch (paletteMode) {
// Radial
case 0:
rs.setPaletteMinMaxMode(FreeSurfacePaletteMinMaxMode.Relative);
rs.setPaletteMinimum(new Vector3(0f, 6f, 0f));
rs.setPaletteMaximum(new Vector3(0f, 7f, 0f));
rs.setPaletteRadialFactor(1f);
rs.setPaletteAxialFactor(new Vector3(0, 0, 0));
rs.setPaletteAzimuthalFactor(0f);
rs.setPalettePolarFactor(0f);
break;
// Axial
case 1:
rs.setPaletteMinMaxMode(FreeSurfacePaletteMinMaxMode.Absolute);
rs.setPaletteMinimum(new Vector3(0f, -4f, 0f));
rs.setPaletteMaximum(new Vector3(0f, 4f, 0f));
rs.setPaletteRadialFactor(0f);
rs.setPaletteAxialFactor(new Vector3(0f, 1f, 0f));
rs.setPaletteAzimuthalFactor(0f);
rs.setPalettePolarFactor(0f);
break;
// Azimuthal
case 2:
rs.setPaletteRadialFactor(0f);
rs.setPaletteAxialFactor(new Vector3(0f, 0f, 0f));
rs.setPaletteAzimuthalFactor(1f);
rs.setPalettePolarFactor(0f);
break;
// Polar
case 3:
rs.setPaletteRadialFactor(0f);
rs.setPaletteAxialFactor(new Vector3(0f, 0f, 0f));
rs.setPaletteAzimuthalFactor(0f);
rs.setPalettePolarFactor(1f);
break;
default:
throw new UnsupportedOperationException();
}
}
}