// 引入 ECharts 主模块
|
import ECharts from "echarts/lib/echarts"
|
|
function ChartManage() {
|
this.charts = {};
|
this.group = '';
|
}
|
/**
|
* [setChart description]
|
*
|
* @param {String} id chart对象的id
|
* @param {Echarts} chart echarts对象
|
*/
|
ChartManage.prototype.set = function (id, chart) {
|
// 将id和chart绑定
|
this.charts[id] = chart;
|
};
|
|
ChartManage.prototype.get = function (id) {
|
return this.charts[id] ? this.charts[id] : -1;
|
};
|
|
ChartManage.prototype.del = function (id) {
|
let chart = this.get(id);
|
if (chart != -1) {
|
// 销毁echarts
|
chart.dispose();
|
delete this.charts[id];
|
}
|
};
|
|
ChartManage.prototype.resize = function (id) {
|
let chart = this.get(id);
|
if (chart != -1) {
|
chart.resize();
|
}
|
};
|
|
ChartManage.prototype.connect = function (ids) {
|
let self = this;
|
let groups = ids.map(function (id) {
|
let chart = self.get(id);
|
if (chart != -1) {
|
return chart;
|
}
|
});
|
|
// 清空分组
|
this.disconnect();
|
this.group = ECharts.connect(groups);
|
|
}
|
|
ChartManage.prototype.disconnect = function () {
|
ECharts.disconnect(this.group);
|
// 清除分组信息
|
Object.keys(this.charts).forEach(id => {
|
delete this.charts[id].group;
|
});
|
}
|
|
|
ChartManage.prototype.changeDataZoom = function (id, range) {
|
let chart = this.get(id);
|
if (chart != -1) {
|
chart.dispatchAction({
|
type: 'dataZoom',
|
batch: [
|
{
|
// 第一个 dataZoom 组件
|
start: range[0],
|
end: range[1],
|
}
|
]
|
});
|
}
|
}
|
|
export default new ChartManage();
|