jmchart 1.1.95 → 1.1.96

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轴,
@@ -85,6 +98,7 @@
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,160 @@
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
+ yLabelFormat: function() {
45
+ return this.field;
46
+ },
47
+ style: {
48
+ markLine: false, // 不展示标线
49
+ chartArea: {
50
+ stroke: 'transparent'
51
+ },
52
+ axis: {
53
+ stroke: '#ccc',
54
+ // 指定栅格条数
55
+ xLabel: {
56
+ count: 3
57
+ }
58
+ },
59
+ grid: {
60
+ x: true, // 是否显示网格
61
+ stroke: '#eaeaf1',
62
+ lineType: 'dotted', // 虚线,不填为实线
63
+ dashLength: 6, //虚线条间隔,默认5
64
+ lineWidth: 1,
65
+ zIndex: 0
66
+ },
67
+ margin: {
68
+ left: 10,
69
+ top: 10,
70
+ right: 80,
71
+ bottom: 10
72
+ }
73
+ }
74
+ });
75
+
76
+ var radar = chart1.createSeries('radar', {
77
+ fields: ['y1' , 'y2', 'y3', 'y4', 'y5', 'y6'],
78
+ legendFormat: function(options) {
79
+ return options.data.x;
80
+ },
81
+ onOver: function(e) {
82
+ console.log(this.option.data)
83
+ e.cancel = true;
84
+ return false;
85
+ },
86
+ itemLabelFormat: function(point) {
87
+ return point.yValue.toFixed(2);
88
+ },
89
+ style: {
90
+ // 指定颜色获取方式,不指定就会使用默认的
91
+ color: function(option) {
92
+ if(!option || !option.data) return;
93
+ const color = option.data.color || this.graph.getColor(option.index);
94
+ return color;
95
+ },
96
+ fill: function(style) {
97
+ if(!style) return '';
98
+ const color = this.graph.utils.hexToRGBA(style.stroke);
99
+ return `rgba(${color.r},${color.g},${color.b}, 0.2)`;
100
+ },
101
+ label: {
102
+ show: true, // 默认就是true, 如果不想显示标签,设为false
103
+ stroke: '#ccc',
104
+ fill: 'green',
105
+ textAlign: 'center',
106
+ textBaseline: 'middle',
107
+ zIndex: -1,
108
+ border: 0
109
+ }
110
+ }
111
+ });
112
+
113
+
114
+ const datacount = 4;
115
+ let data = [
116
+ ];
117
+
118
+ function refreshData() {
119
+
120
+ data = [];
121
+ for(let i=0; i<datacount; i++) {
122
+
123
+ data.push({
124
+ x: 'test' + i,
125
+ y1: 10 * i + Math.random() * 10,
126
+ y2: 10 * i + Math.random() * 50,
127
+ y3: 10 * i + Math.random() * 100,
128
+ y4: 10 * i + Math.random() * 120,
129
+ y5: 10 * i + Math.random() * 120,
130
+ y6: 10 * i + Math.random() * 120
131
+ });
132
+ }
133
+
134
+ chart1.data = data;
135
+ chart1.refresh();
136
+
137
+ }
138
+
139
+
140
+ refreshData();
141
+
142
+ chart1.utils.bindEvent(document.getElementById('btnRedraw'),'click', refreshData);
143
+
144
+ // // 自动刷新代码
145
+ // function update() {
146
+ // if(chart1.needUpdate) chart1.redraw();
147
+ // requestAnimationFrame(update);
148
+ // }
149
+ // requestAnimationFrame(update);
150
+ }
151
+ </script>
152
+ </head>
153
+ <body>
154
+ <div id="mycanvas1">
155
+ </div>
156
+ <div id="mycanvas2">
157
+ </div>
158
+ <button id="btnRedraw">重绘</button>
159
+ </body>
160
+ </html>
@@ -64,7 +64,7 @@
64
64
  //layout: 'inside'
65
65
  },
66
66
  xAxisOption: {
67
- arrowVisible: false
67
+ arrowVisible: true
68
68
  },
69
69
  yAxisOption: {
70
70
  arrowVisible: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jmchart",
3
- "version": "1.1.95",
3
+ "version": "1.1.96",
4
4
  "description": "chart",
5
5
  "main": "./index.js",
6
6
  "directories": {
@@ -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,
@@ -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
+ 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,40 @@ 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
+ const point = {};
157
+ point.x = axis.radarOption.center.x + axis.radarOption.cos * curRadius + bounds.left;
158
+ point.y = axis.radarOption.center.y - axis.radarOption.sin * curRadius + bounds.top;
159
+ points.push(point);
160
+ }
161
+ // 画栅格线
162
+ for(let j=0; j<points.length; j++) {
163
+ const start = points[j];
164
+ const end = points[j+1] || points[0];
165
+ const gridLine = this.graph.createShape('line', {
166
+ start,
167
+ end,
168
+ style: this.style.grid
169
+ });
170
+ this.parent.children.add(gridLine);
171
+ this.gridLines.push(gridLine);
172
+ }
173
+ }
174
+ }
175
+ break;
176
+ }
177
+
124
178
  this.start.x = bounds.left;
