jmchart 1.1.95 → 1.1.98

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/bar.html CHANGED
@@ -60,13 +60,14 @@
60
60
  }
61
61
  },
62
62
  margin: {
63
+
63
64
  bottom: 2
64
65
  },
65
66
  }
66
67
  });
67
68
  chart.legend.legendPosition = 'top';
68
69
  chart.legend.visible = true;
69
- chart.enableAnimate = false;
70
+ chart.enableAnimate = true;
70
71
 
71
72
  // touch改变数据点事件
72
73
  chart.on('touchPointChange', function(args) {
@@ -118,7 +119,7 @@
118
119
  }
119
120
  });
120
121
 
121
- /*var bar2 = chart.createSeries('bar', {
122
+ var bar2 = chart.createSeries('bar', {
122
123
  field: 'y8',
123
124
  style: {
124
125
  // 自定义单个bar的颜色
@@ -141,7 +142,7 @@
141
142
  yLabelFormat: (v, label) => {
142
143
  return v.toFixed(0);
143
144
  }
144
- });*/
145
+ });
145
146
 
146
147
  const datacount = 5;
147
148
  function animate() {
package/example/line.html CHANGED
@@ -13,7 +13,7 @@
13
13
  height:100%;
14
14
  }
15
15
  #mycanvas canvas, #mycanvas div{
16
- background-color:#fff;
16
+ background-color:#ddd;
17
17
  margin:0 auto;
18
18
  }
