<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
div {
width:600px; height:400px;border: 1px solid;border-color: grey;
}
</style>
</head>
<body>
<div id="heatmap"></div>
</body>
<script src="js/heatmap.js"></script>
<script type="text/javascript">
// 创建一个heatmap实例对象
// “h337” 是heatmap.js全局对象的名称.可以使用它来创建热点图实例
// 这里直接指定热点图渲染的div了.heatmap支持自定义的样式方案,具体可看官网api
var heatmapInstance = h337.create({
container: document.querySelector('#heatmap'),
});
//构建一些随机数据点,这里替换成你的业务数据
var points = [];
var max = 0;
var width = 600;
var height = 400;
var len = 200;
while (len--) {
var val = Math.floor(Math.random()*100);
max = Math.max(max, val);
var point = {
x: Math.floor(Math.random()*width),
y: Math.floor(Math.random()*height),
value: val
};
points.push(point);
}
var data = {
max: max,
data: points
};
heatmapInstance.setData(data); //数据绑定还可以使用
</script>
</html>
![](https://img.haomeiwen.com/i6177832/2295dd86986a97f9.png)
h337.create(configObject)
创建heatmap实例,configObject是一个json对象,里面有很多参数
- container 页面操作div的dom对象
- backgroundColor 画板的背景颜色设置,支持rgb(a),颜色名称,但必须要用引号
- gradient 设置热点图的光圈颜色,数值为[0,1],数值大的在光圈内侧,数值相等则靠下的生效,数值设置不分大小顺序,并可以同时设置很多颜色
- radius 设置光圈的半径大小,值>=0,=0取得是默认值
- opacity 光圈透明度设置[0,1],如果值设置了,会重写maxOpacity和minOpacity的值
网友评论