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