jmchart 1.2.10 → 1.2.11

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/src/jmChart.js CHANGED
@@ -1,428 +1,428 @@
1
-
2
- import {
3
- jmGraph,
4
- jmUtils,
5
- jmList
6
- } from 'jmgraph';
7
- import defaultStyle from './common/style.js';
8
- import jmAxis from './core/axis/axis.js';
9
- import jmLegend from './core/legend/legend.js';
10
- import jmBarSeries from './series/barSeries.js';
11
- import jmStackBarSeries from './series/stackBarSeries.js';
12
- import jmPieSeries from './series/pieSeries.js';
13
- import jmRadarSeries from './series/radarSeries.js';
14
- import jmLineSeries from './series/lineSeries.js';
15
- import jmStackLineSeries from './series/stackLineSeries.js';
16
- import jmCandlestickSeries from './series/candlestickSeries.js';
17
- import jmMarkLineManager from './core/markLine/manager';
18
-
19
- /**
20
- * jm图表组件
21
- * option参数:graph=jmgraph
22
- *
23
- * @class jmChart
24
- * @module jmChart
25
- * @param {element} container 图表容器
26
- */
27
- export default class jmChart extends jmGraph {
28
-
29
- constructor(container, options) {
30
- options = options||{};
31
-
32
- const enableAnimate = !!options.enableAnimate;
33
- options.autoRefresh = typeof options.autoRefresh === 'undefined'? enableAnimate: options.autoRefresh;
34
-
35
- if(enableAnimate && !options.autoRefresh) {
36
- console.warn('开启了动画,却没有开户自动刷新');
37
- }
38
-
39
- // 深度复制默认样式,以免被改
40
- options.style = jmUtils.clone(defaultStyle, options.style, true);
41
-
42
- super(container, options);
43
-
44
- this.enableAnimate = enableAnimate;
45
- this.data = options.data || [];
46
- // x轴绑定的字段名
47
- this.xField = options.xField || '';
48
-
49
- this.init(options);
50
-
51
- // 创建操作图层
52
- this.createTouchGraph(this.container, options);
53
- }
54
-
55
- /**
56
- * 绑定的数据源
57
- */
58
- data = [];
59
-
60
- /**
61
- * 当前所有图
62
- */
63
- series = new jmList();
64
-
65
- /**
66
- * 是否启用动画
67
- */
68
- get enableAnimate() {
69
- if(typeof this.option.enableAnimate !== 'undefined') return !!this.option.enableAnimate;
70
- else {
71
- return false;
72
- }
73
- }
74
- set enableAnimate(v) {
75
- this.option.enableAnimate = v;
76
- }
77
-
78
- /**
79
- * Y轴的基线 默认是0
80
- */
81
- get baseY() {
82
- return this.option.baseY;
83
- }
84
- set baseY(v) {
85
- this.option.baseY = v;
86
- }
87
-
88
- // 初始化图表
89
- init(options) {
90
-
91
- /**
92
- * 绘图区域
93
- *
94
- * @property chartArea
95
- * @type jmControl
96
- */
97
- if(!this.chartArea) {
98
- this.chartArea = this.createShape('rect', {
99
- style: this.style.chartArea,
100
- position: { x: 0, y: 0}
101
- });
102
- this.children.add(this.chartArea);
103
- }
104
-
105
- /**
106
- * 图例
107
- *
108
- * @property legend
109
- * @type jmLegend
110
- */
111
- this.legend = this.legend || this.createShape(jmLegend, {
112
- style: this.style.legend
113
- });
114
- this.children.add(this.legend);
115
- // 不显示图例
116
- if(options.legendVisible === false) {
117
- this.legend.visible = false;
118
- }
119
-
120
- /**
121
- * 图表提示控件
122
- *
123
- * @property tooltip
124
- * @type jmTooltip
125
- */
126
- //this.tooltip = this.graph.createShape('tooltip',{style:this.style.tooltip});
127
- //this.chartArea.children.add(this.tooltip);
128
-
129
- this.createXAxis();// 生成X轴
130
- }
131
-
132
- // 创建一个操作层,以免每次刷新
133
- createTouchGraph(container, options) {
134
- if(container && container.tagName === 'CANVAS') {
135
- container = container.parentElement;
136
- }
137
- container && container.style && (container.style.position = 'relative');
138
- // 要先从选项中取出canvas,否则clone过滤掉
139
- let cn = options.touchCanvas;
140
-
141
- // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
142
- // isWXMiniApp 非微信小程序下才能创建
143
- if(container && (options.touchGraph || cn)) {
144
- if(!cn && !this.isWXMiniApp) {
145
- cn = document.createElement('canvas');
146
- cn.width = container.offsetWidth||container.clientWidth;
147
- cn.height = container.offsetHeight||container.clientHeight;
148
- cn.style.position = 'absolute';
149
- cn.style.top = 0;
150
- cn.style.left = 0;
151
- container.appendChild(cn);
152
- }
153
- if(cn) {
154
- options = this.utils.clone(options, {
155
- autoRefresh: true
156
- }, true);
157
-
158
- this.touchGraph = new jmGraph(cn, options);
159
- this.touchGraph.chartGraph = this;
160
-
161
- this.on('propertyChange', (name, args) => {
162
- if(['width', 'height'].includes(name)) {
163
- this.touchGraph[name] = args.newValue;
164
- }
165
- });
166
- // 把上层canvse事件传递给绘图层对象
167
- this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', (args) => {
168
- const eventName = args.event.eventName || args.event.type;
169
- if(eventName) {
170
- this.emit(eventName, args);
171
- args.event.stopPropagation && args.event.stopPropagation();
172
- }
173
- });
174
- }
175
- }
176
- // 初始化标线
177
- this.markLine = new jmMarkLineManager(this);
178
- }
179
-
180
- // 重置整个图表
181
- reset() {
182
- // 清空当前图形,重新生成
183
- let serie;
184
- while(serie = this.series.shift()) {
185
-
186
- // 重置所有图形
187
- let shape;
188
- while(shape = serie.shapes.shift()) {
189
- shape && shape.remove();
190
- }
191
-
192
- serie.remove();
193
- }
194
-
195
- // 轴删除
196
- if(this.xAxis) {
197
- this.xAxis.remove();
198
- delete this.xAxis;
199
- }
200
- if(this.yAxises) {
201
- for(let i in this.yAxises) {
202
- this.yAxises[i].remove();
203
- }
204
- delete this.yAxises;
205
- }
206
- }
207
- /**
208
- * 获取颜色
209
- *
210
- * @method getColor
211
- * @param {int} index 颜色索引
212
- */
213
- getColor(index) {
214
- //如果颜色超过最大个数,则重新获取
215
- if(index >= this.style.chartColors.length) {
216
- index = Math.floor((index - 1) / this.style.chartColors.length)
217
- }
218
- return this.style.chartColors[index];
219
- }
220
-
221
- /**
222
- * 绘制当前图表
223
- * 先绘制轴等基础信息
224
- *
225
- * @method beginDraw
226
- */
227
- beginDraw() {
228
- //const startTime = Date.now();
229
- //重置图例
230
- this.legend && this.legend.init();
231
-
232
- //先定位图例等信息,确定画图区域
233
- this.resetAreaPosition();
234
-
235
- if(this.xAxis) {
236
- this.xAxis.clear();
237
- }
238
-
239
- //计算Y轴位置
240
- if(this.yAxises) {
241
- for(let i in this.yAxises) {
242
- this.yAxises[i].clear();
243
- }
244
- }
245
-
246
- //console.log('beginDraw1', Date.now() - startTime);
247
-
248
- //计算柱形图个数
249
- this.barSeriesCount = 0;
250
- //初始化图序列,并初始化轴值,生成图例项
251
- this.series.each(function(i, serie) {
252
- //设定边框颜色和数据项图示颜 色
253
- if(!serie.style.color) serie.style.color = serie.graph.getColor(i);
254
- //如果排版指定非内缩的方式,但出现了柱图,还是会采用内缩一个刻度的方式
255
- if(serie.graph.style.layout != 'inside') {
256
- if(serie instanceof jmBarSeries) {
257
- serie.graph.style.layout = 'inside';
258
- }
259
- }
260
-
261
- //对柱图计算,并标记为第几个柱图,用为排列
262
- if(serie instanceof jmBarSeries) {
263
- serie.barIndex = serie.graph.barSeriesCount;
264
- serie.graph.barSeriesCount ++;
265
- }
266
- serie.reset();
267
- });
268
- //console.log('beginDraw2', Date.now() - startTime);
269
- //重置图例
270
- this.legend && this.legend.reset();
271
-
272
- //计算Y轴位置
273
- if(this.yAxises) {
274
- for(var i in this.yAxises) {
275
- this.yAxises[i].reset();
276
- }
277
- }
278
- // y 处理完才能处理x
279
- if(this.xAxis) {
280
- this.xAxis.reset();
281
- }
282
-
283
- //console.log('beginDraw3', Date.now() - startTime);
284
- //最后再来初始化图形,这个必须在轴初始化完后才能执行
285
- this.series.each(function(i, serie) {
286
- serie.init && serie.init();
287
- });
288
- //console.log('beginDraw4', Date.now() - startTime);
289
- }
290
-
291
- /**
292
- * 重新定位区域的位置
293
- *
294
- * @method resetAreaPosition
295
- */
296
- resetAreaPosition() {
297
- this.chartArea.position.x = (this.style.margin.left || 0);
298
- this.chartArea.position.y = (this.style.margin.top || 0);
299
- const w = this.width - this.style.margin.right - this.chartArea.position.x;
300
- const h = this.height - this.style.margin.bottom - this.chartArea.position.y;
301
-
302
- this.chartArea.width = w;
303
- this.chartArea.height = h;
304
- }
305
-
306
- /**
307
- * 创建轴
308
- *
309
- * @method createAxis
310
- * @for jmChart
311
- * @param {string} [type] 轴类型(x/y/radar),默认为x
312
- * @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
313
- * @param {object} [style] 样式
314
- * @return {axis} 轴
315
- */
316
- createAxis(options) {
317
- // 深度组件默认样式
318
- options.style = options.style? this.utils.clone(this.style.axis, options.style, true) : this.style.axis;
319
-
320
- const axis = this.createShape(jmAxis, options);
321
- if(typeof options.visible !== 'undefined') axis.visible = options.visible;
322
- this.children.add(axis);
323
- return axis;
324
- }
325
-
326
- /**
327
- * 生成X轴
328
- *
329
- * @method createXAxis
330
- * @param {string} x轴的数据类型(string/number/date)
331
- * @param {bool} 是否从0开始
332
- */
333
- createXAxis(options) {
334
- if(!this.xAxis) {
335
- options = Object.assign({
336
- field: this.xField,
337
- type: 'x',
338
- visible: this.style.axis.x === false? false: true,
339
- format: this.option.xLabelFormat,
340
- ...this.option.xAxisOption
341
- }, options || {});
342
-
343
- if(typeof this.option.minXValue !== 'undefined') {
344
- options.minXValue = typeof options.minXValue === 'undefined'?this.option.minXValue:Math.min(this.option.minXValue, options.minXValue);
345
- }
346
- if(typeof this.option.maxXValue !== 'undefined') {
347
- options.maxXValue = typeof options.maxXValue === 'undefined'?this.option.maxXValue:Math.max(this.option.maxXValue, options.maxXValue);
348
- }
349
- this.xAxis = this.createAxis(options);
350
- }
351
- return this.xAxis;
352
- }
353
-
354
- /**
355
- * 生成Y轴
356
- *
357
- * @method createYAxis
358
- * @param {int} Y轴索引,可以创建多个Y轴
359
- * @param {string} y轴的数据类型(string/number/date)
360
- * @param {bool} 是否从0开始
361
- */
362
- createYAxis(options) {
363
-
364
- if(!this.yAxises) {
365
- this.yAxises = {};
366
- }
367
- options = Object.assign({
368
- index: 1,
369
- type: 'y',
370
- visible: this.style.axis.y === false? false: true,
371
- format: this.option.yLabelFormat,
372
- zeroBase: this.baseY === 0,
373
- ...this.option.yAxisOption,
374
- }, options || {});
375
- if(typeof this.option.minYValue !== 'undefined') {
376
- options.minYValue = typeof options.minYValue === 'undefined'?this.option.minYValue:Math.min(this.option.minYValue, options.minYValue);
377
- }
378
- if(typeof this.option.maxYValue !== 'undefined') {
379
- options.maxYValue = typeof options.maxYValue === 'undefined'?this.option.maxYValue:Math.max(this.option.maxYValue, options.maxYValue);
380
- }
381
-
382
- var yaxis = this.yAxises[options.index] || (this.yAxises[options.index] = this.createAxis(options));
383
- return yaxis;
384
- }
385
-
386
- /**
387
- * 创建图形
388
- *
389
- * @method createSeries
390
- * @for jmChart
391
- * @param {string} [type] 图类型,(line/bar/pie/radar)
392
- * @param {object} [options] 生成图表选项 {xField, yField, index}
393
- * @return {series} 图形
394
- */
395
- createSeries(type, options = {}) {
396
- if(!this.serieTypes) {
397
- this.serieTypes = {
398
- 'line' : jmLineSeries,
399
- 'bar' : jmBarSeries,
400
- 'stackBar' : jmStackBarSeries,
401
- 'pie' : jmPieSeries,
402
- 'radar' : jmRadarSeries,
403
- 'stackLine' : jmStackLineSeries,
404
- 'candlestick': jmCandlestickSeries
405
- };
406
- }
407
-
408
- //默认样式为类型对应的样式
409
- const style = this.style[type] || this.style['line'];
410
- // 深度组件默认样式
411
- options.style = this.utils.clone(style, options.style, true);
412
-
413
- if(typeof type == 'string') type = this.serieTypes[type];
414
-
415
- const serie = this.createShape(type, options);
416
- if(serie) {
417
- this.series.add(serie);
418
- this.chartArea.children.add(serie);
419
- }
420
- return serie;
421
- }
422
-
423
- // 销毁
424
- destroy() {
425
- super.destroy();
426
- this.touchGraph && this.touchGraph.destroy();
427
- }
1
+
2
+ import {
3
+ jmGraph,
4
+ jmUtils,
5
+ jmList
6
+ } from 'jmgraph';
7
+ import defaultStyle from './common/style.js';
8
+ import jmAxis from './core/axis/axis.js';
9
+ import jmLegend from './core/legend/legend.js';
10
+ import jmBarSeries from './series/barSeries.js';
11
+ import jmStackBarSeries from './series/stackBarSeries.js';
12
+ import jmPieSeries from './series/pieSeries.js';
13
+ import jmRadarSeries from './series/radarSeries.js';
14
+ import jmLineSeries from './series/lineSeries.js';
15
+ import jmStackLineSeries from './series/stackLineSeries.js';
16
+ import jmCandlestickSeries from './series/candlestickSeries.js';
17
+ import jmMarkLineManager from './core/markLine/manager';
18
+
19
+ const ANIMATION_DATA_THRESHOLD = 100;
20
+ const DEFAULT_ANIMATION_COUNT = 10;
21
+
22
+ /**
23
+ * jm图表组件
24
+ * option参数:graph=jmgraph
25
+ *
26
+ * @class jmChart
27
+ * @module jmChart
28
+ * @param {element} container 图表容器
29
+ */
30
+ export default class jmChart extends jmGraph {
31
+
32
+ constructor(container, options) {
33
+ options = options || {};
34
+
35
+ const enableAnimate = !!options.enableAnimate;
36
+ options.autoRefresh = typeof options.autoRefresh === 'undefined' ? enableAnimate : options.autoRefresh;
37
+
38
+ if(enableAnimate && !options.autoRefresh) {
39
+ console.warn('开启了动画,却没有开户自动刷新');
40
+ }
41
+
42
+ options.style = jmUtils.clone(defaultStyle, options.style, true);
43
+
44
+ super(container, options);
45
+
46
+ this.enableAnimate = enableAnimate;
47
+ this.data = options.data || [];
48
+ this.xField = options.xField || '';
49
+ this._cache = new Map();
50
+
51
+ this.init(options);
52
+ this.createTouchGraph(this.container, options);
53
+ }
54
+
55
+ /**
56
+ * 绑定的数据源
57
+ */
58
+ data = [];
59
+
60
+ /**
61
+ * 当前所有图
62
+ */
63
+ series = new jmList();
64
+
65
+ /**
66
+ * 是否启用动画
67
+ */
68
+ get enableAnimate() {
69
+ if(typeof this.option.enableAnimate !== 'undefined') return !!this.option.enableAnimate;
70
+ else {
71
+ return false;
72
+ }
73
+ }
74
+ set enableAnimate(v) {
75
+ this.option.enableAnimate = v;
76
+ }
77
+
78
+ /**
79
+ * Y轴的基线 默认是0
80
+ */
81
+ get baseY() {
82
+ return this.option.baseY;
83
+ }
84
+ set baseY(v) {
85
+ this.option.baseY = v;
86
+ }
87
+
88
+ // 初始化图表
89
+ init(options) {
90
+
91
+ /**
92
+ * 绘图区域
93
+ *
94
+ * @property chartArea
95
+ * @type jmControl
96
+ */
97
+ if(!this.chartArea) {
98
+ this.chartArea = this.createShape('rect', {
99
+ style: this.style.chartArea,
100
+ position: { x: 0, y: 0}
101
+ });
102
+ this.children.add(this.chartArea);
103
+ }
104
+
105
+ /**
106
+ * 图例
107
+ *
108
+ * @property legend
109
+ * @type jmLegend
110
+ */
111
+ this.legend = this.legend || this.createShape(jmLegend, {
112
+ style: this.style.legend
113
+ });
114
+ this.children.add(this.legend);
115
+ // 不显示图例
116
+ if(options.legendVisible === false) {
117
+ this.legend.visible = false;
118
+ }
119
+
120
+ /**
121
+ * 图表提示控件
122
+ *
123
+ * @property tooltip
124
+ * @type jmTooltip
125
+ */
126
+ //this.tooltip = this.graph.createShape('tooltip',{style:this.style.tooltip});
127
+ //this.chartArea.children.add(this.tooltip);
128
+
129
+ this.createXAxis();// 生成X轴
130
+ }
131
+
132
+ // 创建一个操作层,以免每次刷新
133
+ createTouchGraph(container, options) {
134
+ if(container && container.tagName === 'CANVAS') {
135
+ container = container.parentElement;
136
+ }
137
+ container && container.style && (container.style.position = 'relative');
138
+ // 要先从选项中取出canvas,否则clone过滤掉
139
+ let cn = options.touchCanvas;
140
+
141
+ // 生成图层, 当图刷新慢时,需要用一个操作图层来进行滑动等操作重绘
142
+ // isWXMiniApp 非微信小程序下才能创建
143
+ if(container && (options.touchGraph || cn)) {
144
+ if(!cn && !this.isWXMiniApp) {
145
+ cn = document.createElement('canvas');
146
+ cn.width = container.offsetWidth||container.clientWidth;
147
+ cn.height = container.offsetHeight||container.clientHeight;
148
+ cn.style.position = 'absolute';
149
+ cn.style.top = 0;
150
+ cn.style.left = 0;
151
+ container.appendChild(cn);
152
+ }
153
+ if(cn) {
154
+ options = this.utils.clone(options, {
155
+ autoRefresh: true
156
+ }, true);
157
+
158
+ this.touchGraph = new jmGraph(cn, options);
159
+ this.touchGraph.chartGraph = this;
160
+
161
+ this.on('propertyChange', (name, args) => {
162
+ if(['width', 'height'].includes(name)) {
163
+ this.touchGraph[name] = args.newValue;
164
+ }
165
+ });
166
+ // 把上层canvse事件传递给绘图层对象
167
+ this.touchGraph.on('mousedown touchstart mousemove touchmove mouseup touchend touchcancel touchleave', (args) => {
168
+ const eventName = args.event.eventName || args.event.type;
169
+ if(eventName) {
170
+ this.emit(eventName, args);
171
+ args.event.stopPropagation && args.event.stopPropagation();
172
+ }
173
+ });
174
+ }
175
+ }
176
+ // 初始化标线
177
+ this.markLine = new jmMarkLineManager(this);
178
+ }
179
+
180
+ // 重置整个图表
181
+ reset() {
182
+ // 清空当前图形,重新生成
183
+ let serie;
184
+ while(serie = this.series.shift()) {
185
+
186
+ // 重置所有图形
187
+ let shape;
188
+ while(shape = serie.shapes.shift()) {
189
+ shape && shape.remove();
190
+ }
191
+
192
+ serie.remove();
193
+ }
194
+
195
+ // 轴删除
196
+ if(this.xAxis) {
197
+ this.xAxis.remove();
198
+ delete this.xAxis;
199
+ }
200
+ if(this.yAxises) {
201
+ for(let i in this.yAxises) {
202
+ this.yAxises[i].remove();
203
+ }
204
+ delete this.yAxises;
205
+ }
206
+ }
207
+ /**
208
+ * 获取颜色,使用缓存优化性能
209
+ *
210
+ * @method getColor
211
+ * @param {int} index 颜色索引
212
+ */
213
+ getColor(index) {
214
+ const cacheKey = `color_${index}`;
215
+ if(this._cache.has(cacheKey)) {
216
+ return this._cache.get(cacheKey);
217
+ }
218
+
219
+ let color;
220
+ if(index >= this.style.chartColors.length) {
221
+ color = this.style.chartColors[index % this.style.chartColors.length];
222
+ } else {
223
+ color = this.style.chartColors[index];
224
+ }
225
+
226
+ this._cache.set(cacheKey, color);
227
+ return color;
228
+ }
229
+
230
+ /**
231
+ * 绘制当前图表
232
+ * 先绘制轴等基础信息
233
+ *
234
+ * @method beginDraw
235
+ */
236
+ beginDraw() {
237
+ if(this.legend) {
238
+ this.legend.init();
239
+ }
240
+
241
+ this.resetAreaPosition();
242
+
243
+ if(this.xAxis) {
244
+ this.xAxis.clear();
245
+ }
246
+
247
+ if(this.yAxises) {
248
+ for(let i in this.yAxises) {
249
+ this.yAxises[i].clear();
250
+ }
251
+ }
252
+
253
+ this.barSeriesCount = 0;
254
+ this.series.each((i, serie) => {
255
+ if(!serie.style.color) {
256
+ serie.style.color = serie.graph.getColor(i);
257
+ }
258
+
259
+ if(serie.graph.style.layout != 'inside') {
260
+ if(serie instanceof jmBarSeries) {
261
+ serie.graph.style.layout = 'inside';
262
+ }
263
+ }
264
+
265
+ if(serie instanceof jmBarSeries) {
266
+ serie.barIndex = serie.graph.barSeriesCount;
267
+ serie.graph.barSeriesCount++;
268
+ }
269
+ serie.reset();
270
+ });
271
+
272
+ if(this.legend) {
273
+ this.legend.reset();
274
+ }
275
+
276
+ if(this.yAxises) {
277
+ for(let i in this.yAxises) {
278
+ this.yAxises[i].reset();
279
+ }
280
+ }
281
+
282
+ if(this.xAxis) {
283
+ this.xAxis.reset();
284
+ }
285
+
286
+ this.series.each((i, serie) => {
287
+ serie.init && serie.init();
288
+ });
289
+ }
290
+
291
+ /**
292
+ * 重新定位区域的位置
293
+ *
294
+ * @method resetAreaPosition
295
+ */
296
+ resetAreaPosition() {
297
+ this.chartArea.position.x = (this.style.margin.left || 0);
298
+ this.chartArea.position.y = (this.style.margin.top || 0);
299
+ const w = this.width - this.style.margin.right - this.chartArea.position.x;
300
+ const h = this.height - this.style.margin.bottom - this.chartArea.position.y;
301
+
302
+ this.chartArea.width = w;
303
+ this.chartArea.height = h;
304
+ }
305
+
306
+ /**
307
+ * 创建轴
308
+ *
309
+ * @method createAxis
310
+ * @for jmChart
311
+ * @param {string} [type] 轴类型(x/y/radar),默认为x
312
+ * @param {string} [dataType] 当前轴的数据类型(number/date/string),默认为 number
313
+ * @param {object} [style] 样式
314
+ * @return {axis} 轴
315
+ */
316
+ createAxis(options) {
317
+ // 深度组件默认样式
318
+ options.style = options.style? this.utils.clone(this.style.axis, options.style, true) : this.style.axis;
319
+
320
+ const axis = this.createShape(jmAxis, options);
321
+ if(typeof options.visible !== 'undefined') axis.visible = options.visible;
322
+ this.children.add(axis);
323
+ return axis;
324
+ }
325
+
326
+ /**
327
+ * 生成X轴
328
+ *
329
+ * @method createXAxis
330
+ * @param {string} x轴的数据类型(string/number/date)
331
+ * @param {bool} 是否从0开始
332
+ */
333
+ createXAxis(options) {
334
+ if(!this.xAxis) {
335
+ options = Object.assign({
336
+ field: this.xField,
337
+ type: 'x',
338
+ visible: this.style.axis.x === false? false: true,
339
+ format: this.option.xLabelFormat,
340
+ ...this.option.xAxisOption
341
+ }, options || {});
342
+
343
+ if(typeof this.option.minXValue !== 'undefined') {
344
+ options.minXValue = typeof options.minXValue === 'undefined'?this.option.minXValue:Math.min(this.option.minXValue, options.minXValue);
345
+ }
346
+ if(typeof this.option.maxXValue !== 'undefined') {
347
+ options.maxXValue = typeof options.maxXValue === 'undefined'?this.option.maxXValue:Math.max(this.option.maxXValue, options.maxXValue);
348
+ }
349
+ this.xAxis = this.createAxis(options);
350
+ }
351
+ return this.xAxis;
352
+ }
353
+
354
+ /**
355
+ * 生成Y轴
356
+ *
357
+ * @method createYAxis
358
+ * @param {int} Y轴索引,可以创建多个Y轴
359
+ * @param {string} y轴的数据类型(string/number/date)
360
+ * @param {bool} 是否从0开始
361
+ */
362
+ createYAxis(options) {
363
+
364
+ if(!this.yAxises) {
365
+ this.yAxises = {};
366
+ }
367
+ options = Object.assign({
368
+ index: 1,
369
+ type: 'y',
370
+ visible: this.style.axis.y === false? false: true,
371
+ format: this.option.yLabelFormat,
372
+ zeroBase: this.baseY === 0,
373
+ ...this.option.yAxisOption,
374
+ }, options || {});
375
+ if(typeof this.option.minYValue !== 'undefined') {
376
+ options.minYValue = typeof options.minYValue === 'undefined'?this.option.minYValue:Math.min(this.option.minYValue, options.minYValue);
377
+ }
378
+ if(typeof this.option.maxYValue !== 'undefined') {
379
+ options.maxYValue = typeof options.maxYValue === 'undefined'?this.option.maxYValue:Math.max(this.option.maxYValue, options.maxYValue);
380
+ }
381
+
382
+ var yaxis = this.yAxises[options.index] || (this.yAxises[options.index] = this.createAxis(options));
383
+ return yaxis;
384
+ }
385
+
386
+ /**
387
+ * 创建图形
388
+ *
389
+ * @method createSeries
390
+ * @for jmChart
391
+ * @param {string} [type] 图类型,(line/bar/pie/radar)
392
+ * @param {object} [options] 生成图表选项 {xField, yField, index}
393
+ * @return {series} 图形
394
+ */
395
+ createSeries(type, options = {}) {
396
+ if(!this.serieTypes) {
397
+ this.serieTypes = {
398
+ 'line' : jmLineSeries,
399
+ 'bar' : jmBarSeries,
400
+ 'stackBar' : jmStackBarSeries,
401
+ 'pie' : jmPieSeries,
402
+ 'radar' : jmRadarSeries,
403
+ 'stackLine' : jmStackLineSeries,
404
+ 'candlestick': jmCandlestickSeries
405
+ };
406
+ }
407
+
408
+ //默认样式为类型对应的样式
409
+ const style = this.style[type] || this.style['line'];
410
+ // 深度组件默认样式
411
+ options.style = this.utils.clone(style, options.style, true);
412
+
413
+ if(typeof type == 'string') type = this.serieTypes[type];
414
+
415
+ const serie = this.createShape(type, options);
416
+ if(serie) {
417
+ this.series.add(serie);
418
+ this.chartArea.children.add(serie);
419
+ }
420
+ return serie;
421
+ }
422
+
423
+ // 销毁
424
+ destroy() {
425
+ super.destroy();
426
+ this.touchGraph && this.touchGraph.destroy();
427
+ }
428
428
  }