wepy绘制雷达图
代码如下:
<style lang='less'>
.radar-canvas2 {
width: 690rpx;
height: 420rpx;
}
</style>
<template>
<canvas class='radar-canvas2' canvas-id='radar-canvas'></canvas>
</template>
<script>
import wepy from 'wepy'
var windowW = wx.getSystemInfoSync().windowWidth export default class RadarCanvas extends wepy.component {
props = {
source: {
default: [
{desc: '综合', value: 0},
{desc: '思修法基', value: 0},
{desc: '史纲', value: 0},
{desc: '马原', value: 0},
{desc: '毛中特', value: 0}
],
type: Array
}
}
data = {
ctx: null,
sideNum: 5,
angle: 1.26,
centerPointX: 345,
centerPointY: 210,
radius: 120
}
methods = {
drawCanvas: () => {
let ctx = wx.createCanvasContext('radar-canvas')
this.sideNum = this.source.length
this.angle = Math.PI * 2 / this.sideNum
this.centerPointX = this.rpx(690 / 2)
this.centerPointY = this.rpx(420 / 2)
this.radius = this.rpx(120)
this.$apply()
this.drawPolygon(ctx)
this.drawRib(ctx)
this.addDataPoint(ctx)
this.linePoint(ctx)
ctx.draw(false)
}
}
drawPolygon(ctx) {
ctx.setLineDash([2, 2])
ctx.setStrokeStyle('#E3E2E2')
let r = this.rpx(30)
for (let i = 1; i < 5; i++) {
ctx.beginPath()
let currR = r * i // 当前半径
ctx.setFontSize(this.rpx(20))
ctx.setFillStyle('#8E8C8B')
ctx.setTextAlign('right')
ctx.fillText(25 * (i - 1), this.centerPointX - 5, this.centerPointY - r * (i - 1) + this.rpx(10))
// 最外面的是实线
if (i === 4) {
ctx.setLineDash()
}
for (let j = 0; j < this.sideNum; j++) {
let x = this.centerPointX + currR * Math.cos(this.angle * j + Math.PI / 3.3)
let y = this.centerPointY + currR * Math.sin(this.angle * j + Math.PI / 3.3)
ctx.lineTo(x, y)
}
ctx.closePath()
ctx.stroke()
}
}
drawRib(ctx) {
ctx.setLineDash([2, 2]) // 虚线
ctx.setStrokeStyle('#E3E2E2')
ctx.beginPath()
for (let i = 0; i < this.sideNum; i++) {
let x = this.centerPointX + this.radius * Math.cos(this.angle * i + Math.PI / 3.3)
let y = this.centerPointY + this.radius * Math.sin(this.angle * i + Math.PI / 3.3)
ctx.moveTo(this.centerPointX, this.centerPointY)
ctx.lineTo(x, y)
ctx.setFontSize(this.rpx(28))
ctx.setFillStyle('#8E8C8B')
switch (i) {
case 0:
ctx.setTextAlign('left')
ctx.fillText(this.source[i].desc, x, y + 20)
break
case 1:
ctx.setTextAlign('right')
ctx.fillText(this.source[i].desc, x, y + 20)
break
case 2:
ctx.setTextAlign('right')
ctx.fillText(this.source[i].desc, x - 10, y)
break
case 3:
ctx.setTextAlign('center')
ctx.fillText(this.source[i].desc, x, y - 10)
break
case 4:
ctx.setTextAlign('left')
ctx.fillText(this.source[i].desc, x + 10, y)
break
default:
break
}
}
ctx.closePath()
ctx.stroke()
}
addDataPoint(ctx) {
ctx.setLineDash()
for (let i = 0; i < this.sideNum; i++) {
let x = this.centerPointX + this.radius * Math.cos(this.angle * i + Math.PI / 3.3) * this.source[i].value
let y = this.centerPointY + this.radius * Math.sin(this.angle * i + Math.PI / 3.3) * this.source[i].value
ctx.beginPath()
ctx.arc(x, y, this.rpx(4), 0, 2 * Math.PI)
ctx.setFillStyle('#47D891')
ctx.fill()
ctx.closePath()
}
}
linePoint(ctx) {
ctx.setStrokeStyle('#47D891')
ctx.beginPath()
for (var i = 0; i < this.sideNum; i++) {
var x = this.centerPointX + this.radius * Math.cos(this.angle * i + Math.PI / 3.3) * this.source[i].value
var y = this.centerPointY + this.radius * Math.sin(this.angle * i + Math.PI / 3.3) * this.source[i].value
ctx.lineTo(x, y)
}
ctx.closePath()
ctx.setFillStyle('rgba(37,212,129,0.25)')
ctx.fill()
ctx.stroke()
}
rpx(param) {
return Number((windowW / 750 * param).toFixed(2))
}
}
</script>
效果图如下:

