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 showcases how to create a Simple 3D Polar Chart in Android with SciChart. Polar 3D Charts are rendered by the PolarDataSeries3D type and FreeSurfaceRenderableSeries3D.
The SciChart Android chart library API allows you to define the Polar’s location and size, as well as set different palette modes (Radial, Axial, Polar and Azimuthal).
FreeSurfaceRenderableSeries3D allows you to create all kinds of shapes, including Sphere, Cylinder, Disc and free-form mesh shapes, and overlay heightmap, colormap (palette) and contours, empowering your slick Android applications. Take a look at other examples of shapes in this section: simple cylindroid chart, simple ellipsoid chart, closed mesh chart and a realtime ellipsoid mesh chart example.
Please find out more with SciChart Documentation:
The full source code for the Android 3D Simple Polar example is included below (Scroll down!).
Did you know you can also view the source code from one of the following sources as well?
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2021. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// PolarMesh3DChartFragment.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.*
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 PolarMesh3DChartFragment : ExampleBaseFragment<ExampleCreateFreeSurface3dFragmentBinding>() {
override fun inflateBinding(inflater: LayoutInflater): ExampleCreateFreeSurface3dFragmentBinding {
return ExampleCreateFreeSurface3dFragmentBinding.inflate(inflater)
}
override fun initExample(binding: ExampleCreateFreeSurface3dFragmentBinding) {
binding.surface3d.suspendUpdates {
xAxis = numericAxis3D()
yAxis = numericAxis3D { visibleRange = DoubleRange(0.0, 3.0) }
zAxis = numericAxis3D()
renderableSeries {
freeSurfaceRenderableSeries3D {
val random = Random()
polarDataSeries3D<Double, Double>(sizeU, sizeV, 0.0, Math.PI * 1.75) {
a = 1.0
b = 5.0
for (u in 0 until sizeU) {
val weightU = 1.0 - abs(2.0 * u / sizeU - 1.0)
for (v in 0 until sizeV) {
val weightV = 1.0 - abs(2.0 * v / sizeV - 1.0)
val offset = random.nextDouble()
setDisplacement(u, v, offset * weightU * weightV)
}
}
}
drawMeshAs = DrawMeshAs.SolidWireframe
stroke = 0x77228B22
contourInterval = 0.1f
contourStroke = 0x77228B22
strokeThickness = 1f
lightingFactor = 0.8f
drawBackSide = true
meshColorPalette = GradientColorPalette(
intArrayOf(0xFF1D2C6B.toInt(), Blue, Cyan, GreenYellow, Yellow, Red, 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, 50f, 200f)
}
}
private fun switchPaletteMode(rs: FreeSurfaceRenderableSeries3D, paletteMode: Int) {
when (paletteMode) {
0 -> {
rs.paletteMinMaxMode = FreeSurfacePaletteMinMaxMode.Relative
rs.paletteMinimum = Vector3(0f, 0f, 0f)
rs.paletteMaximum = Vector3(0f, 0.5f, 0f)
rs.paletteRadialFactor = 1f
rs.paletteAxialFactor = Vector3(0f, 0f, 0f)
rs.paletteAzimuthalFactor = 0f
rs.palettePolarFactor = 0f
}
1 -> {
rs.paletteMinMaxMode = FreeSurfacePaletteMinMaxMode.Absolute
rs.paletteMinimum = Vector3(-5f, 0f, -5f)
rs.paletteMaximum = Vector3(5f, 0f, 5f)
rs.paletteRadialFactor = 0f
rs.paletteAxialFactor = Vector3(0.5f, 0f, 0.5f)
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 = 30
const val sizeV = 10
}
}
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2021. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// CreatePolarMesh3DChartFragment.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 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.PolarDataSeries3D;
import com.scichart.charting3d.visuals.SciChartSurface3D;
import com.scichart.charting3d.visuals.axes.NumericAxis3D;
import com.scichart.charting3d.visuals.camera.Camera3D;
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.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;
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;
public class PolarMesh3DChartFragment 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().build();
final NumericAxis3D yAxis = sciChart3DBuilder.newNumericAxis3D().withVisibleRange(0, 3).build();
final NumericAxis3D zAxis = sciChart3DBuilder.newNumericAxis3D().build();
final int sizeU = 30, sizeV = 10;
final PolarDataSeries3D<Double, Double> meshDataSeries = new PolarDataSeries3D<>(Double.class, Double.class, sizeU, sizeV, 0d, Math.PI * 1.75);
meshDataSeries.setA(1d);
meshDataSeries.setB(5d);
final Random random = new Random();
for (int u = 0; u < sizeU; u++) {
final double weightU = 1d - Math.abs(2d * u / sizeU - 1d);
for (int v = 0; v < sizeV; v++) {
final double weightV = 1d - Math.abs(2d * v / sizeV - 1d);
final double offset = random.nextDouble();
meshDataSeries.setDisplacement(u, v, offset * weightU * weightV);
}
}
final FreeSurfaceRenderableSeries3D rs = sciChart3DBuilder.newFreeSurfaceSeries3D()
.withDataSeries(meshDataSeries)
.withDrawMeshAs(DrawMeshAs.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, 50, 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, 0f, 0f));
rs.setPaletteMaximum(new Vector3(0f, 0.5f, 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(-5f, 0f, -5f));
rs.setPaletteMaximum(new Vector3(5f, 0f, 5f));
rs.setPaletteRadialFactor(0f);
rs.setPaletteAxialFactor(new Vector3(0.5f, 0f, 0.5f));
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();
}
}
}