three.js实现热力图(vue heatmap.js)

vue+three.js项目

heatmap.js这个库太久没维护了,换别人二开的库@rengr/heatmap.js

npm i @rengr/heatmap.js

使用方式与heatmap.js这个库一样

heatmap.js参考文档

import h337 from '@rengr/heatmap.js'
function addHeatmapPlane() {
  let x = 230
  let y = 60
  const canvasBox = document.createElement('div')
  document.body.appendChild(canvasBox)

  canvasBox.style.width = x + 'px'
  canvasBox.style.height = y + 'px'
  canvasBox.style.position = 'absolute'

  let canvas = h337.create({
    container: canvasBox,
    radius: 10,
    maxOpacity: 0.8,
    minOpacity: 0
  })
  canvas.setData({
    max: 20,
    min: 0,
    data: [
      { x: 71, y: 30, value: 2 },
      { x: 80, y: 35, value: 6 },
      { x: 90, y: 30, value: 4 },
      { x: 130, y: 35, value: 15 },
      { x: 140, y: 30, value: 20 },
      { x: 150, y: 30, value: 10 },
      { x: 110, y: 45, value: 11 },
      { x: 150, y: 26, value: 13 },
      { x: 190, y: 45, value: 6 },
      { x: 220, y: 40, value: 12 }
    ]
  })
  const g = new THREE.PlaneGeometry(x, y)
  const m = new THREE.MeshBasicMaterial({
    map: new THREE.CanvasTexture(canvas._renderer.canvas),
    transparent: true,
    side: THREE.DoubleSide
  })
  heatmapPlane = new THREE.Mesh(g, m)
  heatmapPlane.rotateX(Math.PI / 2)
  heatmapPlane.position.set(15, 8, -10)
  scene.add(heatmapPlane)
  document.body.removeChild(canvasBox)
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值