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();
}
- Gang Xu asked 4 years ago
- last edited 4 years ago
- You must login to post comments
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
- Yura Khariton answered 4 years ago
-
It works like a charm. Thanks!
- You must login to post comments
Please login first to submit.