-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradar.js
62 lines (46 loc) · 1.58 KB
/
radar.js
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
import Chart from "./chart";
export default class RadarChart extends Chart {
render() {
super.scale();
var pathArr = [];
// 坐标刻度线
this.yAxis.forEach((it, i) => {
pathArr = [];
let r = this.yAxis[i].number * this.stepLength / 2;
this.yAxis[i].y = r;
let total = this.series[0].data.length;
this.series[0].data.forEach((v, j) => {
let x = Math.round(Math.cos((j / total) * (2 * Math.PI)) * r) + this.radius;
let y = Math.round(Math.sin((j / total) * (2 * Math.PI)) * r) + this.radius;
pathArr.push(x + " " + y + " ");
});
pathArr[pathArr.length] = pathArr[0];
it.path = "M" + pathArr.join("L ");
});
// 射线
var center = (this.radius) + " " + (this.radius);
var numArr = [];
var markerPathArr = [];
var total = this.series[0].data.length;
for (let i = 0; i < total; i++) {
this.xAxis[i] = {
path:"M" + center + " L" + pathArr[i]
};
let r = this.series[0].data[i] * this.stepLength / 2;
let x = Math.round(Math.cos((i / total) * (2 * Math.PI)) * r) + this.radius;
let y = Math.round(Math.sin((i / total) * (2 * Math.PI)) * r) + this.radius;
numArr.push(x + " " + y + " ");
let markerArr = [];
let markerCorner = 20;
for (let j=0; j<markerCorner; j++) {
let m = x + 5 * Math.cos((j / markerCorner) * (2 * Math.PI));
let n = y + 5 * Math.sin((j / markerCorner) * (2 * Math.PI));
markerArr.push(m + " " + n + " ");
}
markerPathArr.push("M" + markerArr.join("L "));
}
numArr[numArr.length] = numArr[0];
this.dataPath = "M" + numArr.join("L ");
this.markerPathArr = markerPathArr;
}
}