代码如下:

<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. ZOJ 80ers' Memory

    80ers' Memory Time Limit: 1 Second      Memory Limit: 32768 KB I guess most of us are so called 80er ...

  2. Delphi下使用指针的简单总结(指针的赋值,数组和指针的转换,函数指针的使用)

    由于最近公司太忙,好久没有更新我的BLOG了.原来想着写写关于HOOK驱动的文章,可是最后想想好久已经没有做驱动的东西了,怕写出来有错误,于是作罢.开发游戏也有一段时间了,发现使用DELPHI来开发网 ...

  3. NGINX:漫谈优化

    优化那些事儿 生产环境下网站做前期的优化肯定是比不可少的,简单来说就是用同等条件的硬件资源,处理更多的网站业务,大程度提供网站业务处理能力:前辈留下的实战经验可都是财富,好多坑只有踩过才知道痛,下面就 ...

  4. mysql 数据操作 单表查询 通过四则运算查询

    #通过四则运算查询 FROM employee; AS Annual_salary FROM employee; Annual_salary FROM employee; 查看年薪salary*12 ...

  5. MySQL不能启动 Can't start server : Bind on unix socke

    MySQL服务器突然不能启动,查看最后的启动日志如下: 080825 09:38:04 mysqld started080825 9:38:04 [ERROR] Can't start server ...

  6. word安装mathtype

    1:window版本的mathtype:https://pan.baidu.com/s/1Yn8kPG9Y9nBPGaotFJaL2Q  ,密码spwm 2:点击exe安装   (安装到c盘,将不会出 ...

  7. PHP接收json格式的POST数据

    /** * 获取 post 参数; 在 content_type 为 application/json 时,自动解析 json * @return array */ private function ...

  8. java.lang.UnsatisfiedLinkError: org.apache.hadoop.util.NativeCrc32.nativeComputeChunkedSumsByteArray(II[BI[BIILjava/lang/String;JZ)V

    环境: Spark2.1.0 .Hadoop-2.7.5   代码运行系统:Win 7在运行Spark程序写出文件(savaAsTextFile)的时候,我遇到了这个错误: // :: ERROR U ...

  9. 用Python实现的数据结构与算法:堆栈

    一.概述 堆栈(Stack)是一种后进先出(LIFO)的线性数据结构,对堆栈的插入和删除操作都只能在栈顶(top)进行. 二.ADT 堆栈ADT(抽象数据类型)一般提供以下接口: Stack() 创建 ...

  10. (转)在 ListViewItem 上拖动进行框选

    public partial class Form1 : Form { private bool IsMouseDown = false; Rectangle MouseRect = Rectangl ...