wepy绘制雷达图的更多相关文章
- 【带着canvas去流浪(6)】绘制雷达图
目录 一. 任务说明 二. 重点提示 三. 示例代码 示例代码托管在:http://www.github.com/dashnowords/blogs 博客园地址:<大史住在大前端>原创博文 ...
- Emgu-WPF 激光雷达研究-绘制雷达图
原文:Emgu-WPF 激光雷达研究-绘制雷达图 硬件:Hokuyo URG04LX 环境:VS2017- win10- 64 Emgu_3.2.0.2682 语言:C# WPF 数据解析参考 ...
- 带着canvas去流浪系列之六 绘制雷达图
[摘要] 用canvas原生API实现百度Echarts基本图表. 示例代码托管在:http://www.github.com/dashnowords/blogs 一. 任务说明 使用原生canvas ...
- 利用matlibplot绘制雷达图
之前在一些数据分析案例中看到用 Go 语言绘制的雷达图,非常的漂亮,就想着用matlibplot.pyplot也照着画一个,遗憾的是matlibplot.pyplot模块中没有直接绘制雷达图的函数,不 ...
- 利用d3.js绘制雷达图
利用d3,js将数据可视化,能够做到数据与代码的分离.方便以后改动数据. 这次利用d3.js绘制了一个五维的雷达图.即将多个对象的五种属性在一张图上对照. 数据写入data.csv.数据类型写入typ ...
- Mesh绘制雷达图(UGUI)
参考资料:http://www.cnblogs.com/jeason1997/p/5130413.html ** 描述:雷达图 刷新 radarDate.SetVerticesDirty(); usi ...
- C# 使用GDI绘制雷达图
最近项目要用C#实现画一个雷达图,搜了搜网上竟然找不到C#画雷达图的解决方案,那么自己实现一个吧 实现效果如下图: 代码如下: public static class RadarDemo { ; ; ...
- Python绘制雷达图(俗称六芒星)
原文链接:https://blog.csdn.net/Just_youHG/article/details/83904618 背景 <Python数据分析与挖掘实战> 案例2–航空公司客户 ...
- R语言绘图:雷达图
使用fmsb包绘制雷达图 library("fmsb") radarfig <- rbind(rep(90, 4), rep(60, 4), c(86.17, 73.96, ...
随机推荐
- mysql_commit() COMMIT ROLLBACK 提交 回滚 连接释放
MySQL :: MySQL 8.0 Reference Manual :: 28.7.7.6 mysql_commit() https://dev.mysql.com/doc/refman/8.0/ ...
- Team Formation---zoj3870(异或)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5518 题意就是有n个数,如果满足a^b > MAX(a, b) ...
- MVC4中使用Html.DropDownList实现级联
本文记录了一个在MVC4中使用PartialView实现级联效果的小例子. 准备工作 首先准备一下要级联的数据,新建两个类:Province和City public class Province { ...
- nodejs学习笔记Node.js 调试命令
3.4 调试 47 下面是一个简单的例子: $ node debug debug.js < debugger listening on port 5858 connecting ...
- kubernetes实战(八):k8s集群安全机制RBAC
1.基本概念 RBAC(Role-Based Access Control,基于角色的访问控制)在k8s v1.5中引入,在v1.6版本时升级为Beta版本,并成为kubeadm安装方式下的默认选项, ...
- RSA与AES的区别
RSA 非对称加密,公钥加密,私钥解密,反之亦然.由于需要大数的乘幂求模等算法,运行速度慢,不易于硬件实现. 通常私钥长度有512bit,1024bit,2048bit,4096bit,长度越长,越安 ...
- 代码处理 iOS 的横竖屏旋转
一.监听屏幕旋转方向 在处理iOS横竖屏时,经常会和UIDeviceOrientation.UIInterfaceOrientation和UIInterfaceOrientationMask这三个枚举 ...
- AE开发的一个想法
基于字典进行GIS图形进行编辑. 图层信息 大类别 字典项(属性字段) 居民点 控制点 GPS控制点 线状道路 铁路 省道 国道 一般公路 名称 长度 等级 备注 线状水系 面状道路 面状水系 湖泊 ...
- 1124 Raffle for Weibo Followers[简单]
1124 Raffle for Weibo Followers(20 分) John got a full mark on PAT. He was so happy that he decided t ...
- Kd-tree的学习
一.普通kd-tree 1.在选择划分维度的时候,不能简单的每一个维度轮流划分.还有一种更合适的是利用数据的方差来划分,哪个维度的方差大,就选择哪一个维度划分.理由解释如下: 最简单的方法就是轮着来, ...