jmchart 1.1.79 → 1.1.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/example/pie.html CHANGED
@@ -1,354 +1,354 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
5
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <!--<script type="text/javascript" src="../src/jmchart.debug.js" id="jmgraph" ></script>-->
7
-
8
- <style>
9
- html,body {
10
- margin:0;
11
- padding:0;
12
- width:100%;
13
- height:100%;
14
- }
15
- #mycanvas canvas, #mycanvas div{
16
- background-color:#fff;
17
- margin:0 auto;
18
- }
19
- /*div.jm-tooltip {
20
- background-color: rgba(255,255,255,0.8);
21
- padding:4px;
22
- border:1px solid #000;
23
- box-shadow: 0 0 3px #000;
24
- border-radius: 6px;
25
- }*/
26
- </style>
27
- <script type="module">
28
-
29
- import { jmChart } from '../dist/jmchart.esm.js';
30
-
31
- (function load() {
32
- var w = Math.max((window.innerWidth || window.document.body.clientWidth) * 0.8, 600);
33
- var h = Math.max((window.innerHeight || window.document.body.clientHeight) * 0.4, 400);
34
- inichart(w, h);
35
- })();
36
-
37
-
38
- function inichart(w, h) {
39
- var chart1 = new jmChart('mycanvas1', {
40
- width: w,
41
- height: h,
42
- enableAnimate: true,
43
- autoRefresh: true,
44
- style: {
45
- markLine: false, // 不展示标线
46
- margin: {
47
- left: 200,
48
- top: 100,
49
- right: 200,
50
- bottom: 100
51
- }
52
- }
53
- });
54
-
55
- var pie1 = chart1.createSeries('pie', {
56
- field: 'y1',
57
- startAngle: function(data) {
58
- const step = Math.abs(data[0].y1 / this.totalValue);
59
- return Math.PI/2 - step * Math.PI;// 当前占的角度的一半加上偏移要刚好等于90度
60
- },//10,
61
- anticlockwise: false, //是否逆时针
62
- legendFormat: function(options) {
63
- return 'test' + options.data.x;
64
- },
65
- itemLabelFormat: function(point) {
66
- //return (point.step * 100).toFixed(2) + '%';
67
- //return point.data.name;
68
- const label = this.graph.createShape('label', {
69
- style: this.style.label,
70
- text: point.data.name,
71
- position: function() {
72
-
73
- // 动态计算位置
74
- const parentRect = this.parent.getBounds();
75
-
76
- // 圆弧的中间位,离圆心最近和最完的二个点
77
- let centerMaxPoint = this.parent.points[Math.floor(this.parent.points.length / 2)];
78
- // 如果是空心圆,则要计算 1/4 和 3/4位的点。顺时针和逆时针二个点大小不一样,这里只取,大小计算时处理
79
- if(point.shape.style.isHollow) {
80
- centerMaxPoint = this.parent.points[Math.floor(this.parent.points.length * 0.75)];
81
- }
82
-
83
- const size = this.testSize();
84
- const offset = 100;
85
- const position = {
86
- x: 0,
87
- y: 0
88
- };
89
-
90
- position.x = (centerMaxPoint.x - this.parent.center.x) / this.parent.radius * offset + centerMaxPoint.x - parentRect.left;
91
- position.y = (centerMaxPoint.y - this.parent.center.y) / this.parent.radius * offset + centerMaxPoint.y - parentRect.top;
92
- return position;
93
- }
94
- });
95
- return label;
96
- },
97
- /*radius: function(p, radius, index) {
98
- if(p.data.selected) {
99
- return radius + 10;
100
- }
101
- return radius;
102
- },*/
103
- minRadius: function(p, r, i) {
104
- if(p.data.selected) {
105
- return r + 10;
106
- }
107
- return r;
108
- },
109
- maxRadius: function(p, r, i) {
110
- if(p.data.selected) {
111
- return r + 10;
112
- }
113
- return r;
114
- },
115
- center: function(p, center, index) {
116
- // 如果被选中
117
- if(p.data.selected) {
118
- // 根据中心角度,偏移离中心偏移一个量
119
- const mradius = 10;
120
- // 逆时针需要反过来
121
- const angle = ((p.endAngle - p.startAngle) / 2 + p.startAngle) * (p.anticlockwise? 1: -1);
122
- if(angle !== 0) {
123
- return {
124
- x: center.x + Math.cos(angle) * mradius,
125
- y: center.y - Math.sin(angle) * mradius
126
- }
127
- }
128
- }
129
- return center;
130
- },
131
- // 点击事件
132
- onClick: function(point, e) {
133
- refreshData(point.data.name);
134
- },
135
- /*onOver: function(point, e) {
136
- point.data.overColor = '#D8E404';
137
- this.needUpdate = true;
138
-
139
- // 每隔一段时间检查是否在图形上,否则认为离开
140
- clearTimeout(point.data.___event_check_handler);
141
- point.data.___event_check_handler = setTimeout(() => {
142
- if(point.data.overColor) {
143
- point.data.overColor = '';
144
- this.needUpdate = true;
145
- }
146
- }, 200);
147
- },
148
- onLeave: function(point, e) {
149
- point.data.overColor = '';// 去除当前色
150
- this.needUpdate = true;
151
- },*/
152
- style: {
153
- isHollow: true, // 是否空心
154
- arcWidth: 30, // 圆弧宽
155
- marginAngle: 0.02,// 间隔角度
156
- // 指定颜色获取方式,不指定就会使用默认的
157
- color: function(point) {
158
- if(!point || !point.data) return;
159
- const color = point.data.color || this.graph.getColor(point.x);
160
- if(!point.data.selected) {
161
- // 如果没有被选中,则给个透明度
162
- const colorRGBA = this.graph.utils.hexToRGBA(color);
163
- return `rgba(${colorRGBA.r},${colorRGBA.g},${colorRGBA.b}, 0.5)`;
164
- }
165
- return color;
166
- },
167
- label: {
168
- show: true, // 默认就是true
169
- stroke: '#ccc',
170
- fill: 'blue',
171
- textAlign: 'center',
172
- textBaseline: 'middle',
173
- border: {
174
- top: true,
175
- left: true,
176
- right: true,
177
- bottom: true,
178
- style: {
179
- fill: '#000'
180
- }
181
- }
182
- }
183
- }
184
- });
185
-
186
- var chart2 = new jmChart('mycanvas2', {
187
- width: w,
188
- height: h,
189
- enableAnimate: true,
190
- autoRefresh: true,// 启用动画,建议指定自动动画,否则需要自已写刷新代码
191
- style: {
192
- markLine: false, // 不展示标线
193
- // 指定一个渐变的样式,这里也可以不指定,会用默认的
194
- chartColors: [
195
- `radial-gradient(50% 50% 0 50% 50% 100%,
196
- #42a4ff 0,
197
- #62A2E0 0.5,
198
- #0D64B7 1)`,
199
- `radial-gradient(50% 50% 0 50% 50% 100%,
200
- #fa7d7d 0,
201
- #F2ADB2 0.5,
202
- #fa7d7d 1)`,
203
- `radial-gradient(50% 50% 0 50% 50% 100%,
204
- #007aff 0,
205
- #6CA7E8 0.5,
206
- #054893 1)`
207
- ]
208
- }
209
- });
210
-
211
- var pie2 = chart2.createSeries('pie', {
212
- field: 'y1',
213
- anticlockwise: true, //是否逆时针
214
- legendFormat: function(options) {
215
- return 'test' + options.data.x;
216
- },
217
- itemLabelFormat: function(point) {
218
- return point.data.name + ':' + (point.step * 100).toFixed(2) + '$';
219
- },
220
- /*radius: function(p, radius, index) {
221
- if(p.data.name === 'test0') {
222
- return radius + 20;
223
- }
224
- return radius;
225
- },*/
226
- center: function(p, center, index) {
227
- if(p.data.name === 'test1') {
228
- // 根据中心角度,偏移离中心偏移一个量
229
- const mradius = 20;
230
- // 逆时针需要反过来
231
- const angle = ((p.endAngle - p.startAngle) / 2 + p.startAngle) * (p.anticlockwise? 1: -1);
232
- if(angle !== 0) {
233
- return {
234
- x: center.x + Math.cos(angle) * mradius,
235
- y: center.y - Math.sin(angle) * mradius
236
- }
237
- }
238
- }
239
- return center;
240
- },
241
- style: {
242
- isHollow: false, // 是否空心
243
- marginAngle: 0,// 间隔角度
244
- arcWidth: 50 // 空心时,圆弧的宽度, 不指定就默认20%半径
245
- }
246
- });
247
-
248
- const datacount = 4;
249
-
250
- // 把圆分成一百份, 只有选中的第一个才点半圆 50
251
- const otherNum = 50 / (datacount - 1);
252
- const selectNum = 50;
253
-
254
- let data1 = [
255
- {
256
- x : 0,
257
- name: 'test1',
258
- color: '#249FDA',
259
- y1 : selectNum,
260
- selected: true
261
- },
262
- {
263
- x : 1,
264
- name: 'test2',
265
- color: '#EA3B7C',
266
- y1 : otherNum
267
- },
268
- {
269
- x : 2,
270
- name: 'test3',
271
- color: '#8EBC00',
272
- y1 : otherNum
273
- },
274
- {
275
- x : 3,
276
- name: 'test4',
277
- color: '#309B46',
278
- y1 : otherNum
279
- }
280
- ];
281
-
282
- function refreshData(selectName) {
283
- // 选择没有改变,不处理
284
- if(selectName === data1[0].name) return;
285
-
286
- // 第一个图,当选中某个项后,它移到第一个,其它项顺移
287
- const data1Tmp = [];
288
- for(let i=0; i<data1.length; i++) {
289
- data1[i].selected = false;
290
- if(data1[i].name == selectName) {
291
- data1Tmp.push(data1[i]);
292
- data1[i].y1 = selectNum;
293
-
294
- for(let j=i+1;j<data1.length;j++) {
295
- data1[j].y1 = otherNum;
296
- data1Tmp.push(data1[j]);
297
- }
298
- for(let j=0;j<i;j++) {
299
- data1[j].y1 = otherNum;
300
- data1Tmp.push(data1[j]);
301
- }
302
-
303
- data1[i].selected = true;
304
- break;
305
- }
306
- }
307
- if(data1Tmp.length) data1 = data1Tmp;
308
- // 默认选中第一个
309
- if(!selectName) {
310
- data1[0].selected = true;
311
- }
312
-
313
- chart1.data = data1;
314
- chart1.refresh();
315
-
316
-
317
- const data2 = [];
318
- for(let i=0; i< datacount;i++) {
319
- data2.push({
320
- x : i,
321
- name: 'test' + i,
322
- y1 : Math.random() * 100
323
- });
324
- }
325
- chart2.data = data2;
326
- //setTimeout(animate,500);
327
- // 默认刷新一次
328
- chart2.refresh();
329
-
330
- console.log(chart1.data);
331
- }
332
-
333
-
334
- refreshData();
335
-
336
- chart1.utils.bindEvent(document.getElementById('btnRedraw'),'click', refreshData);
337
-
338
- // // 自动刷新代码
339
- // function update() {
340
- // if(chart1.needUpdate) chart1.redraw();
341
- // requestAnimationFrame(update);
342
- // }
343
- // requestAnimationFrame(update);
344
- }
345
- </script>
346
- </head>
347
- <body>
348
- <div id="mycanvas1">
349
- </div>
350
- <div id="mycanvas2">
351
- </div>
352
- <button id="btnRedraw">重绘</button>
353
- </body>
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <!--<script type="text/javascript" src="../src/jmchart.debug.js" id="jmgraph" ></script>-->
7
+
8
+ <style>
9
+ html,body {
10
+ margin:0;
11
+ padding:0;
12
+ width:100%;
13
+ height:100%;
14
+ }
15
+ #mycanvas canvas, #mycanvas div{
16
+ background-color:#fff;
17
+ margin:0 auto;
18
+ }
19
+ /*div.jm-tooltip {
20
+ background-color: rgba(255,255,255,0.8);
21
+ padding:4px;
22
+ border:1px solid #000;
23
+ box-shadow: 0 0 3px #000;
24
+ border-radius: 6px;
25
+ }*/
26
+ </style>
27
+ <script type="module">
28
+
29
+ import { jmChart } from '../dist/jmchart.esm.js';
30
+
31
+ (function load() {
32
+ var w = Math.max((window.innerWidth || window.document.body.clientWidth) * 0.8, 600);
33
+ var h = Math.max((window.innerHeight || window.document.body.clientHeight) * 0.4, 400);
34
+ inichart(w, h);
35
+ })();
36
+
37
+
38
+ function inichart(w, h) {
39
+ var chart1 = new jmChart('mycanvas1', {
40
+ width: w,
41
+ height: h,
42
+ enableAnimate: true,
43
+ autoRefresh: true,
44
+ style: {
45
+ markLine: false, // 不展示标线
46
+ margin: {
47
+ left: 200,
48
+ top: 100,
49
+ right: 200,
50
+ bottom: 100
51
+ }
52
+ }
53
+ });
54
+
55
+ var pie1 = chart1.createSeries('pie', {
56
+ field: 'y1',
57
+ startAngle: function(data) {
58
+ const step = Math.abs(data[0].y1 / this.totalValue);
59
+ return Math.PI/2 - step * Math.PI;// 当前占的角度的一半加上偏移要刚好等于90度
60
+ },//10,
61
+ anticlockwise: false, //是否逆时针
62
+ legendFormat: function(options) {
63
+ return 'test' + options.data.x;
64
+ },
65
+ itemLabelFormat: function(point) {
66
+ //return (point.step * 100).toFixed(2) + '%';
67
+ //return point.data.name;
68
+ const label = this.graph.createShape('label', {
69
+ style: this.style.label,
70
+ text: point.data.name,
71
+ position: function() {
72
+
73
+ // 动态计算位置
74
+ const parentRect = this.parent.getBounds();
75
+
76
+ // 圆弧的中间位,离圆心最近和最完的二个点
77
+ let centerMaxPoint = this.parent.points[Math.floor(this.parent.points.length / 2)];
78
+ // 如果是空心圆,则要计算 1/4 和 3/4位的点。顺时针和逆时针二个点大小不一样,这里只取,大小计算时处理
79
+ if(point.shape.style.isHollow) {
80
+ centerMaxPoint = this.parent.points[Math.floor(this.parent.points.length * 0.75)];
81
+ }
82
+
83
+ const size = this.testSize();
84
+ const offset = 100;
85
+ const position = {
86
+ x: 0,
87
+ y: 0
88
+ };
89
+
90
+ position.x = (centerMaxPoint.x - this.parent.center.x) / this.parent.radius * offset + centerMaxPoint.x - parentRect.left;
91
+ position.y = (centerMaxPoint.y - this.parent.center.y) / this.parent.radius * offset + centerMaxPoint.y - parentRect.top;
92
+ return position;
93
+ }
94
+ });
95
+ return label;
96
+ },
97
+ /*radius: function(p, radius, index) {
98
+ if(p.data.selected) {
99
+ return radius + 10;
100
+ }
101
+ return radius;
102
+ },*/
103
+ minRadius: function(p, r, i) {
104
+ if(p.data.selected) {
105
+ return r + 10;
106
+ }
107
+ return r;
108
+ },
109
+ maxRadius: function(p, r, i) {
110
+ if(p.data.selected) {
111
+ return r + 10;
112
+ }
113
+ return r;
114
+ },
115
+ center: function(p, center, index) {
116
+ // 如果被选中
117
+ if(p.data.selected) {
118
+ // 根据中心角度,偏移离中心偏移一个量
119
+ const mradius = 10;
120
+ // 逆时针需要反过来
121
+ const angle = ((p.endAngle - p.startAngle) / 2 + p.startAngle) * (p.anticlockwise? 1: -1);
122
+ if(angle !== 0) {
123
+ return {
124
+ x: center.x + Math.cos(angle) * mradius,
125
+ y: center.y - Math.sin(angle) * mradius
126
+ }
127
+ }
128
+ }
129
+ return center;
130
+ },
131
+ // 点击事件
132
+ onClick: function(point, e) {
133
+ refreshData(point.data.name);
134
+ },
135
+ /*onOver: function(point, e) {
136
+ point.data.overColor = '#D8E404';
137
+ this.needUpdate = true;
138
+
139
+ // 每隔一段时间检查是否在图形上,否则认为离开
140
+ clearTimeout(point.data.___event_check_handler);
141
+ point.data.___event_check_handler = setTimeout(() => {
142
+ if(point.data.overColor) {
143
+ point.data.overColor = '';
144
+ this.needUpdate = true;
145
+ }
146
+ }, 200);
147
+ },
148
+ onLeave: function(point, e) {
149
+ point.data.overColor = '';// 去除当前色
150
+ this.needUpdate = true;
151
+ },*/
152
+ style: {
153
+ isHollow: true, // 是否空心
154
+ arcWidth: 30, // 圆弧宽
155
+ marginAngle: 0.02,// 间隔角度
156
+ // 指定颜色获取方式,不指定就会使用默认的
157
+ color: function(point) {
158
+ if(!point || !point.data) return;
159
+ const color = point.data.color || this.graph.getColor(point.x);
160
+ if(!point.data.selected) {
161
+ // 如果没有被选中,则给个透明度
162
+ const colorRGBA = this.graph.utils.hexToRGBA(color);
163
+ return `rgba(${colorRGBA.r},${colorRGBA.g},${colorRGBA.b}, 0.5)`;
164
+ }
165
+ return color;
166
+ },
167
+ label: {
168
+ show: true, // 默认就是true
169
+ stroke: '#ccc',
170
+ fill: 'blue',
171
+ textAlign: 'center',
172
+ textBaseline: 'middle',
173
+ border: {
174
+ top: true,
175
+ left: true,
176
+ right: true,
177
+ bottom: true,
178
+ style: {
179
+ fill: '#000'
180
+ }
181
+ }
182
+ }
183
+ }
184
+ });
185
+
186
+ var chart2 = new jmChart('mycanvas2', {
187
+ width: w,
188
+ height: h,
189
+ enableAnimate: true,
190
+ autoRefresh: true,// 启用动画,建议指定自动动画,否则需要自已写刷新代码
191
+ style: {
192
+ markLine: false, // 不展示标线
193
+ // 指定一个渐变的样式,这里也可以不指定,会用默认的
194
+ chartColors: [
195
+ `radial-gradient(50% 50% 0 50% 50% 100%,
196
+ #42a4ff 0,
197
+ #62A2E0 0.5,
198
+ #0D64B7 1)`,
199
+ `radial-gradient(50% 50% 0 50% 50% 100%,
200
+ #fa7d7d 0,
201
+ #F2ADB2 0.5,
202
+ #fa7d7d 1)`,
203
+ `radial-gradient(50% 50% 0 50% 50% 100%,
204
+ #007aff 0,
205
+ #6CA7E8 0.5,
206
+ #054893 1)`
207
+ ]
208
+ }
209
+ });
210
+
211
+ var pie2 = chart2.createSeries('pie', {
212
+ field: 'y1',
213
+ anticlockwise: true, //是否逆时针
214
+ legendFormat: function(options) {
215
+ return 'test' + options.data.x;
216
+ },
217
+ itemLabelFormat: function(point) {
218
+ return point.data.name + ':' + (point.step * 100).toFixed(2) + '$';
219
+ },
220
+ /*radius: function(p, radius, index) {
221
+ if(p.data.name === 'test0') {
222
+ return radius + 20;
223
+ }
224
+ return radius;
225
+ },*/
226
+ center: function(p, center, index) {
227
+ if(p.data.name === 'test1') {
228
+ // 根据中心角度,偏移离中心偏移一个量
229
+ const mradius = 20;
230
+ // 逆时针需要反过来
231
+ const angle = ((p.endAngle - p.startAngle) / 2 + p.startAngle) * (p.anticlockwise? 1: -1);
232
+ if(angle !== 0) {
233
+ return {
234
+ x: center.x + Math.cos(angle) * mradius,
235
+ y: center.y - Math.sin(angle) * mradius
236
+ }
237
+ }
238
+ }
239
+ return center;
240
+ },
241
+ style: {
242
+ isHollow: false, // 是否空心
243
+ marginAngle: 0,// 间隔角度
244
+ arcWidth: 50 // 空心时,圆弧的宽度, 不指定就默认20%半径
245
+ }
246
+ });
247
+
248
+ const datacount = 4;
249
+
250
+ // 把圆分成一百份, 只有选中的第一个才点半圆 50
251
+ const otherNum = 50 / (datacount - 1);
252
+ const selectNum = 50;
253
+
254
+ let data1 = [
255
+ {
256
+ x : 0,
257
+ name: 'test1',
258
+ color: '#249FDA',
259
+ y1 : selectNum,
260
+ selected: true
261
+ },
262
+ {
263
+ x : 1,
264
+ name: 'test2',
265
+ color: '#EA3B7C',
266
+ y1 : otherNum
267
+ },
268
+ {
269
+ x : 2,
270
+ name: 'test3',
271
+ color: '#8EBC00',
272
+ y1 : otherNum
273
+ },
274
+ {
275
+ x : 3,
276
+ name: 'test4',
277
+ color: '#309B46',
278
+ y1 : otherNum
279
+ }
280
+ ];
281
+
282
+ function refreshData(selectName) {
283
+ // 选择没有改变,不处理
284
+ if(selectName === data1[0].name) return;
285
+
286
+ // 第一个图,当选中某个项后,它移到第一个,其它项顺移
287
+ const data1Tmp = [];
288
+ for(let i=0; i<data1.length; i++) {
289
+ data1[i].selected = false;
290
+ if(data1[i].name == selectName) {
291
+ data1Tmp.push(data1[i]);
292
+ data1[i].y1 = selectNum;
293
+
294
+ for(let j=i+1;j<data1.length;j++) {
295
+ data1[j].y1 = otherNum;
296
+ data1Tmp.push(data1[j]);
297
+ }
298
+ for(let j=0;j<i;j++) {
299
+ data1[j].y1 = otherNum;
300
+ data1Tmp.push(data1[j]);
301
+ }
302
+
303
+ data1[i].selected = true;
304
+ break;
305
+ }
306
+ }
307
+ if(data1Tmp.length) data1 = data1Tmp;
308
+ // 默认选中第一个
309
+ if(!selectName) {
310
+ data1[0].selected = true;
311
+ }
312
+
313
+ chart1.data = data1;
314
+ chart1.refresh();
315
+
316
+
317
+ const data2 = [];
318
+ for(let i=0; i< datacount;i++) {
319
+ data2.push({
320
+ x : i,
321
+ name: 'test' + i,
322
+ y1 : Math.random() * 100
323
+ });
324
+ }
325
+ chart2.data = data2;
326
+ //setTimeout(animate,500);
327
+ // 默认刷新一次
328
+ chart2.refresh();
329
+
330
+ console.log(chart1.data);
331
+ }
332
+
333
+
334
+ refreshData();
335
+
336
+ chart1.utils.bindEvent(document.getElementById('btnRedraw'),'click', refreshData);
337
+
338
+ // // 自动刷新代码
339
+ // function update() {
340
+ // if(chart1.needUpdate) chart1.redraw();
341
+ // requestAnimationFrame(update);
342
+ // }
343
+ // requestAnimationFrame(update);
344
+ }
345
+ </script>
346
+ </head>
347
+ <body>
348
+ <div id="mycanvas1">
349
+ </div>
350
+ <div id="mycanvas2">
351
+ </div>
352
+ <button id="btnRedraw">重绘</button>
353
+ </body>
354
354
  </html>