19
19
  /*div.jm-tooltip {
@@ -57,10 +57,17 @@
57
57
  },
58
58
  style: {
59
59
  margin: {
60
- left: 50
60
+ left: 80
61
61
  },
62
62
  legend: {
63
63
  legendPosition: 'top'
64
+ },
65
+ axis: {
66
+ yLabel: {
67
+ margin: {
68
+ left: 30
69
+ }
70
+ }
64
71
  }
65
72
  }
66
73
  });
@@ -72,6 +79,12 @@
72
79
  console.log(args);
73
80
  });
74
81
 
82
+ // 滑动标线,阻止默认事件
83
+ chart.on('marklinemove', (args)=>{
84
+ args.event.preventDefault();// 阻止默认行为
85
+ args.event.stopPropagation();
86
+ });
87
+
75
88
  var line1 = chart.createSeries('line', {
76
89
  field: 'y1',
77
90
  //index: 2, // 指定Y轴索引,如是档指定就会共用左边的Y轴,
@@ -80,11 +93,12 @@
80
93
  minYValue: 0,
81
94
  maxYValue: 200 ,
82
95
  style: {
83
- // 画圆滑的曲线
96
+ // 画圆滑的曲线 , 否则就是折线
84
97
  curve: true,// 填充图形
85
98
  label: {
86
99
  show: true
87
100
  },
101
+ color: 'blue',
88
102
  area: {
89
103
  // 自定义填充颜色处理
90
104
  fill: function(style) {
package/example/pie.html CHANGED
@@ -132,6 +132,43 @@
132
132
  onClick: function(point, e) {
133
133
  refreshData(point.data.name);
134
134
  },
135
+ // 图初始化回调
136
+ onInit: function(center, radius) {
137
+ const label1 = this.graph.createShape('label', {
138
+ style: {
139
+ stroke: '#effaaa',
140
+ fill: 'red',
141
+ textAlign: 'right',
142
+ textBaseline: 'middle',
143
+ fontFamily: "Arial",
144
+ fontSize: 24,
145
+ shadow: '0,0,10,#fff'
146
+ },
147
+ text: '2个',
148
+ center: {
149
+ x: center.x,
150
+ y: center.y - 10
151
+ }
152
+ });
153
+ this.addShape(label1);
154
+ const label2 = this.graph.createShape('label', {
155
+ style: {
156
+ stroke: '#effaaa',
157
+ fill: '#000',
158
+ textAlign: 'right',
159
+ textBaseline: 'middle',
160
+ font: "normal bold 20px Arial",
161
+ //fontSize: 40,
162
+ shadow: '0,0,10,#fff'
163
+ },
164
+ text: '资产分布',
165
+ center: {
166
+ x: center.x,
167
+ y: center.y + 15
168
+ }
169
+ });
170
+ this.addShape(label2);
171
+ },
135
172
  /*onOver: function(point, e) {
136
173
  point.data.overColor = '#D8E404';
137
174
  this.needUpdate = true;
@@ -0,0 +1,162 @@
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 {
16
+ margin-top: 50px;
17
+ }
18
+ #mycanvas canvas, #mycanvas div{
19
+
20
+ background-color:#fff;
21
+ margin:0 auto;
22
+ }
23
+ /*div.jm-tooltip {
24
+ background-color: rgba(255,255,255,0.8);
25
+ padding:4px;
26
+ border:1px solid #000;
27
+ box-shadow: 0 0 3px #000;
28
+ border-radius: 6px;
29
+ }*/
30
+ </style>
31
+ <script type="module">
32
+
33
+ import { jmChart } from '../dist/jmchart.esm.js';
34
+
35
+ (function load() {
36
+ var w = Math.max((window.innerWidth || window.document.body.clientWidth) * 0.8, 600);
37
+ var h = Math.max((window.innerHeight || window.document.body.clientHeight) * 0.4, 400);
38
+ inichart(w, h);
39
+ })();
40
+
41
+
42
+ function inichart(w, h) {
43
+ var chart1 = new jmChart('mycanvas', {
44
+ width: w,
45
+ height: h,
46
+ enableAnimate: true,
47
+ //autoRefresh: false,
48
+ yLabelFormat: function() {
49
+ return this.field;
50
+ },
51
+ style: {
52
+ markLine: false, // 不展示标线
53
+ chartArea: {
54
+ stroke: 'transparent'
55
+ },
56
+ axis: {
57
+ stroke: '#ccc',
58
+ // 指定栅格条数
59
+ xLabel: {
60
+ count: 3
61
+ }
62
+ },
63
+ grid: {
64
+ x: true, // 是否显示网格
65
+ stroke: '#eaeaf1',
66
+ lineType: 'dotted', // 虚线,不填为实线
67
+ dashLength: 6, //虚线条间隔,默认5
68
+ lineWidth: 1,
69
+ zIndex: 0
70
+ },
71
+ margin: {
72
+ left: 10,
73
+ top: 10,
74
+ right: 80,
75
+ bottom: 10
76
+ }
77
+ }
78
+ });
79
+
80
+ var radar = chart1.createSeries('radar', {
81
+ fields: ['y1' , 'y2', 'y3', 'y4', 'y5', 'y6'],
82
+ legendFormat: function(options) {
83
+ return options.data.x;
84
+ },
85
+ onOver: function(e) {
86
+ console.log(this.option.data)
87
+ e.cancel = true;
88
+ return false;
89
+ },
90
+ itemLabelFormat: function(point) {
91
+ return point.yValue.toFixed(2);
92
+ },
93
+ style: {
94
+ // 指定颜色获取方式,不指定就会使用默认的
95
+ color: function(option) {
96
+ if(!option || !option.data) return;
97
+ const color = option.data.color || this.graph.getColor(option.index);
98
+ return color;
99
+ },
100
+ fill: function(style) {
101
+ if(!style) return '';
102
+ const color = this.graph.utils.hexToRGBA(style.stroke);
103
+ return `rgba(${color.r},${color.g},${color.b}, 0.2)`;
104
+ },
105
+ label: {
106
+ show: true, // 默认就是true, 如果不想显示标签,设为false
107
+ stroke: '#ccc',
108
+ fill: 'green',
109
+ textAlign: 'center',
110
+ textBaseline: 'middle',
111
+ zIndex: -1,
112
+ border: 0
113
+ }
114
+ }
115
+ });
116
+
117
+
118
+ const datacount = 4;
119
+ let data = [
120
+ ];
121
+
122
+ function refreshData() {
123
+
124
+ data = [];
125
+ for(let i=0; i<datacount; i++) {
126
+
127
+ data.push({
128
+ x: 'test' + i,
129
+ y1: 10 * i + Math.random() * 10,
130
+ y2: 10 * i + Math.random() * 50,
131
+ y3: 10 * i + Math.random() * 100,
132
+ y4: 10 * i + Math.random() * 120,
133
+ y5: 10 * i + Math.random() * 120,
134
+ y6: 10 * i + Math.random() * 120
135
+ });
136
+ }
137
+
138
+ chart1.data = data;
139
+ chart1.refresh();
140
+
141
+ }
142
+
143
+
144
+ refreshData();
145
+
146
+ chart1.utils.bindEvent(document.getElementById('btnRedraw'),'click', refreshData);
147
+
148
+ // // 自动刷新代码
149
+ // function update() {
150
+ // if(chart1.needUpdate) chart1.redraw();
151
+ // requestAnimationFrame(update);
152
+ // }
153
+ // requestAnimationFrame(update);
154
+ }
155
+ </script>
156
+ </head>
157
+ <body>
158
+ <div id="mycanvas">
159
+ </div>
160
+ <button id="btnRedraw">重绘</button>
161
+ </body>
162
+ </html>
@@ -61,10 +61,17 @@
61
61
  left: 100,
