jmchart 1.1.81 → 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/line.html CHANGED
@@ -1,298 +1,301 @@
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:10px;
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
- //window.devicePixelRatio = 1;
29
- import { jmChart } from '../dist/jmchart.esm.js';
30
-
31
- (function load() {
32
- var w = Math.max((window.innerWidth || window.document.body.clientWidth) * 0.9, 600);
33
- var h = Math.max((window.innerHeight || window.document.body.clientHeight) * 0.6, 200);
34
- inichart(w,h);
35
- })();
36
-
37
-
38
- function inichart(w, h) {
39
- var chart = new jmChart('mycanvas', {
40
- width: w,
41
- height: h,
42
- xField: 'x',
43
- //baseY: 0,
44
- // 最大和最小X值, 这里一般不用指定,除非硬是需要
45
- minXValue : 0,
46
- maxXValue : 10,
47
- minYValue: -100,
48
- maxYValue: 400,
49
- enableAnimate: true,
50
- autoRefresh: true,
51
- yLabelFormat: (value, shape)=>{
52
- return value + '%';
53
- },
54
- xLabelFormat: (value, data, index)=>{
55
- if(index % 5 === 0) return value + 'x';
56
- return '';
57
- },
58
- style: {
59
- margin: {
60
- left: 50
61
- }
62
- }
63
- });
64
- chart.legend.legendPosition = 'top';
65
- chart.legend.visible = true;
66
-
67
- // touch改变数据点事件
68
- chart.on('touchPointChange', function(args) {
69
- console.log(args);
70
- });
71
-
72
- var line1 = chart.createSeries('line', {
73
- field: 'y1',
74
- //index: 2, // 指定Y轴索引,如是档指定就会共用左边的Y轴,
75
- // 最大值和最小值,如果不指定会自动计算,
76
- // 如果指定了也只是指定了最大或最小边界,如果有数值超过它,依然以事实数值为准
77
- minYValue: 0,
78
- maxYValue: 200 ,
79
- style: {
80
- // 画圆滑的曲线
81
- curve: true,// 填充图形
82
- label: {
83
- show: true
84
- },
85
- area: {
86
- // 自定义填充颜色处理
87
- fill: function(style) {
88
- // 根据颜色生成渐变效果
89
- const color = this.graph.utils.hexToRGBA(this.style.stroke);
90
- return `linear-gradient(50% 0 50% 100%,
91
- rgba(${color.r},${color.g},${color.b}, 0) 1,
92
- rgba(${color.r},${color.g},${color.b}, 0) 0.8,
93
- rgba(${color.r},${color.g},${color.b}, 0.3) 0.5,
94
- rgba(${color.r},${color.g},${color.b}, 0.5) 0.2,
95
- rgba(${color.r},${color.g},${color.b}, 0.8) 0)`;
96
- }
97
- }
98
- },
99
- itemLabelFormat: function(p) {
100
- return p.yValue.toFixed(0);
101
- },
102
- legendFormat: function(options) {
103
- return '图例2';
104
- },
105
- // 生成点的回调
106
- onPointCreated(point) {
107
- //console.log('onPointCreated', point);
108
- if(point.data.x === 10) {
109
- addPointMarkLabel.call(this, point);
110
- }
111
- }
112
- });
113
-
114
-
115
-
116
- var line2 = chart.createSeries('line', {
117
- field: 'y2',
118
- legendLabel: '图例3',
119
- style: {
120
- showItem: false
121
- }
122
- });
123
-
124
- var line3 = chart.createSeries('line', {
125
- field: 'y8',
126
- legendLabel: '图例8',
127
- style: {
128
- showItem: false,
129
- lineWidth: 3,
130
- //curve: true,
131
- lineType: 'dotted', // 虚线
132
- shadow: function() {
133
- return `2, 2, 10, ${this.style.stroke}`;
134
- },
135
- }
136
- });
137
- var line4 = chart.createSeries('line', {
138
- field: 'y9',
139
- legendLabel: '图例9',
140
- style: {
141
- showItem: false,
142
- lineWidth: 3,
143
- shadow: function() {
144
- return `2, 2, 10, ${this.style.stroke}`;
145
- },
146
- area: {
147
- // 自定义填充颜色处理
148
- fill: function(style) {
149
- // 根据颜色生成渐变效果
150
- const color = this.graph.utils.hexToRGBA(this.style.stroke);
151
- return `linear-gradient(50% 0 50% 100%,
152
- rgba(${color.r},${color.g},${color.b}, 0) 1,
153
- rgba(${color.r},${color.g},${color.b}, 0) 0.8,
154
- rgba(${color.r},${color.g},${color.b}, 0.3) 0.5,
155
- rgba(${color.r},${color.g},${color.b}, 0.5) 0.2,
156
- rgba(${color.r},${color.g},${color.b}, 0.8) 0)`;
157
- }
158
- }
159
- }
160
- });
161
- var line5 = chart.createSeries('line', {
162
- field: 'y10',
163
- legendLabel: '图例10',
164
- style: {
165
- showItem: false,
166
- lineWidth: 3,
167
- lineType: 'dotted', // 虚线
168
- shadow: function() {
169
- return `2, 2, 10, ${this.style.stroke}`;
170
- },
171
- }
172
- });
173
-
174
- const datacount = 50;
175
- function animate() {
176
- if(true) {
177
- chart.data = [];
178
- for(var i = 0;i<datacount;i++) {
179
- var data = {
180
- x : i,
181
- y1 : Math.random() * 200 - 100,
182
- y2: Math.random() * 200 + 50,
183
- y3: Math.random() * 200 + 50,
184
- y4:Math.random() * 200 + 50,
185
- y5:Math.random() * 200 + 50,
186
- y6:Math.random() * 200 + 50,
187
- y7:i,
188
- y8: i * 6 + Math.random(),
189
- y9: i * 3 + Math.random(),
190
- y10: -i + Math.random()
191
- };
192
- if(i == 3) {
193
- data.y = null;
194
- }
195
- chart.data.push(data);
196
- }
197
- }
198
- else {
199
- for(var i=datacount-1;i>0;i--) {
200
- var x = chart.data[i].x;
201
- chart.data[i] = chart.utils.clone(chart.data[i - 1]);
202
- chart.data[i].x = x;
203
- }
204
-
205
- chart.source[0] = {
206
- x : chart.data[0].x,
207
- y : Math.random() * 200 - 100
208
- };
209
-
210
- }
211
-
212
- //setTimeout(animate,500);
213
- chart.refresh();
214
- console.log(chart.data);
215
- }
216
-
217
- animate();
218
- chart.utils.bindEvent(document.getElementById('btnRedraw'),'click',animate);
219
-
220
- }
221
-
222
- // 创建点的标注
223
- function addPointMarkLabel(point) {
224
- const w = 40 * this.graph.devicePixelRatio;
225
- const h = 20 * this.graph.devicePixelRatio;
226
- const bottom = 20 * this.graph.devicePixelRatio;
227
- const arrowOffset = 10 * this.graph.devicePixelRatio;
228
-
229
- // 标注图形左上角
230
- const p1 = {
231
- x: point.x - w / 2,
232
- y: point.y - bottom - h
233
- };
234
- const p2 = {
235
- x: p1.x,
236
- y: p1.y + h
237
- };
238
- const p3 = {
239
- x: p2.x + w,
240
- y: p2.y
241
- };
242
- const p4 = {
243
- x: p3.x,
244
- y: p1.y
245
- };
246
-
247
- const labelPath = this.graph.createShape('path', {
248
- style: {
249
- stroke: 'red',
250
- fill: '#55cccccc',
251
- zIndex: 18,
252
- close: true
253
- },
254
- points: [
255
- p1,
256
- p2,
257
- {
258
- x: point.x - arrowOffset / 2,
259
- y: p2.y
260
- },
261
- {
262
- x: point.x,
263
- y: p2.y + arrowOffset
264
- },
265
- {
266
- x: point.x + arrowOffset / 2,
267
- y: p2.y
268
- },
269
- p3,
270
- p4
271
- ]
272
- });
273
- const label = this.graph.createShape('label', {
274
- style: {
275
- textAlign: 'center',
276
- textBaseline: 'middle',
277
- fill: 'red'
278
- },
279
- center: {
280
- x: w / 2,
281
- y: h / 2 + 2
282
- },
283
- text: '买入'
284
- });
285
- labelPath.children.add(label);
286
- this.addShape(labelPath);
287
- }
288
- </script>
289
- </head>
290
- <body>
291
- <div id="mycanvas">
292
- </div>
293
- <button id="btnRedraw">重绘</button>
294
-
295
- <br />
296
- <iframe src="wk/line.html" style="width: 90%;height: 600px;"></iframe>
297
- </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:10px;
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
+ //window.devicePixelRatio = 1;
29
+ import { jmChart } from '../dist/jmchart.esm.js';
30
+
31
+ (function load() {
32
+ var w = Math.max((window.innerWidth || window.document.body.clientWidth) * 0.9, 600);
33
+ var h = Math.max((window.innerHeight || window.document.body.clientHeight) * 0.6, 200);
34
+ inichart(w,h);
35
+ })();
36
+
37
+
38
+ function inichart(w, h) {
39
+ var chart = new jmChart('mycanvas', {
40
+ width: w,
41
+ height: h,
42
+ xField: 'x',
43
+ //baseY: 0,
44
+ // 最大和最小X值, 这里一般不用指定,除非硬是需要
45
+ minXValue : 0,
46
+ maxXValue : 10,
47
+ minYValue: -100,
48
+ maxYValue: 400,
49
+ enableAnimate: true,
50
+ autoRefresh: true,
51
+ yLabelFormat: (value, shape)=>{
52
+ return value + '%';
53
+ },
54
+ xLabelFormat: (value, data, index)=>{
55
+ if(index % 5 === 0) return value + 'x';
56
+ return '';
57
+ },
58
+ style: {
59
+ margin: {
60
+ left: 50
61
+ },
62
+ legend: {
63
+ legendPosition: 'top'
64
+ }
65
+ }
66
+ });
67
+ //chart.legend.legendPosition = 'top';
68
+ chart.legend.visible = true;
69
+
70
+ // touch改变数据点事件
71
+ chart.on('touchPointChange', function(args) {
72
+ console.log(args);
73
+ });
74
+
75
+ var line1 = chart.createSeries('line', {
76
+ field: 'y1',
77
+ //index: 2, // 指定Y轴索引,如是档指定就会共用左边的Y轴,
78
+ // 最大值和最小值,如果不指定会自动计算,
79
+ // 如果指定了也只是指定了最大或最小边界,如果有数值超过它,依然以事实数值为准
80
+ minYValue: 0,
81
+ maxYValue: 200 ,
82
+ style: {
83
+ // 画圆滑的曲线
84
+ curve: true,// 填充图形
85
+ label: {
86
+ show: true
87
+ },
88
+ area: {
89
+ // 自定义填充颜色处理
90
+ fill: function(style) {
91
+ // 根据颜色生成渐变效果
92
+ const color = this.graph.utils.hexToRGBA(this.style.stroke);
93
+ return `linear-gradient(50% 0 50% 100%,
94
+ rgba(${color.r},${color.g},${color.b}, 0) 1,
95
+ rgba(${color.r},${color.g},${color.b}, 0) 0.8,
96
+ rgba(${color.r},${color.g},${color.b}, 0.3) 0.5,
97
+ rgba(${color.r},${color.g},${color.b}, 0.5) 0.2,
98
+ rgba(${color.r},${color.g},${color.b}, 0.8) 0)`;
99
+ }
100
+ }
101
+ },
102
+ itemLabelFormat: function(p) {
103
+ return p.yValue.toFixed(0);
104
+ },
105
+ legendFormat: function(options) {
106
+ return '图例2';
107
+ },
108
+ // 生成点的回调
109
+ onPointCreated(point) {
110
+ //console.log('onPointCreated', point);
111
+ if(point.data.x === 10) {
112
+ addPointMarkLabel.call(this, point);
113
+ }
114
+ }
115
+ });
116
+
117
+
118
+
119
+ var line2 = chart.createSeries('line', {
120
+ field: 'y2',
121
+ legendLabel: '图例3',
122
+ style: {
123
+ showItem: false
124
+ }
125
+ });
126
+
127
+ var line3 = chart.createSeries('line', {
128
+ field: 'y8',
129
+ legendLabel: '图例8',
130
+ style: {
131
+ showItem: false,
132
+ lineWidth: 3,
133
+ //curve: true,
134
+ lineType: 'dotted', // 虚线
135
+ shadow: function() {
136
+ return `2, 2, 10, ${this.style.stroke}`;
137
+ },
138
+ }
139
+ });
140
+ var line4 = chart.createSeries('line', {
141
+ field: 'y9',
142
+ legendLabel: '图例9',
143
+ style: {
144
+ showItem: false,
145
+ lineWidth: 3,
146
+ shadow: function() {
147
+ return `2, 2, 10, ${this.style.stroke}`;
148
+ },
149
+ area: {
150
+ // 自定义填充颜色处理
151
+ fill: function(style) {
152
+ // 根据颜色生成渐变效果
153
+ const color = this.graph.utils.hexToRGBA(this.style.stroke);
154
+ return `linear-gradient(50% 0 50% 100%,
155
+ rgba(${color.r},${color.g},${color.b}, 0) 1,
156
+ rgba(${color.r},${color.g},${color.b}, 0) 0.8,
157
+ rgba(${color.r},${color.g},${color.b}, 0.3) 0.5,
158
+ rgba(${color.r},${color.g},${color.b}, 0.5) 0.2,
159
+ rgba(${color.r},${color.g},${color.b}, 0.8) 0)`;
160
+ }
161
+ }
162
+ }
163
+ });
164
+ var line5 = chart.createSeries('line', {
165
+ field: 'y10',
166
+ legendLabel: '图例10',
167
+ style: {
168
+ showItem: false,
169
+ lineWidth: 3,
170
+ lineType: 'dotted', // 虚线
171
+ shadow: function() {
172
+ return `2, 2, 10, ${this.style.stroke}`;
173
+ },
174
+ }
175
+ });
176
+
177
+ const datacount = 50;
178
+ function animate() {
179
+ if(true) {
180
+ chart.data = [];
181
+ for(var i = 0;i<datacount;i++) {
182
+ var data = {
183
+ x : i,
184
+ y1 : Math.random() * 200 - 100,
185
+ y2: Math.random() * 200 + 50,
186
+ y3: Math.random() * 200 + 50,
187
+ y4:Math.random() * 200 + 50,
188
+ y5:Math.random() * 200 + 50,
189
+ y6:Math.random() * 200 + 50,
190
+ y7:i,
191
+ y8: i * 6 + Math.random(),
192
+ y9: i * 3 + Math.random(),
193
+ y10: -i + Math.random()
194
+ };
195
+ if(i == 3) {
196
+ data.y = null;
197
+ }
198
+ chart.data.push(data);
199
+ }
200
+ }
201
+ else {
202
+ for(var i=datacount-1;i>0;i--) {
203
+ var x = chart.data[i].x;
204
+ chart.data[i] = chart.utils.clone(chart.data[i - 1]);
205
+ chart.data[i].x = x;
206
+ }
207
+
208
+ chart.source[0] = {
209
+ x : chart.data[0].x,
210
+ y : Math.random() * 200 - 100
211
+ };
212
+
213
+ }
214
+
215
+ //setTimeout(animate,500);
216
+ chart.refresh();
217
+ console.log(chart.data);
218
+ }
219
+
220
+ animate();
221
+ chart.utils.bindEvent(document.getElementById('btnRedraw'),'click',animate);
222
+
223
+ }
224
+
225
+ // 创建点的标注
226
+ function addPointMarkLabel(point) {
227
+ const w = 40 * this.graph.devicePixelRatio;
228
+ const h = 20 * this.graph.devicePixelRatio;
229
+ const bottom = 20 * this.graph.devicePixelRatio;
230
+ const arrowOffset = 10 * this.graph.devicePixelRatio;
231
+
232
+ // 标注图形左上角
233
+ const p1 = {
234
+ x: point.x - w / 2,
235
+ y: point.y - bottom - h
236
+ };
237
+ const p2 = {
238
+ x: p1.x,
239
+ y: p1.y + h
240
+ };
241
+ const p3 = {
242
+ x: p2.x + w,
243
+ y: p2.y
244
+ };
245
+ const p4 = {
246
+ x: p3.x,
247
+ y: p1.y
248
+ };
249
+
250
+ const labelPath = this.graph.createShape('path', {
251
+ style: {
252
+ stroke: 'red',
253
+ fill: '#55cccccc',
254
+ zIndex: 18,
255
+ close: true
256
+ },
257
+ points: [
258
+ p1,
259
+ p2,
260
+ {
261
+ x: point.x - arrowOffset / 2,
262
+ y: p2.y
263
+ },
264
+ {
265
+ x: point.x,
266
+ y: p2.y + arrowOffset
267
+ },
268
+ {
269
+ x: point.x + arrowOffset / 2,
270
+ y: p2.y
271
+ },
272
+ p3,
273
+ p4
274
+ ]
275
+ });
276
+ const label = this.graph.createShape('label', {
277
+ style: {
278
+ textAlign: 'center',
279
+ textBaseline: 'middle',
280
+ fill: 'red'
281
+ },
282
+ center: {
283
+ x: w / 2,
284
+ y: h / 2 + 2
285
+ },
286
+ text: '买入'
287
+ });
288
+ labelPath.children.add(label);
289
+ this.addShape(labelPath);
290
+ }
291
+ </script>
292
+ </head>
293
+ <body>
294
+ <div id="mycanvas">
295
+ </div>
296
+ <button id="btnRedraw">重绘</button>
297
+
298
+ <br />
299
+ <iframe src="wk/line.html" style="width: 90%;height: 600px;"></iframe>
300
+ </body>
298
301
  </html>