125
179
  this.start.y = bounds.bottom;
126
180
  this.end.x = bounds.right;
@@ -137,25 +191,34 @@ export default class jmAxis extends jmArrowLine {
137
191
  }
138
192
  break;
139
193
  }
140
- case 'y' : {
141
- const index = this.index || 1;
142
- let xoffset = bounds.left;
143
-
194
+ case 'y' : {
144
195
  //初始化显示标签个数
145
196
  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;
197
+
198
+ const index = this.index || 1;
199
+ // 如果是雷达图,则画发散的线
200
+ if(this.radarOption) {
201
+ this.end.x = this.radarOption.center.x + this.radarOption.cos * this.radarOption.radius + bounds.left;;
202
+ this.end.y = this.radarOption.center.y - this.radarOption.sin * this.radarOption.radius + bounds.top;
203
+ this.start.x = this.radarOption.center.x + bounds.left;
204
+ this.start.y = this.radarOption.center.y + bounds.top;
205
+ }
206
+ else {
207
+ let xoffset = bounds.left;
208
+
209
+ //多Y轴时,第二个为右边第一轴,其它的依此递推
210
+ if(index == 2) {
211
+ xoffset = bounds.right;
212
+ }
213
+ else if(index > 2) {
214
+ xoffset = this.graph.yAxises[index-1].start.x + this.graph.yAxises[index-1].width + 10;
215
+ }
216
+
217
+ this.start.x = xoffset;
218
+ this.start.y = bounds.bottom;
219
+ this.end.x = this.start.x;
220
+ this.end.y = bounds.top;
221
+ }
159
222
  break;
160
223
  }
161
224
  }
