vue2中使用observablehq plot.js库绘制密度图(Density contours)和散点图

效果

在这里插入图片描述
注意:plot.js库中的交互功能没有echarts等库丰富,它主要是用于数据展示。官方文档链接:https://observablehq.com/plot/getting-started 遇到问题时候,可以去官方社区(https://talk.observablehq.com)提问,亲测一般一天内都会有结果。

正文

  1. 首先安装plot.js(个人使用的vue2)
npm install @observablehq/plot
  1. 在需要用到的页面导入
import * as Plot from "@observablehq/plot";
  1. 使用
    在vue页面的methods中写个方法:
 show(faithful) {
 let a=Plot.plot({
  inset: 10,
  marks: [
  //密度图
    Plot.density(faithful, {x: "waiting", y: "eruptions", stroke: "steelblue", strokeWidth: 0.25}),
    Plot.density(faithful, {x: "waiting", y: "eruptions", stroke: "steelblue", thresholds: 4}),
    //散点图
    Plot.dot(faithful, {x: "waiting", y: "eruptions", fill: "currentColor", r: 1.5})
  ]
})
 $("#plot").append(ps);
 }

数据结构
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
首先,你需要在Vue3项目安装heatmap.js。可以使用npm或yarn命令来进行安装,例如: ``` npm install heatmap.js --save ``` 或者 ``` yarn add heatmap.js ``` 接下来,你需要在Vue组件使用heatmap.js绘制热力。以下是一个简单的示例: ```html <template> <div id="map"></div> </template> <script> import heatmap from 'heatmap.js'; export default { mounted() { // 创建地对象 const map = new AMap.Map('map', { zoom: 13, center: [116.39, 39.9] }); // 绘制热力 const heatmapData = []; for (let i = 0; i < 100; i++) { heatmapData.push({ lng: 116.39 + Math.random() * 0.1, lat: 39.9 + Math.random() * 0.1, count: Math.floor(Math.random() * 10) }); } const heatmapInstance = heatmap.create({ container: map.getContainer(), radius: 30, maxOpacity: 0.8, minOpacity: 0.2, blur: 0.75, gradient: { 0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1.0: 'red' } }); heatmapInstance.setData({ max: 10, data: heatmapData }); } } </script> <style> #map { width: 100%; height: 500px; } </style> ``` 在上面的代码,我们首先创建了一个地对象,然后使用循环生成了一些随机的点数据,接着使用heatmap.create()方法创建了一个热力实例,并通过setData()方法设置了热力的数据,最后把热力实例绑定到地即可。 需要注意的是,在Vue组件使用heatmap.js时,需要先在组件引入heatmap.js,然后再通过import语句来使用heatmap。同时,还需要注意在创建热力实例时,需要指定container属性为地的容器节点,以便热力能够正确地显示在地上。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值