当前位置:网站首页>canvas--pie chart
canvas--pie chart
2022-08-02 03:38:00 【cjx177187】

<body>
<style>
#box {
border: 1px solid black;
}
</style>
<canvas id="box" width="600" height="600"></canvas>
<script>
var canvas = document.querySelector("#box")
var pen = canvas.getContext("2d")
var deg = Math.PI / 180
//假数据
var arr = [{
name: "clothes",
money: 8000
},
{
name: "car",
money: 1580
},
{
name: "eat",
money: 5790
},
{
name: "cash",
money: 4090
},
{
name: "foot",
money: 2439
},
]
//总价
arr.tatol = 0
for (let i = 0; i < arr.length; i++) {
arr.tatol = arr.tatol + arr[i].money
}
var stardeg = 0
arr.forEach(el => {
pen.beginPath()
var r1 = 200
//随机颜色
var r = parseInt(Math.random() * 255)
var g = parseInt(Math.random() * 255)
var b = parseInt(Math.random() * 255)
pen.fillStyle = `rgb(${ r},${ g},${ b})`
//求出每个money的占比
var angle = (el.money / arr.tatol) * 360
//Use proportions to draw arcs
pen.arc(300, 300, r1, stardeg * deg, (stardeg + angle) * deg)
//Connect the arc to the center of the circle,form a fan
pen.lineTo(300, 300)
//Add an array to each sectorname
var y1 = 300 + Math.sin((stardeg + angle) * deg-angle*deg/2 ) *( r1+30)
var x1 = 300 + Math.cos((stardeg + angle) * deg-angle*deg/2 ) * (r1+30)
pen.fillText(`${ el.name}`, x1, y1)
stardeg = stardeg + angle
pen.fill()
pen.stroke()
});
</script>
</body>
边栏推荐
- AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
- 【面试】失败的一次面试
- AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
- np.isnan ()
- 啃瓜记录又一天
- MySQL中JOIN的用法
- 错误:with open(txt_path,‘r‘) as f: FileNotFoundError: [Errno 2] No such file or directory:
- C语言 void和void *(无类型指针)
- C语言 十六进制整数字符串转十进制整数
- 3 minutes to take you to understand WeChat applet development
猜你喜欢

新工程加载YOLOV6的预训练权重问题

STM32 触发HardFault_Handler如何查找原因

The @autowired distinguished from @ the Resource

canvas--饼状图

kettle 安装与配置

String comparison size in MySQL (date string comparison problem)

UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the index ing argu

parser = argparse.ArgumentParser()解析

Amazon sellers how to improve the conversion

每天填坑,精卫填坑第二集,TX1 配置从固态启动,安装Pytorch
随机推荐
DSPE-PEG-DBCO Phospholipid-Polyethylene Glycol-Dibenzocyclooctyne A Linear Heterobifunctional Pegylation Reagent
np.isnan ()
mysql中如何查看表是否被锁
@Autowired注解的使用
如何查看一个现有的keil工程之前由什么版本的keil IDE编译
科研试剂DMPE-PEG-Mal 二肉豆蔻酰磷脂酰乙醇胺-聚乙二醇-马来酰亚胺
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/yolov5-5.0/models/commo
MySQL删除表数据 MySQL清空表命令 3种方法
parser = argparse.ArgumentParser() parsing
MySQL中字符串比较大小(日期字符串比较问题)
JJWT tool class
parser = argparse.ArgumentParser()解析
知识问答与知识会话的区别
MySql创建数据表
相对路径和绝对路径
最新,每天填坑,Jeston TX1 精卫填坑,第一步:刷机
Debian 10 NTP Service Configuration
针对简历上的问题
SSM integration
nucleo stm32 h743 FREERTOS CUBE MX配置小记录