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.
Demonstrates how to use FastUniformHeatmapRenderableSeries and create a *Heatmap Chart with Text in the cells* in SciChart for Android.
The FastUniformHeatmapRenderableSeries requires an UniformHeatmapDataSeries, which contains 1D array with heatmap values and ColorMap instance which allows to map values to colors.
Tip!
You can customize style of text in cells by calling setCellTextStyle() method.
The full source code for the Android Heatmap Chart with Text 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
//
// HeatmapWithTextFragment.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.examples2d.basicChartTypes.kt
import android.view.LayoutInflater
import com.scichart.charting.model.dataSeries.IDataSeries
import com.scichart.data.model.DoubleRange
import com.scichart.drawing.common.FontStyle
import com.scichart.drawing.utility.ColorUtil
import com.scichart.examples.databinding.ExampleHeatmapWithTextFragmentBinding
import com.scichart.examples.fragments.base.ExampleBaseFragment
import com.scichart.examples.utils.scichartExtensions.*
import java.text.DecimalFormat
import java.util.*
import kotlin.math.pow
class HeatmapWithTextFragment : ExampleBaseFragment<ExampleHeatmapWithTextFragmentBinding>() {
override fun inflateBinding(inflater: LayoutInflater): ExampleHeatmapWithTextFragmentBinding {
return ExampleHeatmapWithTextFragmentBinding.inflate(inflater)
}
override fun initExample(binding: ExampleHeatmapWithTextFragmentBinding) {
binding.surface.suspendUpdates {
xAxes { numericAxis { growBy = DoubleRange(0.1, 0.1); flipCoordinates = true }}
yAxes { numericAxis { growBy = DoubleRange(0.1, 0.1); flipCoordinates = true }}
renderableSeries {
fastUniformHeatmapRenderableSeries {
minimum = 0.0
maximum = 100.0
cellTextStyle = FontStyle(8f.toDip(), ColorUtil.White)
drawTextInCell = true
dataSeries = createDataSeries()
binding.heatmapColourMap.run {
minimum = this@fastUniformHeatmapRenderableSeries.minimum
maximum = this@fastUniformHeatmapRenderableSeries.maximum
colorMap = this@fastUniformHeatmapRenderableSeries.colorMap
textFormat = DecimalFormat("0.##")
}
}
}
chartModifiers { defaultModifiers() }
}
}
private fun createDataSeries(): IDataSeries<*, *> {
val w = 12
val h = 7
val dataSeries = UniformHeatmapDataSeries<Int, Int, Double>(w, h)
val random = Random()
for (x in 0 until w) {
for (y in 0 until h) {
dataSeries.updateZAt(x, y, random.nextDouble().pow(0.15) * x / (w - 1) * y / (h - 1) * 100)
}
}
return dataSeries
}
}
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2021. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// HeatmapWithTextFragment.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.examples2d.basicChartTypes;
import android.view.LayoutInflater;
import androidx.annotation.NonNull;
import com.scichart.charting.model.dataSeries.IDataSeries;
import com.scichart.charting.model.dataSeries.UniformHeatmapDataSeries;
import com.scichart.charting.visuals.SciChartHeatmapColourMap;
import com.scichart.charting.visuals.SciChartSurface;
import com.scichart.charting.visuals.axes.NumericAxis;
import com.scichart.charting.visuals.renderableSeries.FastUniformHeatmapRenderableSeries;
import com.scichart.drawing.utility.ColorUtil;
import com.scichart.examples.databinding.ExampleHeatmapWithTextFragmentBinding;
import com.scichart.examples.fragments.base.ExampleBaseFragment;
import java.text.DecimalFormat;
import java.util.Collections;
import java.util.Random;
public class HeatmapWithTextFragment extends ExampleBaseFragment<ExampleHeatmapWithTextFragmentBinding> {
@NonNull
@Override
protected ExampleHeatmapWithTextFragmentBinding inflateBinding(@NonNull LayoutInflater inflater) {
return ExampleHeatmapWithTextFragmentBinding.inflate(inflater);
}
@Override
protected void initExample(ExampleHeatmapWithTextFragmentBinding binding) {
final NumericAxis xAxis = sciChartBuilder.newNumericAxis()
.withGrowBy(0.1, 0.1)
.withFlipCoordinates(true)
.build();
final NumericAxis yAxis = sciChartBuilder.newNumericAxis()
.withGrowBy(0.1, 0.1)
.withFlipCoordinates(true)
.build();
final FastUniformHeatmapRenderableSeries heatmapRenderableSeries = sciChartBuilder.newUniformHeatmap()
.withMinimum(0)
.withMaximum(100)
.withCellTextStyle(sciChartBuilder.newFont().withTextSize(8).withTextColor(ColorUtil.White).build())
.withDrawTextInCell(true)
.withDataSeries(createDataSeries())
.build();
final SciChartHeatmapColourMap colourMap = binding.heatmapColourMap;
colourMap.setMinimum(heatmapRenderableSeries.getMinimum());
colourMap.setMaximum(heatmapRenderableSeries.getMaximum());
colourMap.setColorMap(heatmapRenderableSeries.getColorMap());
colourMap.setTextFormat(new DecimalFormat("0.##"));
final SciChartSurface chart = binding.surface;
Collections.addAll(chart.getXAxes(), xAxis);
Collections.addAll(chart.getYAxes(), yAxis);
Collections.addAll(chart.getRenderableSeries(), heatmapRenderableSeries);
Collections.addAll(chart.getChartModifiers(), sciChartBuilder.newModifierGroupWithDefaultModifiers().build());
}
private IDataSeries<?,?> createDataSeries() {
final int w = 12;
final int h = 7;
final UniformHeatmapDataSeries<Integer, Integer, Double> dataSeries = new UniformHeatmapDataSeries<>(Integer.class, Integer.class, Double.class, w, h);
final Random random = new Random();
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
dataSeries.updateZAt(x, y, Math.pow(random.nextDouble(), 0.15) * x / (w - 1) * y / (h - 1) * 100);
}
}
return dataSeries;
}
}