简体   繁体   中英

Heatmap.js clickable heatmap

Im using Heatmap.js to create a clickable heatmap. Im trying the following code unsuccessfully.

The legend is being displayed, but click on the canvas is not generating the heatmap like its supposed to .

<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="heatmap.js"></script>
</head>
<body>
<script type="text/javascript">
window.onload = function(){
// heatmap configuration
var config = {
element: document.getElementById("heatmapArea"),
radius: 30,
opacity: 50,
legend: {
position: 'br',
title: 'Example Distribution'
}
};
//creates and initializes the heatmap
var heatmap = h337.create(config);

document.getElementById("heatmapArea").onclick = function(e){
heatmap.store.addDataPoint(e.layerX, e.layerY, 1);
};
};

</script>

<div id ="heatmapArea">

  </div>
</body>
</html>

In their example it looks like their div contains a few styling definition and a class:

<div id="heatmapArea" class="well" style="width:610px;padding:0;height:400px;cursor:pointer;position:relative;"></div>

However, you probably only need to add a height and width to your div .

Here's an EXAMPLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM