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.
The 3D Android Realtime example of Surface Mesh shows how to update a UniformGridDataSeries3D in real-time to render a 3D SurfaceMeshRenderableSeries3D.
Read more in SciChart 3D Android Chart Tutorial:
The full source code for the Android 3D Realtime Surface Mesh 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
//
// RealTimeUniformMeshChart3DFragment.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.realtime3DCharts.kt
import com.scichart.charting.visuals.axes.AutoRange.Always
import com.scichart.charting3d.model.dataSeries.IndexCalculator
import com.scichart.charting3d.visuals.SciChartSurface3D
import com.scichart.charting3d.visuals.renderableSeries.data.GradientColorPalette
import com.scichart.core.model.DoubleValues
import com.scichart.data.model.DoubleRange
import com.scichart.drawing.utility.ColorUtil.*
import com.scichart.examples.fragments.base.ExampleSingleChart3DBaseFragment
import com.scichart.examples.utils.scichartExtensions.*
import java.util.*
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledFuture
import java.util.concurrent.TimeUnit
import kotlin.math.sin
import kotlin.math.sqrt
class RealTimeUniformMeshChart3DFragment : ExampleSingleChart3DBaseFragment() {
private val scheduledExecutorService = Executors.newSingleThreadScheduledExecutor()
private lateinit var schedule: ScheduledFuture<*>
val dataSeries = UniformGridDataSeries3D<Double, Double, Double>(WIDTH, HEIGHT)
override fun initExample(surface3d: SciChartSurface3D) {
surface3d.suspendUpdates {
xAxis = numericAxis3D { autoRange = Always }
yAxis = numericAxis3D { visibleRange = DoubleRange(0.0, 1.0) }
zAxis = numericAxis3D { autoRange = Always }
renderableSeries {
surfaceMeshRenderableSeries3D {
dataSeries = this@RealTimeUniformMeshChart3DFragment.dataSeries
stroke = 0x7FFFFFFF
strokeThickness = 1f
drawSkirt = false
minimum = 0.0
maximum = 0.5
shininess = 64f
meshColorPalette = GradientColorPalette(
intArrayOf(0xFF1D2C6B.toInt(), Blue, Cyan, GreenYellow, Yellow, Red, DarkRed),
floatArrayOf(0f, .1f, .3f, .5f, .7f, .9f, 1f)
)
}
}
chartModifiers { defaultModifiers3D() }
}
schedule = scheduledExecutorService.scheduleWithFixedDelay(scheduledRunnable, 0, 33, TimeUnit.MILLISECONDS)
}
private val scheduledRunnable: Runnable = object : Runnable {
private val buffer = DoubleValues()
private var frames = 0
override fun run() {
binding.surface3d.suspendUpdates {
val wc = WIDTH * 0.5
val hc = HEIGHT * 0.5
val freq = sin(frames++ * 0.1) * 0.1 + 0.1
val indexCalculator: IndexCalculator = dataSeries.indexCalculator
buffer.setSize(indexCalculator.size)
val items = buffer.itemsArray
for (i in 0 until HEIGHT) {
for (j in 0 until WIDTH) {
val radius = sqrt((wc - i) * (wc - i) + (hc - j) * (hc - j))
val d = Math.PI * radius * freq
val value = sin(d) / d
val index = indexCalculator.getIndex(i, j)
items[index] = if (value.isNaN()) 1.toDouble() else value
}
}
dataSeries.copyFrom(buffer)
}
}
}
override fun onDestroyView() {
super.onDestroyView()
schedule.cancel(true)
}
companion object {
private const val WIDTH = 50
private const val HEIGHT = 50
}
}
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2021. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// CreateRealTimeUniformMeshChart3DFragment.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.realtime3DCharts;
import com.scichart.charting3d.model.dataSeries.IndexCalculator;
import com.scichart.charting3d.model.dataSeries.grid.UniformGridDataSeries3D;
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.surfaceMesh.SurfaceMeshRenderableSeries3D;
import com.scichart.core.framework.UpdateSuspender;
import com.scichart.core.model.DoubleValues;
import com.scichart.examples.fragments.base.ExampleSingleChart3DBaseFragment;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import static com.scichart.charting.visuals.axes.AutoRange.Always;
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 androidx.annotation.NonNull;
public class RealTimeUniformMeshChart3DFragment extends ExampleSingleChart3DBaseFragment {
private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
private ScheduledFuture<?> schedule;
private static final int WIDTH = 50;
private static final int HEIGHT = 50;
final UniformGridDataSeries3D<Double, Double, Double> dataSeries = new UniformGridDataSeries3D<>(Double.class, Double.class, Double.class, WIDTH, HEIGHT);
@Override
protected void initExample(@NonNull SciChartSurface3D surface3d) {
final NumericAxis3D xAxis = sciChart3DBuilder.newNumericAxis3D().withAutoRangeMode(Always).build();
final NumericAxis3D yAxis = sciChart3DBuilder.newNumericAxis3D().withVisibleRange(0, 1).build();
final NumericAxis3D zAxis = sciChart3DBuilder.newNumericAxis3D().withAutoRangeMode(Always).build();
final SurfaceMeshRenderableSeries3D rs = sciChart3DBuilder.newSurfaceMeshSeries3D()
.withDataSeries(dataSeries)
.withStroke(0x7FFFFFFF)
.withStrokeThicknes(1f)
.withDrawSkirt(false)
.withMinimum(0)
.withMaximum(0.5)
.withShininess(64f)
.withMeshColorPalette(new GradientColorPalette(
new int[]{0xFF1D2C6B, Blue, Cyan, GreenYellow, Yellow, Red, DarkRed},
new float[]{0, .1f, .3f, .5f, .7f, .9f, 1}
))
.build();
UpdateSuspender.using(surface3d, () -> {
surface3d.setXAxis(xAxis);
surface3d.setYAxis(yAxis);
surface3d.setZAxis(zAxis);
surface3d.getRenderableSeries().add(rs);
surface3d.getChartModifiers().add(sciChart3DBuilder.newModifierGroupWithDefaultModifiers().build());
});
schedule = scheduledExecutorService.scheduleWithFixedDelay(scheduledRunnable, 0, 33, TimeUnit.MILLISECONDS);
}
private final Runnable scheduledRunnable = new Runnable() {
private final DoubleValues buffer = new DoubleValues();
private int frames = 0;
@Override
public void run() {
UpdateSuspender.using(binding.surface3d, () -> {
double wc = WIDTH * 0.5, hc = HEIGHT * 0.5;
double freq = Math.sin(frames++ * 0.1) * 0.1 + 0.1;
final IndexCalculator indexCalculator = dataSeries.getIndexCalculator();
buffer.setSize(indexCalculator.size);
final double[] items = buffer.getItemsArray();
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
final double radius = Math.sqrt((wc - i) * (wc - i) + (hc - j) * (hc - j));
final double d = Math.PI * radius * freq;
final double value = Math.sin(d) / d;
final int index = indexCalculator.getIndex(i, j);
items[index] = Double.isNaN(value) ? 1 : value;
}
}
dataSeries.copyFrom(buffer);
});
}
};
@Override
public void onDestroyView() {
super.onDestroyView();
if (schedule != null) {
schedule.cancel(true);
}
}
}