html5----综合属性图表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
实际代码如下:
 
 
 
<html>
 
<head>
 
<title>html5 人物属性图</title></head>
 
<body>
 
<canvas id="my" width="400" height="400"></canvas>
 
<script language="javascript" type="text/javascript">
 
var a = new $attr({
 
  name : '路飞',
 
  values : [5,6,7,8,10],
 
  keys : ['力量','防御','命中','闪避','反击'],
 
  size : 10
 
});
 
a.draw();
 
 
 
function $attr(p){
 
  var ctx = document.getElementById('my').getContext('2d'), _p = {
 
    name : '春哥',
 
    values : [10,10,10,10,10,10,10],
 
    keys : ['力量','防御','闪避','反击','必杀','命中','格挡'],
 
    size : 10,
 
    r : 10
 
  }
 
  ctx.clearRect(0,0,400,400);
 
  ctx.translate(200,200);
 
  ctx.save();
 
 
 
  this.draw = function(){
 
    init();
 
    drawCircle();
 
    drawLine();
 
  };
 
 
 
  //等级圆
 
  function drawCircle(){
  
    ctx.beginPath();
 
    ctx.strokeStyle = '#c0c0c0';
 
    for(var i = p.size; i > 0; i--){
 
      ctx.moveTo(p.r * i, 0);
 
      ctx.fillText(i,p.r * i, 0);
  
      ctx.arc(0,0,p.r * i,0,Math.PI*2,true);
 
    }
 
    ctx.stroke();
  };
 
  //属性线
 
  function drawLine(){
 
    var l = p.keys.length, rad = Math.PI * 2 / p.keys.length;
 
    ctx.rotate(Math.PI / 2 * 3);
 
    ctx.beginPath();
  
    ctx.font = 'bold 20px 宋体';
 
    for(var i = l; i > 0; i--){
 
      ctx.rotate(rad);
 
      ctx.moveTo(0,0);
 
      ctx.lineTo(p.r * p.size,0);
 
    }
 
    ctx.stroke();
 
    drawRange(l,rad);
 
    drawKeys(l,rad);
 
  };
 
  //画区域
 
  function drawRange(l,rad){
 
    var x1 = p.values[0] * p.r;
 
    ctx.beginPath();
 
    ctx.fillStyle = 'rgba(2,140,253,0.5)';
  
    ctx.strokeStyle = 'black';
 
    ctx.moveTo(x1,0);
 
    for(var i = l - 1; i >= 1; i--){
 
      ctx.rotate(rad);
 
      ctx.lineTo(p.values[i] * p.r,0);
 
    }
 
    ctx.rotate(rad);
 
    ctx.lineTo(x1,0);
 
    ctx.stroke();
 
    ctx.fill();
 
  };
 
  //属性名
 
  function drawKeys(l,rad){
 
    ctx.fillStyle = 'gray';
 
    ctx.font = 'bold 10px 宋体';
 
    ctx.translate(-6,-15);
 
    ctx.beginPath();
 
    for(var i = l; i > 0; i--){
 
      ctx.rotate(rad);
 
      ctx.save();
 
      ctx.translate(p.r * p.size + 15,5);
 
      ctx.rotate(rad * i + Math.PI / 2 - rad);
 
      ctx.fillText(p.keys[i - 1],0,0);
 
      ctx.restore();
 
    }
 
    ctx.stroke();
 
  };
 
  //初始化数据
 
  function init(){
 
    for(var a in _p){
 
      p[a] || (p[a] = _p[a]);
 
    }
 
  };
 
};
 
</script>
 
</body>
 
</html>

  

posted @   ahl5esoft  阅读(381)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示