热力图 heatmap.js

使用heatmap.js实现热力图

   <div class="content-box" >
            <img style="width: 100%; height: 429px;" src="@/assets/dataBoard/heat-bg.png" />
            <div class="heat-map">
                <div ref="heatmapContainer" style="width: 100%; height: 429px;"></div>
            </div>
        </div>
import heatmap from "heatmap.js";

export default {
    name: 'HeatAnalysisDetail',

    data() {
        return {
            heatmapInstance: null,
            heatmapData: [
                {
                    x: 25, y: 25, value: 2,
                },
                {
                    x: 30, y: 30, value: 10,
                },
                {
                    x: 35, y: 35, value: 15,
                },
                {
                    x: 40, y: 35, value: 10,
                }, {
                    x: 55, y: 40, value: 10,
                },
                {
                    x: 100, y: 100, value: 15,
                },
                {
                    x: 120, y: 120, value: 15,
                }, {
                    x: 115, y: 124, value: 15,
                }, {
                    x: 128, y: 122, value: 17,
                },
                {
                    x: 150, y: 120, value: 20,
                }
            ],
        };
    },

    mounted() {
        this.initHeatmap()
        setTimeout(() => {
            this.updateHeatmap()

        }, 0)
    },
    methods: {
        initHeatmap() {
            const cfg = {
                container: this.$refs.heatmapContainer,
                radius: 10, // 点的半径  
                maxOpacity: 1, // 最大不透明度  
                minOpacity: 0.05, // 最小不透明度  
                scaleRadius: true, // 是否缩放半径  
                useLocalExtrema: true, // 是否使用局部极值  
                gridSize: 20, // 网格大小  
                gradient: {
                    0.2: '#5d785d',
                    0.5: "#a66622",
                    0.7: '#ab271a',
                    1.0: '#aa121a' // 这里定义了不同值范围对应的颜色  
                },
            };
            this.heatmapInstance = heatmap.create(cfg);
        },

        updateHeatmap() {
            this.heatmapInstance.setData({
                data: this.heatmapData,
                max: 20 // 设置最大值
            });
        }
    }
};
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值