62
62
  right: 100
63
63
  },
64
+ markLine: {
65
+ longtap: false, // 长按才出现标线
66
+ lock: {
67
+ y: 10,
68
+ x: 10
69
+ }
70
+ },
64
71
  //layout: 'inside'
65
72
  },
66
73
  xAxisOption: {
67
- arrowVisible: false
74
+ arrowVisible: true
68
75
  },
69
76
  yAxisOption: {
70
77
  arrowVisible: false
@@ -77,6 +84,11 @@
77
84
  chart.on('touchPointChange', function(args) {
78
85
  console.log(args);
79
86
  });
87
+ // 滑动标线,阻止默认事件
88
+ chart.on('marklinemove', (args)=>{
89
+ //args.event.preventDefault();// 阻止默认行为
90
+ //args.event.stopPropagation();
91
+ });
80
92
 
81
93
  var line1 = chart.createSeries('line', {
82
94
  field: 'y1',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jmchart",
3
- "version": "1.1.95",
3
+ "version": "1.1.98",
4
4
  "description": "chart",
5
5
  "main": "./index.js",
6
6
  "directories": {
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/jiamao/jmchart#readme",
30
30
  "dependencies": {
31
- "jmgraph": "^3.1.90"
31
+ "jmgraph": "^3.1.94"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@babel/core": "^7.10.2",
@@ -203,7 +203,6 @@ export default {
203
203
  zIndex: 17,
204
204
  cursor: 'default',
205
205
  close : true,
206
- opacity: 0.8,
207
206
  shadow: {
208
207
  x: 1,
209
208
  y: 1,
@@ -232,7 +231,34 @@ export default {
232
231
  zIndex: 11,
233
232
  cursor: 'default',
234
233
  close : true,
235
- opacity: 0.8,
234
+ shadow: {
235
+ x: 1,
236
+ y: 1,
237
+ blur: 2,
238
+ color: '#ccc'
239
+ }
240
+ },
241
+ radar: {
242
+ normal: {
243
+ zIndex: 11,
244
+ cursor: 'default',
245
+ opacity: 0.8
246
+ },
247
+ hover: {
248
+ //zIndex: 100,
249
+ opacity: 1,
250
+ cursor: 'pointer'
251
+ },
252
+ margin: {
253
+ left: 10,
254
+ top: 10,
255
+ right: 10,
256
+ bottom: 10
257
+ },
258
+ lineWidth: 1,
259
+ zIndex: 11,
260
+ cursor: 'default',
261
+ close : true,
236
262
  shadow: {
237
263
  x: 1,
238
264
  y: 1,
@@ -43,8 +43,7 @@ export default {
43
43
 
44
44
  // 销毁
45
45
  destroyed() {
46
- this.chartInstance && this.chartInstance.destory();
47
- this.chartInstance && this.chartInstance.touchGraph && this.chartInstance.touchGraph.destory();
46
+ this.chartInstance && this.chartInstance.destroy();
48
47
  },
49
48
 
50
49
  watch: {
@@ -33,6 +33,7 @@ export default class jmAxis extends jmArrowLine {
33
33
 
34
34
  this.field = options.field || '';
35
35
  this.index = options.index || 0;
36
+ this.gridLines = [];// 线条数组
36
37
 
37
38
  this.init(options);
38
39
  }
@@ -44,6 +45,9 @@ export default class jmAxis extends jmArrowLine {
44
45
  // 深度组件默认样式
45
46
  if(options.style) this.graph.utils.clone(options.style, this.style, true);
46
47
 
48
+ this.field = options.field || this.field || '';
49
+ this.radarOption = options.radarOption;
50
+
47
51
  if(this.type == 'x') {
48
52
  if(typeof options.maxXValue !== 'undefined') this.maxValue = options.maxXValue; // 最大的值,如果指定了,则如果有数值比它大才会修改上限,否则以它为上限
49
53
  if(typeof options.minXValue !== 'undefined') this.minValue = options.minXValue;// 最小值,如果指定了,则轴的最小值为它或更小的值
@@ -98,6 +102,11 @@ export default class jmAxis extends jmArrowLine {
98
102
  */
99
103
  scalePoints = [];
100
104
 
105
+ /**
106
+ * 轴上的标签,只读
107
+ */
108
+ labels = [];
109
+
101
110
  /**
102
111
  * 关联访问的是chart的数据源
103
112
  */
@@ -108,6 +117,23 @@ export default class jmAxis extends jmArrowLine {
108
117
  this.graph.data = d;
109
118
  }
110
119
 
120
+ // 生成绘制点,
121
+ // 重写原函数
122
+ initPoints() {
123
+ // 如果是雷达图
124
+ if(this.radarOption && this.type === 'x') {
125
+ this.points = [];
126
+ for(const axis of this.radarOption.yAxises) {
127
+ axis.end && this.points.push(axis.end);
128
+ }
129
+ this.points.push(this.points[0]);
130
+ return this.points;
131
+ }
132
+ else {
133
+ return super.initPoints();
134
+ }
135
+ }
136
+
111
137
 
112
138
  /**
113
139
  * 计算当前轴的位置
@@ -115,12 +141,41 @@ export default class jmAxis extends jmArrowLine {
115
141
  * @method reset
116
142
  */
117
143
  reset() {
118
-
119
144
  const bounds = this.graph.chartArea.getBounds();// 获取画图区域
120
145
  switch(this.type) {
121
- case 'x' : {
146
+ case 'x' : {
122
147
  //初始化显示标签个数
123
- this.labelCount = this.style.xLabel.count || 5;
148
+ this.labelCount = this.style.xLabel.count || 5;
149
+ // 如果是雷达图,则画栅格线
150
+ if(this.radarOption) {
151
+ if(this.style.grid && this.style.grid.x) {
152
+ for(let i=1; i< this.labelCount+1; i++) {
153
+ const points = [];
154
+ const curRadius = this.radarOption.radius / this.labelCount * i;
155
+ for(const axis of this.radarOption.yAxises) {
156
+ if(!axis.radarOption) continue;
157
+ const point = {};
158
+ point.x = axis.radarOption.center.x + axis.radarOption.cos * curRadius + bounds.left;
159
+ point.y = axis.radarOption.center.y - axis.radarOption.sin * curRadius + bounds.top;
160
+ points.push(point);
161
+ }
162
+ // 画栅格线
163
+ for(let j=0; j<points.length; j++) {
164
+ const start = points[j];
165
+ const end = points[j+1] || points[0];
166
+ const gridLine = this.graph.createShape('line', {
167
+ start,
168
+ end,
169
+ style: this.style.grid
170
+ });
171
+ this.parent.children.add(gridLine);
172
+ this.gridLines.push(gridLine);
173
+ }
174
+ }
175
+ }
176
+ break;
177
+ }
178
+
124
179
  this.start.x = bounds.left;
125
180
  this.start.y = bounds.bottom;
126
181
  this.end.x = bounds.right;
@@ -137,25 +192,34 @@ export default class jmAxis extends jmArrowLine {
137
192
  }
138
193
  break;
139
194
  }
140
- case 'y' : {
141
- const index = this.index || 1;
142
- let xoffset = bounds.left;
143
-
195
+ case 'y' : {
144
196
  //初始化显示标签个数
145
197
  this.labelCount = this.style.yLabel.count || 5;
146
-
147
- //多Y轴时,第二个为右边第一轴,其它的依此递推
148
- if(index == 2) {
149
- xoffset = bounds.right;
150
- }
151
- else if(index > 2) {
152
- xoffset = this.graph.yAxises[index-1].start.x + this.graph.yAxises[index-1].width + 10;
153
- }
154
-
155
- this.start.x = xoffset;
156
- this.start.y = bounds.bottom;
157
- this.end.x = this.start.x;
158
- this.end.y = bounds.top;
198
+
199
+ const index = this.index || 1;
200
+ // 如果是雷达图,则画发散的线
201
+ if(this.radarOption) {
202
+ this.end.x = this.radarOption.center.x + this.radarOption.cos * this.radarOption.radius + bounds.left;;
203
+ this.end.y = this.radarOption.center.y - this.radarOption.sin * this.radarOption.radius + bounds.top;
204
+ this.start.x = this.radarOption.center.x + bounds.left;
205
+ this.start.y = this.radarOption.center.y + bounds.top;
206
+ }
207
+ else {
208
+ let xoffset = bounds.left;
209
+
210
+ //多Y轴时,第二个为右边第一轴,其它的依此递推
211
+ if(index == 2) {
212
+ xoffset = bounds.right;
213
+ }
214
+ else if(index > 2) {
215
+ xoffset = this.graph.yAxises[index-1].start.x + this.graph.yAxises[index-1].width + 10;
216
+ }
217
+
218
+ this.start.x = xoffset;
219
+ this.start.y = bounds.bottom;
220
+ this.end.x = this.start.x;
221
+ this.end.y = bounds.top;
222
+ }
159
223
  break;
160
224
  }
161
225
  }
@@ -174,17 +238,18 @@ export default class jmAxis extends jmArrowLine {
174
238
  * @method createLabel
175
239
  */
176
240
  createLabel() {
177
- //移除原有的标签
178
- this.children.each(function(i, c) {
179
- c.remove();
180
- }, true);
181
-
182
- this.labels = [];
241
+ if(this.visible === false) return;
242
+
243
+ // 雷达图的标签单独处理
244
+ if(this.radarOption) {
245
+ return this.createRadarLabel();
246
+ }
247
+
183
248
  //如果是?X轴则执行X轴标签生成
184
249
  if(this.type == 'x') {
185
250
  this.createXLabel();
186
251
  }
187
- else if(this.type == 'y') {
252
+ else if(this.type == 'y') {
188
253
  this.createYLabel();
189
254
  }
190
255
  }
@@ -303,23 +368,19 @@ export default class jmAxis extends jmArrowLine {
303
368
  this.scalePoints = [];// 刻度点集合
304
369
 
305
370
  let count = this.labelCount;
306
- const mm = max - min;
307
- /*if(mm <= 10) {
308
- count = mm;
309
- }*/
310
- // mm 放大10000倍,这里结果也需要除于10000
311
- let pervalue = (mm / count) || 1;
312
- //if(pervalue > 1 || pervalue < -1) pervalue = Math.floor(pervalue);
371
+ const mm = max - min;
372
+ let pervalue = (mm / count) || 1;
313
373
 
314
374
  const format = this.option.format || this.format;
315
375
  const marginLeft = this.style.yLabel.margin.left * this.graph.devicePixelRatio || 0;
316
376
  const marginRight = this.style.yLabel.margin.right * this.graph.devicePixelRatio || 0;
317
377
  let p = 0;
378
+
318
379
  for(let i=0; i<count+1; i++) {
319
380
  p = min + pervalue * i;
320
381
  if(p > max || i === count) p = max;
321
382
  const h = (p - min) * step; // 当前点的偏移高度
322
- const label = this.graph.graph.createShape('label', {
383
+ const label = this.graph.createShape('label', {
323
384
  style: this.style.yLabel
324
385
  });
325
386
 
@@ -357,7 +418,7 @@ export default class jmAxis extends jmArrowLine {
357
418
  });
358
419
 
359
420
  // 指定要显示网格
360
- if(this.style.grid && this.style.grid.x) {
421
+ if(!this.radarOption && this.style.grid && this.style.grid.x) {
361
422
  // 它的坐标是相对于轴的,所以Y轴会用负的区域高度
362
423
  const line = this.graph.createShape('line', {
363
424
  start: {
@@ -423,6 +484,38 @@ export default class jmAxis extends jmArrowLine {
423
484
  }
424
485
  }
425
486
 
487
+ /**
488
+ * 生成雷达图的Y轴标签
489
+ */
490
+ createRadarLabel() {
491
+ const format = this.option.format;
492
+ const bounds = this.graph.chartArea.getBounds();// 获取画图区域
493
+ const self = this;
494
+ const label = this.graph.createShape('label', {
495
+ style: this.style.yLabel,
496
+ position: function() {
497
+ // 因为axis是相对于chart的,而center是相对于chartArea的,所以要计算axis位置相对于chartArea来比较
498
+ const pos = {
499
+ x: self.end.x - bounds.left,
500
+ y: self.end.y - bounds.top
501
+ };
502
+ const size = this.testSize();
503
+ if(pos.x < self.radarOption.center.x) {
504
+ pos.x -= size.width;
505
+ }
506
+
507
+ if(pos.y < self.radarOption.center.y) {
508
+ pos.y -= size.height;
509
+ }
510
+ return pos;
511
+ }
512
+ });
513
+
514
+ label.text = typeof format === 'function'? format.call(this, label): this.field; // 格式化label
515
+ this.labels.push(label);
516
+ this.graph.chartArea.children.add(label);
517
+ }
518
+
426
519
  /**
427
520
  * 获取当前轴所占宽
428
521
  *
@@ -569,6 +662,18 @@ export default class jmAxis extends jmArrowLine {
569
662
  clear() {
570
663
  this._min = null;
571
664
  this._max = null;
665
+ this.children.each((i, c) => {
666
+ c.remove();
667
+ }, true);
668
+ // 清空栅格线
669
+ this.gridLines && this.gridLines.forEach((line)=>{
670
+ line.remove();
671
+ });
672
+ this.labels && this.labels.forEach((label)=>{
673
+ label.remove();
674
+ });
675
+ this.labels = [];
676
+ this.gridLines = [];
572
677
  }
573
678
 
574
679
  /**
@@ -579,7 +684,7 @@ export default class jmAxis extends jmArrowLine {
579
684
  */
580
685
  step() {
581
686
  if(this.type == 'x') {
582
- const w = this.width;
687
+ const w = this.radarOption? this.radarOption.radius : this.width;
583
688
 
584
689
  //如果排版为内联,则单位占宽减少一个单位,
585
690
  //也就是起始位从一个单位开始
@@ -597,7 +702,7 @@ export default class jmAxis extends jmArrowLine {
597
702
 
598
703
  }
599
704
  else if(this.type == 'y') {
600
- const h = this.height;
705
+ const h = this.radarOption? this.radarOption.radius : this.height;
601
706
  switch(this.dataType) {
602
707
  case 'string': {
603
708
  return h / this.max();