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, ...
 
随机推荐
- 使用or展开进行sql优化(即sql语法union all代替or可以提高效率)
			
问题: 这样一条sql应该怎么优化? select * from sys_user where user_code = 'zhangyong' or user_code in (select grp_ ...
 - Python开发【Django】:中间件、CSRF
			
CSRF 1.概述 CSRF(Cross Site Request Forgery)跨站点伪造请求,举例来讲,某个恶意的网站上有一个指向你的网站的链接,如果某个用户已经登录到你的网站上了,那么当这个用 ...
 - 大话https演化过程(对称加密、非对称加密、公钥、私钥、数字签名、数字证书)
			
大话https演化过程(包括概念:对称加密.非对称加密.公钥.私钥.数字签名.数字证书.https访问全过程) 在网络上发送数据是非常不安全的,非常容易被劫持或是被篡改,所以每次定向发送数据你都可 ...
 - Android中的Handler及它所引出的Looper、MessageQueue、Message
			
0.引入 0.1.线程间通信的目的 首先,线程间通信要交流些什么呢? 解答这个问题要从为什么要有多线程开始,需要多线程的原因大概有这些 最早也最基本:有的任务需要大量的时间,但其实并不占用计算资源,比 ...
 - Python总结篇——知识大全
			
python基础 Python开发环境搭建 Python变量和基本数据类型 python基本数据类型之操作 python的语法规范及for和while python编码 python文件操作 pyth ...
 - 【Python学习 】Python实现的FTP上传和下载功能
			
一.背景 最近公司的一些自动化操作需要使用Python来实现FTP的上传和下载功能.因此参考网上的例子,撸了一段代码来实现了该功能,下面做个记录. 二.ftplib介绍 Python中默认安装的ftp ...
 - git-【二】本地git操作提交、版本回退
			
一.创建版本库,提交文件 什么是版本库?版本库又名仓库,英文名repository,你可以简单的理解一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改,删除,Git都能跟踪,以便任 ...
 - 调试:Spring AOP执行过程
			
调试项目:https://github.com/1367356/laboratoryWeb 断点位置 点击查询:http://localhost:9002/queryNews?htmlid=15318 ...
 - JDK eclipse selenium的安装以及环境变量的配置
			
未经允许,禁止转载!!! 未经允许,禁止转载!!! 首先下载安装JDK: 然后双击进行安装 选着第一个:开发工具!点击next 一定要记住:Install to: C:\Program Files\ ...
 - 妙用Excel数据透视表和透视图向导,将二维数据转换为一维数据
			
项目中,每年都会有各种经销商的各种产品目标数据导入,经销商和产品过多,手工操作过于单调和复杂.那有没有一种方式可以将复杂的二维数据转换为一维数据呢? 有,强大的Excel就支持此功能. 常用Excel ...