New file |
| | |
| | | function ChartManage() { |
| | | |
| | | } |
| | | /** |
| | | * [setChart description] |
| | | * |
| | | * @param {String} id chart对象的id |
| | | * @param {Echarts} chart echarts对象 |
| | | */ |
| | | ChartManage.prototype.set = function(id, chart) { |
| | | // 检测window下是否有$$chartManage |
| | | if(window.chartManage) { |
| | | window.chartManage = {}; |
| | | } |
| | | console.log(window); |
| | | window.$$chartManage[id] = chart; |
| | | }; |
| | | |
| | | ChartManage.prototype.get = function(id) { |
| | | if(window.$$chartManage && window.$$chartManage[id]) { |
| | | return window.$$chartManage[id]; |
| | | } |
| | | |
| | | return -1; |
| | | }; |
| | | |
| | | ChartManage.prototype.del = function(id) { |
| | | if(window.$$chartManage && window.$$chartManage[id]) { |
| | | let chart = window.$$chartManage[id]; |
| | | // 销毁echarts |
| | | chart.dispose(); |
| | | delete window.$$chartManage[id]; |
| | | } |
| | | }; |
| | | |
| | | export default ChartManage; |
| | |
| | | import getMaxFromArr from './getMaxFromArr' // 最大值 |
| | | import hex_md5 from './hex_md5' |
| | | import isSetOption from './isSetOption' |
| | | import ChartManage from './ChartManage' |
| | | |
| | | export { |
| | | Timeout, |
| | |
| | | getMaxFromArr, |
| | | hex_md5, |
| | | isSetOption, |
| | | ChartManage, |
| | | } |
| | |
| | | import "./theme/transparent" |
| | | |
| | | import { |
| | | getMaxFromArr |
| | | getMaxFromArr, |
| | | } from '../../assets/js/common.js' |
| | | |
| | | |
| | | export default { |
| | | props: { |
| | |
| | | option.title.subtext=""; |
| | | } |
| | | // 绘制图表 |
| | | this.chart.setOption(option); |
| | | this.$G.chartManage.get(this.id).setOption(option); |
| | | }, |
| | | changeFullState: function() { |
| | | this.isFull = this.isFull?false:true; |
| | | this.$nextTick(()=>{ |
| | | this.chart.resize(); |
| | | this.$G.chartManage.get(this.id).resize(); |
| | | }); |
| | | }, |
| | | mouseEnter() { |
| | |
| | | return false; |
| | | } |
| | | // 绘制图表 |
| | | this.chart.setOption({ |
| | | this.$G.chartManage.get(this.id).setOption({ |
| | | grid: { |
| | | bottom: '40px', |
| | | }, |
| | |
| | | } |
| | | this.dataZoom.show = false; |
| | | // 绘制图表 |
| | | this.chart.setOption({ |
| | | this.$G.chartManage.get(this.id).setOption({ |
| | | grid: { |
| | | bottom: '1', |
| | | }, |
| | |
| | | }, |
| | | mounted() { |
| | | var ele = document.getElementById(this.id); |
| | | this.chart = ECharts.init(ele, 'transparent'); |
| | | let chart = ECharts.init(ele, 'transparent'); |
| | | // 将图表添加到图表管理 |
| | | this.$G.chartManage.set(this.id, chart); |
| | | // 设置配置 |
| | | this.setOption({}); |
| | | // 监听显示 |
| | | this.chart.on('showTip', (data)=>{ |
| | | chart.on('showTip', (data)=>{ |
| | | this.dataIndex = data.dataIndex; |
| | | let option = this.chart.getOption(); |
| | | let option = this.$G.chartManage.get(this.id).getOption(); |
| | | this.history.time = option.xAxis[0].data[data.dataIndex-1]; |
| | | this.history.value = option.series[0].data[data.dataIndex-1]; |
| | | }); |
| | | }, |
| | | destroyed() { |
| | | // 销毁echarts |
| | | this.chart.dispose(); |
| | | this.$G.chartManage.del(this.id); |
| | | }, |
| | | } |
| | | </script> |
New file |
| | |
| | | // 引入 ECharts 主模块 |
| | | import ECharts from "echarts/lib/echarts" |
| | | |
| | | function ChartManage() { |
| | | this.charts = {}; |
| | | } |
| | | /** |
| | | * [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; |
| | | } |
| | | }); |
| | | |
| | | ECharts.connect(groups); |
| | | } |
| | | |
| | | export default new ChartManage(); |
New file |
| | |
| | | import chartManage from './ChartManage' |
| | | |
| | | export default { |
| | | chartManage |
| | | }; |
| | |
| | | import router from './router' |
| | | import store from './store' |
| | | import config from './assets/js/config' |
| | | import G from './global' |
| | | import './api' |
| | | import ElementUI from 'element-ui' |
| | | import 'element-ui/lib/theme-chalk/index.css' |
| | |
| | | }; |
| | | // 挂载配置 |
| | | Vue.prototype.$config = config; |
| | | Vue.prototype.$G = G; |
| | | |
| | | new Vue({ |
| | | router, |
| | |
| | | <script> |
| | | // 引入 ECharts 主模块 |
| | | import FlexLayout from '@/components/FlexLayout' |
| | | import ECharts from "echarts/lib/echarts" |
| | | import LineChart from '@/components/chart/LineChart' |
| | | import ChartConfigs from '@/components/chart/ChartConfigs' |
| | | |
| | |
| | | if(this.options[key].show) { |
| | | // 配置项初始化 |
| | | this.$refs[key][0].setOption(this.options[key].option); |
| | | groups.push(this.$refs[key][0].chart); |
| | | groups.push(key); |
| | | } |
| | | } |
| | | |
| | | // 或者可以直接传入需要联动的实例数组 |
| | | ECharts.connect(groups); |
| | | this.$G.chartManage.connect(groups); |
| | | }, |
| | | resizeCharts() { |
| | | // 设置配置项 |
| | | for(let key in this.options) { |
| | | if(this.options[key].show) { |
| | | // 配置项初始化 |
| | | this.$refs[key][0].chart.resize(); |
| | | this.$G.chartManage.resize(key); |
| | | } |
| | | } |
| | | }, |
| | |
| | | }, |
| | | }, |
| | | mounted() { |
| | | console.log(this.$G); |
| | | let self = this; |
| | | // 查询事件类型 |
| | | this.changeOptions(); |
| | |
| | | </template> |
| | | |
| | | <script> |
| | | // 引入 ECharts 主模块 |
| | | import ECharts from "echarts/lib/echarts"; |
| | | import LineChart from '@/components/chart/LineChart' |
| | | import FlexLayout from '@/components/FlexLayout' |
| | | import ChartConfigs from '@/components/chart/ChartConfigs' |
| | |
| | | if(this.options[key].show) { |
| | | // 配置项初始化 |
| | | this.$refs[key][0].setOption(this.options[key].option); |
| | | groups.push(this.$refs[key][0].chart); |
| | | groups.push(key); |
| | | } |
| | | } |
| | | |
| | | // 或者可以直接传入需要联动的实例数组 |
| | | ECharts.connect(groups); |
| | | this.$G.chartManage.connect(groups); |
| | | }, |
| | | resizeCharts() { |
| | | // 设置配置项 |
| | | for(let key in this.options) { |
| | | if(this.options[key].show) { |
| | | // 配置项初始化 |
| | | this.$refs[key][0].chart.resize(); |
| | | this.$G.chartManage.resize(key); |
| | | } |
| | | } |
| | | }, |
| | | startSearchRealData() { |
| | | this.timer.start(()=>{ |
| | | this.searchRealData(); |
| | | }, 2000); |
| | | }, 1000); |
| | | }, |
| | | searchRealData() { |
| | | var batt = this.$store.state.batt; |