Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to destroy heatmap.js instance?

I'm using patrick wied's heatmapjs. I want to know how to destroy an instance and remove the canvas div created by h337.create(configObject) function.

Example:

var config = {
  container: document.getElementById('heatmapContainer'),
  radius: 10
};
var config2 = {
  container: document.getElementById('heatmapContainer'),
  radius: 5
};
var heatmapInstance1 = h337.create(config);
var heatmapInstance2 = h337.create(config);
var heatmapInstance3 = h337.create(config2);

I want to destroy and delete canvas div only for heatmapInstance1 instance.

like image 884
Mokhlesur Rahman Avatar asked Feb 11 '26 03:02

Mokhlesur Rahman


1 Answers

Currently there is no method to destroy a heatmapjs instance, but we can do that manually.

First we have to remove the canvas element from DOM and than unset or destroy the heatmapjs instance.

Example:

//find corresponding canvas element
var canvas = heatmapInstance1._renderer.canvas;
//remove the canvas from DOM
$(canvas).remove();
//than unset the variable
heatmapInstance1 = undefined;
//or
heatmapInstance1 = null;
like image 104
Mokhlesur Rahman Avatar answered Feb 12 '26 17:02

Mokhlesur Rahman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!