-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhighcharts-3d-pie-chart.js
164 lines (160 loc) · 5.54 KB
/
highcharts-3d-pie-chart.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
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
/*
* @Author: cui<devcui@outlook.com>
* @LastEditors: cui<devcui@outlook.com>
* @Date: 2022-09-22 15:45:50
* @LastEditTime: 2022-09-26 17:33:33
* @FilePath: \custom-chart-plugins\highcharts-3d-pie-chart.js
* @Description:
*
* Copyright (c) 2022 by cui<devcui@outlook.com>, All Rights Reserved.
*/
function HighCharts3dPieChart({ dHelper }) {
let instance = null;
return {
config: {
datas: [
{ label: "dimension", key: "dimension", type: "group", allowSameField: false },
{ label: "metrics", key: "metrics", type: "aggregate", allowSameField: false }
],
styles: [
{
label: '标题',
key: 'title',
comType: 'input',
},
{
label: '描述',
key: 'desc',
comType: 'input',
},
{
label: '图例',
key: 'name',
comType: 'input',
}
],
i18ns: [],
},
isISOContainer: 'highcharts-3d',
dependency: [
'/custom-chart-plugins/common/highcharts/code/highcharts.js',
'/custom-chart-plugins/common/highcharts/code/highcharts-3d.js',
'/custom-chart-plugins/common/highcharts/code/highcharts-more.js',
'/custom-chart-plugins/common/highcharts/code/css/highcharts.css',
],
meta: {
id: 'highcharts-3d-pie-chart',
name: '[Highcharts][3d][Pie][Chart]',
icon: 'chart',
requirements: [
{
group: null,
aggregate: null,
},
],
},
onMount(options, context) {
if (!options.containerId || !context.document) return;
if (!options.containerId || !context.document) return;
const { window: { Highcharts } } = context
const { containerId } = options
instance = Highcharts.chart(containerId, {
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 45,
beta: 0
}
},
title: {
text: '2014年某网站不同浏览器访问量占比'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
depth: 35,
dataLabels: {
enabled: true,
format: '{point.name}'
}
}
},
series: [{
type: 'pie',
name: '浏览器占比',
data: [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
},
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
}]
});
},
onUpdated(options, context) {
if (!options.containerId || !context.document) return;
const { config, dataset, containerId } = options;
if (!dataset || !dataset.rows || dataset.rows.length === 0) return
const { window: { Highcharts } } = context
const styleConfigs = config.styles;
// 标题
let title = styleConfigs.filter((style) => style.key === 'title')
title = title.length > 0 ? title[0].value : 'title'
// 描述
let desc = styleConfigs.filter((style) => style.key === 'desc')
desc = desc.length > 0 ? desc[0].value : 'desc'
// 图例
let name = styleConfigs.filter((style) => style.key === 'name')
name = name.length > 0 ? name[0].value : 'name'
instance = Highcharts.chart(containerId, {
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 45,
beta: 0
}
},
title: {
text: title
},
subtitle: {
text: desc
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
depth: 35,
dataLabels: {
enabled: true,
format: '{point.name}'
}
}
},
series: [{
type: 'pie',
name: name,
data: dataset.rows
}]
});
},
onUnMount() { },
onResize(options, context) { }
}
}