SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components



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.