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

Answered
0
0

Hi,

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?

Thanks,

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);
        }
    }
    heatmapDataSeries.setStartX(0d);
    heatmapSurface.zoomExtentsX();
}
Version
3.1.0.4341
  • You must to post comments
Best Answer
0
0

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() {
        super(FastUniformHeatmapRenderableSeries.class);
    }

    @Override
    public boolean shouldSetColors() {
        return true;
    }

    @Override
    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];
            if(Double.isNaN(value))
                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}))
            .withMinimum(0)
            .withMaximum(200)
            .withDataSeries(dataSeries)
            .withPaletteProvider(new TransparentNanUniformHeatMapProvider())
            .build();

Is this suitable for your needs?

Best regards,
Yura

  • 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