代码如下:

<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绘制雷达图的更多相关文章

  1. 【带着canvas去流浪(6)】绘制雷达图

    目录 一. 任务说明 二. 重点提示 三. 示例代码 示例代码托管在:http://www.github.com/dashnowords/blogs 博客园地址:<大史住在大前端>原创博文 ...

  2. Emgu-WPF 激光雷达研究-绘制雷达图

    原文:Emgu-WPF 激光雷达研究-绘制雷达图 硬件:Hokuyo URG04LX 环境:VS2017- win10- 64  Emgu_3.2.0.2682 语言:C#  WPF   数据解析参考 ...

  3. 带着canvas去流浪系列之六 绘制雷达图

    [摘要] 用canvas原生API实现百度Echarts基本图表. 示例代码托管在:http://www.github.com/dashnowords/blogs 一. 任务说明 使用原生canvas ...

  4. 利用matlibplot绘制雷达图

    之前在一些数据分析案例中看到用 Go 语言绘制的雷达图,非常的漂亮,就想着用matlibplot.pyplot也照着画一个,遗憾的是matlibplot.pyplot模块中没有直接绘制雷达图的函数,不 ...

  5. 利用d3.js绘制雷达图

    利用d3,js将数据可视化,能够做到数据与代码的分离.方便以后改动数据. 这次利用d3.js绘制了一个五维的雷达图.即将多个对象的五种属性在一张图上对照. 数据写入data.csv.数据类型写入typ ...

  6. Mesh绘制雷达图(UGUI)

    参考资料:http://www.cnblogs.com/jeason1997/p/5130413.html ** 描述:雷达图 刷新 radarDate.SetVerticesDirty(); usi ...

  7. C# 使用GDI绘制雷达图

    最近项目要用C#实现画一个雷达图,搜了搜网上竟然找不到C#画雷达图的解决方案,那么自己实现一个吧 实现效果如下图: 代码如下: public static class RadarDemo { ; ; ...

  8. Python绘制雷达图(俗称六芒星)

    原文链接:https://blog.csdn.net/Just_youHG/article/details/83904618 背景 <Python数据分析与挖掘实战> 案例2–航空公司客户 ...

  9. R语言绘图:雷达图

    使用fmsb包绘制雷达图 library("fmsb") radarfig <- rbind(rep(90, 4), rep(60, 4), c(86.17, 73.96, ...

随机推荐

  1. 如何打造高性能Web应用

    Sean Hull是Heavyweight Internet Group的创始人兼高级顾问,拥有20年以上技术顾问相关经验,曾为多家知名机构提供咨询,其中包括The Hollywood Reporte ...

  2. 洛谷P1858 多人背包 多人背包板子题/多人背包学习笔记

    ,,,本来自以为,我dp学得还挺好的 然后今天一考发现都不会啊QAQ 连最基础的知识点都不清楚啊QAQ 所以就来写个题解嘛! 先放下板子题 其实我jio得,这题只要大概了解方法就不是很难鸭,,,毕竟是 ...

  3. supervisor - Python进程管理工具(转)

    add by zhj: 下面是在ubuntu上的一些使用经验 1. 简介 supervisor有两个组件:supervisord和supervisorctl,组成了client/server结构. s ...

  4. 第1章 1.9计算机网络概述--OSI参考模型和网络安全

    1.物理层安全: 风险:无关人员接入网络. 防范:将用不到的口的网线拔掉,或者用命令将用不到的网线接口shutdown(关闭). 2.数据链路层安全: ADSL账号密码 无线网账号密码 交换机绑定MA ...

  5. python中读取配置文件的方式

    方式1:argparse argparse,是Python标准库中推荐使用的编写命令行程序的工具.也可以用于读取配置文件. 字典样式的配置文件*.conf 配置文件test1.conf { " ...

  6. redis.conf配置文件说明

    # Redis 配置文件 # 当配置中需要配置内存大小时,可以使用 1k, 5GB, 4M 等类似的格式,其转换方式如下(不区分大小写) # # 1k => 1000 bytes # 1kb = ...

  7. python selenium webdriver方法封装(find_element_by)

    下面是对find_element_by_就行了封装,封装之后的高级方法就是getElement() 下面是具体的代码: def getElement(self, selector): "&q ...

  8. mysql_escape_string — 转义一个字符串用于 mysql_query

    string mysql_escape_string ( string $unescaped_string ) 本函数将 unescaped_string 转义,使之可以安全用于 mysql_quer ...

  9. 2018 Multi-University Training Contest 2 Solution

    A - Absolute 留坑. B - Counting Permutations 留坑. C - Cover 留坑. D - Game puts("Yes") #include ...

  10. 对Java平台的理解

    1)  Java是一种面向对象的语言(封装,继承,多态),最显著的特性有两个方面: ----书写一次,到处运行(Write once,run anywhere) 能够非常容易的获得跨平台的能力 --- ...