| | |
| | | components: {}, |
| | | data() { |
| | | //这里存放数据 |
| | | return {}; |
| | | return { myChart }; |
| | | }, |
| | | mounted() { |
| | | this.lineChart(); |
| | | this.$bus.$on('resizeEchart', (res) => { |
| | | this.myChart.resize(); |
| | | }); |
| | | }, |
| | | //方法集合 |
| | | methods: { |
| | | lineChart() { |
| | | let dataAxis = [ |
| | | "勘察数据", |
| | | "岩土数据", |
| | | "测量数据", |
| | | "合规数据", |
| | | "管理数据", |
| | | '勘察数据', |
| | | '岩土数据', |
| | | '测量数据', |
| | | '合规数据', |
| | | '管理数据', |
| | | ]; |
| | | // prettier-ignore |
| | | let data = [1200,500,1000,200,200]; |
| | |
| | | } |
| | | let option = { |
| | | title: { |
| | | text: "数据下载量", |
| | | text: '数据下载量', |
| | | textStyle: { |
| | | color: "#fff", |
| | | color: '#fff', |
| | | }, |
| | | }, |
| | | tooltip: { |
| | | trigger: "axis", |
| | | trigger: 'axis', |
| | | axisPointer: { |
| | | type: "shadow", |
| | | type: 'shadow', |
| | | }, |
| | | }, |
| | | grid: { |
| | | left: "0%", |
| | | right: "0%", |
| | | bottom: "0%", |
| | | left: '0%', |
| | | right: '0%', |
| | | bottom: '0%', |
| | | containLabel: true, |
| | | }, |
| | | xAxis: { |
| | | type: "category", |
| | | type: 'category', |
| | | data: dataAxis, |
| | | axisLabel: { |
| | | show: true, |
| | | textStyle: { |
| | | color: "#fff", |
| | | color: '#fff', |
| | | }, |
| | | formatter: function (params) { |
| | | var newParamsName = ""; // 最终拼接成的字符串 |
| | | var newParamsName = ''; // 最终拼接成的字符串 |
| | | var paramsNameNumber = params.length; // 实际标签的个数 |
| | | var provideNumber = 6; // 每行能显示的字的个数 |
| | | var rowNumber = Math.ceil(paramsNameNumber / provideNumber); // 换行的话,需要显示几行,向上取整 |
| | |
| | | if (paramsNameNumber > provideNumber) { |
| | | /** 循环每一行,p表示行 */ |
| | | for (var p = 0; p < rowNumber; p++) { |
| | | var tempStr = ""; // 表示每一次截取的字符串 |
| | | var tempStr = ''; // 表示每一次截取的字符串 |
| | | var start = p * provideNumber; // 开始截取的位置 |
| | | var end = start + provideNumber; // 结束截取的位置 |
| | | // 此处特殊处理最后一行的索引值 |
| | |
| | | tempStr = params.substring(start, paramsNameNumber); |
| | | } else { |
| | | // 每一次拼接字符串并换行 |
| | | tempStr = params.substring(start, end) + "\n"; |
| | | tempStr = params.substring(start, end) + '\n'; |
| | | } |
| | | newParamsName += tempStr; // 最终拼成的字符串 |
| | | } |
| | |
| | | axisLabel: { |
| | | show: true, |
| | | textStyle: { |
| | | color: "#fff", |
| | | color: '#fff', |
| | | }, |
| | | }, |
| | | }, |
| | | dataZoom: [ |
| | | { |
| | | type: "inside", |
| | | type: 'inside', |
| | | }, |
| | | ], |
| | | series: [ |
| | | { |
| | | type: "bar", |
| | | type: 'bar', |
| | | showBackground: true, |
| | | itemStyle: { |
| | | color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [ |
| | | { offset: 0, color: "#40FBCB" }, |
| | | { offset: 1, color: "#20B2AA" }, |
| | | { offset: 0, color: '#40FBCB' }, |
| | | { offset: 1, color: '#20B2AA' }, |
| | | ]), |
| | | }, |
| | | emphasis: { |
| | | itemStyle: { |
| | | color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [ |
| | | { offset: 0, color: "#2378f7" }, |
| | | { offset: 0.7, color: "#2378f7" }, |
| | | { offset: 1, color: "##7ed3f4" }, |
| | | { offset: 0, color: '#2378f7' }, |
| | | { offset: 0.7, color: '#2378f7' }, |
| | | { offset: 1, color: '##7ed3f4' }, |
| | | ]), |
| | | }, |
| | | }, |
| | |
| | | ], |
| | | }; |
| | | const zoomSize = 6; |
| | | let myChart = this.$echarts.init(document.getElementById("echart22")); |
| | | myChart.on("click", function (params) { |
| | | this.myChart = this.$echarts.init(document.getElementById('echart22')); |
| | | this.myChart.on('click', function (params) { |
| | | console.log(dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)]); |
| | | myChart.dispatchAction({ |
| | | type: "dataZoom", |
| | | this.myChart.dispatchAction({ |
| | | type: 'dataZoom', |
| | | startValue: dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)], |
| | | endValue: |
| | | dataAxis[ |
| | |
| | | }); |
| | | }); |
| | | |
| | | myChart.setOption(option); |
| | | window.addEventListener("resize", function () { |
| | | myChart.resize(); |
| | | this.myChart.setOption(option); |
| | | window.addEventListener('resize', function () { |
| | | this.myChart.resize(); |
| | | }); |
| | | }, |
| | | }, |