jmchart 1.2.6 → 1.2.9

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