Pre loader

NaN value in Heatmap for transparent pixel

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums



I tried to initialize heatmap chart with NaN to make it transparent, but it doesn’t work that way. The color was blue, which is zero in the colormap. Is there a way to make it not showing any color?


public void initECMSciChart() {
    // initialize chart with NaN
    for (int i = 0; i < MATRIX_COLUMNS; i++) {
        for (int j = 0; j < MATRIX_ROWS; j++) {
            heatmap2DMatrix[i][j] = 0;
            heatmapDataSeries.updateZAt(i, j, Double.NaN);
  • You must to post comments
Best Answer

Hi there,

By default we don’t handle NaN values in heatmap and we use colors that are specified by color map. If you want to display transparent color you can use PaletteProvider API to override colors of the cells with NaN values. We have an example in our demo application. Here is code of PaletteProvider which sets transparent color if Z value is NaN:

class TransparentNanUniformHeatMapProvider extends PaletteProviderBase<FastUniformHeatmapRenderableSeries> implements IUniformHeatmapPaletteProvider {
    public TransparentNanUniformHeatMapProvider() {

    public boolean shouldSetColors() {
        return true;

    public void update() {
        final FastUniformHeatmapRenderableSeries renderableSeries = this.renderableSeries;
        final UniformHeatmapRenderPassData currentRenderPassData = (UniformHeatmapRenderPassData) renderableSeries.getCurrentRenderPassData();

        final DoubleValues zValues = currentRenderPassData.zValues;
        final IntegerValues zColors = currentRenderPassData.zColors;

        final int size = zValues.size();

        // working with array is much faster than calling set() many times
        final double[] zValuesArray = zValues.getItemsArray();
        final int[] zColorsArray = zColors.getItemsArray();

        for (int zIndex = 0; zIndex < size; zIndex++) {
            final double value = zValuesArray[zIndex];
                zColorsArray[zIndex] = Color.TRANSPARENT;

You just need to set it for heatmap series:

        final FastUniformHeatmapRenderableSeries heatmapRenderableSeries = sciChartBuilder.newUniformHeatmap()
            .withColorMap(new ColorMap(new int[]{DarkBlue, CornflowerBlue, DarkGreen, Chartreuse, Yellow, Red}, new float[]{0f, 0.2f, 0.4f, 0.6f, 0.8f, 1}))
            .withPaletteProvider(new TransparentNanUniformHeatMapProvider())

Is this suitable for your needs?

Best regards,

  • Gang Xu
    It works like a charm. Thanks!
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies