|
@@ -1,55 +1,72 @@
|
|
|
<!-- 柱图 -->
|
|
|
<template>
|
|
|
- <div style="height:300px;" :id="props.id" class="myChart"></div>
|
|
|
+ <div style="height:100%;" :id="props.id" class="myChart"></div>
|
|
|
</template>
|
|
|
-
|
|
|
<script setup lang="ts">
|
|
|
-import { inject,onMounted,reactive } from "vue";
|
|
|
+import { onMounted, inject, watch, reactive } from "vue";
|
|
|
+import findDataFun from '@/plugins/findData'
|
|
|
+// 接受父组件参数,配置默认值
|
|
|
const props = defineProps({
|
|
|
id: {
|
|
|
type: String,
|
|
|
default: () => '',
|
|
|
},
|
|
|
- lineData:{
|
|
|
- type:Object,
|
|
|
- default: () => {},
|
|
|
+ lineData: {
|
|
|
+ type: Object,
|
|
|
+ default: () => { },
|
|
|
},
|
|
|
-})
|
|
|
+ switchData: {
|
|
|
+ type: Boolean,
|
|
|
+ default: () => true,
|
|
|
+ }
|
|
|
+});
|
|
|
|
|
|
-let echartData:any = reactive({
|
|
|
- titles:'',//标题
|
|
|
- xAxisArr:[],//x轴
|
|
|
- seriesDiscount:[], //合同总金额
|
|
|
- seriesRecoveries:[] //合同已回款金额
|
|
|
-})
|
|
|
+let echart: any = null
|
|
|
+let myChart: any = null
|
|
|
|
|
|
-let echart:any = null
|
|
|
-let myChart:any = null
|
|
|
+let echartData: any = reactive({
|
|
|
+ titles: '',//标题
|
|
|
+ xAxisArr: [],//x轴
|
|
|
+ seriesDiscount: [], //合同总金额
|
|
|
+ seriesRecoveries: [] //合同已回款金额
|
|
|
+})
|
|
|
+watch(() => props.switchData, () => {
|
|
|
+ // echartData = findDataFun('line', props.lineData, props.switchData)
|
|
|
+ myChart.clear();
|
|
|
+ myChart.setOption(initEcharts());
|
|
|
+})
|
|
|
|
|
|
+watch(() => props.lineData, async () => {
|
|
|
+ // echartData = findDataFun('line', props.lineData, props.switchData)
|
|
|
+ myChart.clear();
|
|
|
+ myChart.setOption(initEcharts());
|
|
|
+})
|
|
|
onMounted(() => {
|
|
|
echart = inject('echart')
|
|
|
myChart = echart.init(document.getElementById(props.id));
|
|
|
setEchartFun();
|
|
|
})
|
|
|
+
|
|
|
//函数
|
|
|
-const setEchartFun = async ()=>{
|
|
|
+const setEchartFun = async () => {
|
|
|
myChart.setOption(initEcharts());
|
|
|
window.onresize = function () {
|
|
|
myChart.resize();
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+
|
|
|
const initEcharts = () => {
|
|
|
// 绘制图表
|
|
|
return {
|
|
|
tooltip: {
|
|
|
trigger: 'axis',
|
|
|
- axisPointer: {
|
|
|
- type: 'cross',
|
|
|
- label: {
|
|
|
- backgroundColor: '#6a7985'
|
|
|
- }
|
|
|
- }
|
|
|
+ // axisPointer: {
|
|
|
+ // type: 'cross',
|
|
|
+ // label: {
|
|
|
+ // backgroundColor: '#6a7985'
|
|
|
+ // }
|
|
|
+ // }
|
|
|
},
|
|
|
title: {
|
|
|
// text: 'Rainfall vs Evaporation',
|
|
@@ -61,26 +78,39 @@ const initEcharts = () => {
|
|
|
bottom: '0%',
|
|
|
containLabel: true
|
|
|
},
|
|
|
- xAxis: [
|
|
|
- {
|
|
|
- boundaryGap: false,
|
|
|
- type: 'category',
|
|
|
- // data: echartData.xAxisArr
|
|
|
- }
|
|
|
- ],
|
|
|
+ xAxis: {
|
|
|
+ type: 'category',
|
|
|
+ data: ['Mon', 'Tue', 'Wed', 'Thu']
|
|
|
+ },
|
|
|
yAxis: {
|
|
|
type: 'value'
|
|
|
},
|
|
|
series: [
|
|
|
{
|
|
|
- // name: echartData.tooltip,
|
|
|
- type: 'line',
|
|
|
- smooth: true,
|
|
|
- stack: 'Total',
|
|
|
- areaStyle: {},
|
|
|
- emphasis: {
|
|
|
- focus: 'series'
|
|
|
+ data: [Math.random(), Math.random(), Math.random(), Math.random()],
|
|
|
+ type: 'bar',
|
|
|
+ barMaxWidth:'10%',//宽度
|
|
|
+ itemStyle: { //面积图颜色设置
|
|
|
+ color: {
|
|
|
+ type: 'linear',
|
|
|
+ x: 0,
|
|
|
+ y: 0,
|
|
|
+ x2: 0,
|
|
|
+ y2: 1,
|
|
|
+ colorStops: [
|
|
|
+ { offset: 0, color: '#5389fd' },
|
|
|
+ { offset: 0.5, color: '#3a6cf9' },
|
|
|
+ { offset: 1, color: '#2251f7' }
|
|
|
+ ],
|
|
|
+ globalCoord: false // 缺省为 false
|
|
|
+ },
|
|
|
+ barBorderRadius: [30, 30, 0, 0] //圓角
|
|
|
},
|
|
|
+ },
|
|
|
+ {
|
|
|
+ data: [Math.random(), Math.random(), Math.random(), Math.random()],
|
|
|
+ type: 'bar',
|
|
|
+ barMaxWidth:'10%',//宽度
|
|
|
itemStyle: { //面积图颜色设置
|
|
|
color: {
|
|
|
type: 'linear',
|
|
@@ -89,21 +119,17 @@ const initEcharts = () => {
|
|
|
x2: 0,
|
|
|
y2: 1,
|
|
|
colorStops: [
|
|
|
- {
|
|
|
- offset: 0, //offset 可取范围 0、0.1、0.2、到1
|
|
|
- color: 'rgba(250, 51, 171, 0.8)', // 0% 处的颜色
|
|
|
- },
|
|
|
- {
|
|
|
- offset: 1,
|
|
|
- color: 'rgba(206, 51, 181, 0.4)' // 100% 处的颜色
|
|
|
- }
|
|
|
+ { offset: 0, color: '#feae4d' },
|
|
|
+ { offset: 0.5, color: '#f99b45' },
|
|
|
+ { offset: 1, color: '#fd8c38' }
|
|
|
],
|
|
|
globalCoord: false // 缺省为 false
|
|
|
- }
|
|
|
+ },
|
|
|
+ barBorderRadius: [30, 30, 0, 0] //圓角
|
|
|
},
|
|
|
- data:[120, 200, 150, 80, 70, 110, 130],
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
</script>
|