| | |
| | | import 'echarts/lib/component/tooltip' |
| | | import 'echarts/lib/component/title' |
| | | import 'echarts/lib/component/legend' |
| | | import {deleteChartId} from "@/api/statistic/chart" |
| | | import { deleteChartId } from "@/api/statistic/chart" |
| | | |
| | | export default { |
| | | name: "ColumnarChart", |
| | | props:{ |
| | | columnarData:{ |
| | | type:Array, |
| | | default:[] |
| | | props: { |
| | | columnarData: { |
| | | type: Array, |
| | | default: [] |
| | | }, |
| | | chartName:{ |
| | | type:String, |
| | | chartName: { |
| | | type: String, |
| | | default: "" |
| | | }, |
| | | btmname :{ |
| | | btmname: { |
| | | type: String |
| | | } |
| | | }, |
| | | watch:{ |
| | | columnarData:{ |
| | | immediate:true, |
| | | handler(newval,oldval){ |
| | | if(newval && newval.length > 0){ |
| | | const minValues = newval[0].map(function (_, i) { |
| | | return Math.min.apply( |
| | | null, |
| | | newval.map(function (item) { |
| | | return item[i]; |
| | | }) |
| | | ); |
| | | }); |
| | | |
| | | let colors = ['#84C9E5', '#F68686']; |
| | | |
| | | const seriesData = []; |
| | | for (let i = 0; i < newval.length; i++) { |
| | | let curSeriesData = []; |
| | | for (let j = 0; j < newval[i].length; j++) { |
| | | let borderRadius = [0, 0, 0, 0]; |
| | | if (newval[i][j] === minValues[j]) { |
| | | borderRadius = [50, 50, 0, 0]; |
| | | } |
| | | curSeriesData.push({ |
| | | value: newval[i][j], |
| | | itemStyle: { |
| | | normal: { |
| | | // barBorderRadius: borderRadius, // 设置圆角 |
| | | color: colors[i], |
| | | } |
| | | }, |
| | | }); |
| | | } |
| | | let seriesName = (i === 0 ? "总量" : "新增") |
| | | seriesData.push({ |
| | | name: seriesName, |
| | | type: "bar", |
| | | stack: "总量", |
| | | barWidth: 60, |
| | | data: curSeriesData, |
| | | watch: { |
| | | columnarData: { |
| | | immediate: true, |
| | | handler(newval, oldval) { |
| | | if (newval && newval.length > 0) { |
| | | let seriesData = newval.map((data, index) => { |
| | | let name = index === 0 ? "总量" : "新增"; |
| | | return { |
| | | name: name, |
| | | type: 'bar', |
| | | data: data, |
| | | barWidth: '40%', |
| | | label: { |
| | | show: true, |
| | | position: 'top', |
| | | formatter: function (params) { |
| | | return params.value === 0 ? '' : params.value; // 值为 0 不显示,其他情况显示 |
| | | } |
| | | // formatter: function (params) { |
| | | // if (params.value !== 0) { |
| | | // return params.value; |
| | | // } else { |
| | | // return ''; |
| | | // } |
| | | // } |
| | | }, |
| | | emphasis: { |
| | | focus: "series", |
| | | }, |
| | | }); |
| | | this.chartOptions.series=seriesData |
| | | } |
| | | }; |
| | | }); |
| | | this.chartOptions.series = seriesData; |
| | | } |
| | | } |
| | | }, |
| | | chartName:{ |
| | | handler(newval,oldval){ |
| | | if(newval){ |
| | | chartName: { |
| | | handler(newval, oldval) { |
| | | if (newval) { |
| | | this.chartOptions.title.text = newval + "数据统计" |
| | | } |
| | | }, |
| | | immediate:true, |
| | | deep:true |
| | | immediate: true, |
| | | deep: true |
| | | } |
| | | }, |
| | | data() { |
| | | return { |
| | | chartOptions: { |
| | | color:['#84C9E5', '#F68686'], |
| | | color: ['#84C9E5', '#F68686'], |
| | | title: { |
| | | text: "", |
| | | }, |
| | |
| | | }, |
| | | created() { |
| | | }, |
| | | methods:{ |
| | | delHandler(){ |
| | | deleteChartId({btmname:this.btmname,chartId:'2'}).then(res=>{ |
| | | methods: { |
| | | delHandler() { |
| | | deleteChartId({ btmname: this.btmname, chartId: '2' }).then(res => { |
| | | this.$message.success('删除成功') |
| | | this.$emit('refresh'); |
| | | }).catch(error=>{ |
| | | }).catch(error => { |
| | | this.$message.error(error) |
| | | }) |
| | | } |
| | |
| | | async getEcharts() { |
| | | try { |
| | | const firstResponse = await getBtmAndChart(); |
| | | this.ResponseData = await getBtmAndChart(); |
| | | console.log(firstResponse) |
| | | const btmNames = Object.keys(firstResponse.data.data).join(','); |
| | | const btmValue = Object.values(firstResponse.data.data); |
| | | if (!btmNames) { |
| | |
| | | }); |
| | | }); |
| | | } |
| | | } else { |
| | | console.log('else') |
| | | } |
| | | }); |
| | | }, |
| | |
| | | }, |
| | | //表格多选 |
| | | selectChange(selection) { |
| | | console.log('selection', selection) |
| | | this.selectData = selection; |
| | | }, |
| | | } |