@@ -174,17 +237,18 @@ export default class jmAxis extends jmArrowLine {
174
237
  * @method createLabel
175
238
  */
176
239
  createLabel() {
177
- //移除原有的标签
178
- this.children.each(function(i, c) {
179
- c.remove();
180
- }, true);
181
-
182
- this.labels = [];
240
+ if(this.visible === false) return;
241
+
242
+ // 雷达图的标签单独处理
243
+ if(this.radarOption) {
244
+ return this.createRadarLabel();
245
+ }
246
+
183
247
  //如果是?X轴则执行X轴标签生成
184
248
  if(this.type == 'x') {
185
249
  this.createXLabel();
186
250
  }
187
- else if(this.type == 'y') {
251
+ else if(this.type == 'y') {
188
252
  this.createYLabel();
189
253
  }
190
254
  }
@@ -303,23 +367,19 @@ export default class jmAxis extends jmArrowLine {
303
367
  this.scalePoints = [];// 刻度点集合
304
368
 
305
369
  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);
370
+ const mm = max - min;
371
+ let pervalue = (mm / count) || 1;
313
372
 
314
373
  const format = this.option.format || this.format;
315
374
  const marginLeft = this.style.yLabel.margin.left * this.graph.devicePixelRatio || 0;
316
375
  const marginRight = this.style.yLabel.margin.right * this.graph.devicePixelRatio || 0;
317
376
  let p = 0;
377
+
318
378
  for(let i=0; i<count+1; i++) {
319
379
  p = min + pervalue * i;
320
380
  if(p > max || i === count) p = max;
321
381
  const h = (p - min) * step; // 当前点的偏移高度
322
- const label = this.graph.graph.createShape('label', {
382
+ const label = this.graph.createShape('label', {
323
383
  style: this.style.yLabel
324
384
  });
325
385
 
@@ -357,7 +417,7 @@ export default class jmAxis extends jmArrowLine {
357
417
  });
358
418
 
359
419
  // 指定要显示网格
360
- if(this.style.grid && this.style.grid.x) {
420
+ if(!this.radarOption && this.style.grid && this.style.grid.x) {
361
421
  // 它的坐标是相对于轴的,所以Y轴会用负的区域高度
362
422
  const line = this.graph.createShape('line', {
363
423
  start: {
@@ -423,6 +483,38 @@ export default class jmAxis extends jmArrowLine {
423
483
  }
424
484
  }
425
485
 
486
+ /**
487
+ * 生成雷达图的Y轴标签
488
+ */
489
+ createRadarLabel() {
490
+ const format = this.option.format;
491
+ const bounds = this.graph.chartArea.getBounds();// 获取画图区域
492
+ const self = this;
493
+ const label = this.graph.createShape('label', {
494
+ style: this.style.yLabel,
495
+ position: function() {
496
+ // 因为axis是相对于chart的,而center是相对于chartArea的,所以要计算axis位置相对于chartArea来比较
497
+ const pos = {
498
+ x: self.end.x - bounds.left,
499
+ y: self.end.y - bounds.top
500
+ };
501
+ const size = this.testSize();
502
+ if(pos.x < self.radarOption.center.x) {
503
+ pos.x -= size.width;
504
+ }
505
+
506
+ if(pos.y < self.radarOption.center.y) {
507
+ pos.y -= size.height;
508
+ }
509
+ return pos;
510
+ }
511
+ });
512
+
513
+ label.text = typeof format === 'function'? format.call(this, label): this.field; // 格式化label
514
+ this.labels.push(label);
515
+ this.graph.chartArea.children.add(label);
516
+ }
517
+
426
518
  /**
427
519
  * 获取当前轴所占宽
428
520
  *
@@ -569,6 +661,18 @@ export default class jmAxis extends jmArrowLine {
569
661
  clear() {
570
662
  this._min = null;
571
663
  this._max = null;
664
+ this.children.each((i, c) => {
665
+ c.remove();
666
+ }, true);
667
+ // 清空栅格线
668
+ this.gridLines && this.gridLines.forEach((line)=>{
669
+ line.remove();
670
+ });
671
+ this.labels && this.labels.forEach((label)=>{
672
+ label.remove();
673
+ });
674
+ this.labels = [];
675
+ this.gridLines = [];
572
676
  }
573
677
 
574
678
  /**
@@ -579,7 +683,7 @@ export default class jmAxis extends jmArrowLine {
579
683
  */
580
684
  step() {
581
685
  if(this.type == 'x') {
582
- const w = this.width;
686
+ const w = this.radarOption? this.radarOption.radius : this.width;
583
687
 
584
688
  //如果排版为内联,则单位占宽减少一个单位,
585
689
  //也就是起始位从一个单位开始
@@ -597,7 +701,7 @@ export default class jmAxis extends jmArrowLine {
597
701
 
598
702
  }
599
703
  else if(this.type == 'y') {
600
- const h = this.height;
704
+ const h = this.radarOption? this.radarOption.radius : this.height;
601
705
  switch(this.dataType) {
602
706
  case 'string': {
603
707
  return h / this.max();
package/src/jmChart.js CHANGED
@@ -10,7 +10,7 @@ import jmLegend from './core/legend/legend.js';
10
10
  import jmBarSeries from './series/barSeries.js';
11
11
  import jmStackBarSeries from './series/stackBarSeries.js';
12
12
  import jmPieSeries from './series/pieSeries.js';
13
-
13
+ import jmRadarSeries from './series/radarSeries.js';
14
14
  import jmLineSeries from './series/lineSeries.js';
15
15
  import jmStackLineSeries from './series/stackLineSeries.js';
16
16
  import jmCandlestickSeries from './series/candlestickSeries.js';
@@ -333,7 +333,7 @@ export default class jmChart extends jmGraph {
333
333
  type: 'x',
334
334
  visible: this.style.axis.x === false? false: true,
335
335
  format: this.option.xLabelFormat,
336
- ...this.option.yAxisOption
336
+ ...this.option.xAxisOption
337
337
  }, options || {});
338
338
 
339
339
  if(typeof this.option.minXValue !== 'undefined') {
@@ -366,7 +366,7 @@ export default class jmChart extends jmGraph {
366
366
  visible: this.style.axis.y === false? false: true,
367
367
  format: this.option.yLabelFormat,
368
368
  zeroBase: this.baseY === 0,
369
- ...this.option.xAxisOption,
369
+ ...this.option.yAxisOption,
370
370
  }, options || {});
371
371
  if(typeof this.option.minYValue !== 'undefined') {
372
372
  options.minYValue = typeof options.minYValue === 'undefined'?this.option.minYValue:Math.min(this.option.minYValue, options.minYValue);
@@ -395,6 +395,7 @@ export default class jmChart extends jmGraph {
395
395
  'bar' : jmBarSeries,
396
396
  'stackBar' : jmStackBarSeries,
397
397
  'pie' : jmPieSeries,
398
+ 'radar' : jmRadarSeries,
398
399
  'stackLine' : jmStackLineSeries,
399
400
  'candlestick': jmCandlestickSeries
400
401
  };