|
@@ -4,31 +4,26 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
-import { computed, defineComponent, onMounted, ref } from 'vue'
|
|
|
-import { useStore } from 'vuex'
|
|
|
+import { defineComponent, onMounted, ref, watch } from 'vue'
|
|
|
+// import { useStore } from 'vuex'
|
|
|
import * as echarts from 'echarts'
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: 'LoopLineChart',
|
|
|
- setup() {
|
|
|
- const store = useStore()
|
|
|
+ props: {
|
|
|
+ num: Number,
|
|
|
+ unit:String
|
|
|
+ },
|
|
|
+ setup(props) {
|
|
|
+ // const store = useStore()
|
|
|
const lineChartBanlance = ref(null)
|
|
|
|
|
|
- // 总数
|
|
|
- const total = computed(() => store.state.Home.worksChartData.total)
|
|
|
- // num
|
|
|
- const num = computed(() => store.state.Home.worksChartData.num)
|
|
|
-
|
|
|
// 读取数据 func
|
|
|
const loading = ref(true)
|
|
|
const getData = async () => {
|
|
|
- // loading.value = true
|
|
|
- // await store.dispatch('Home/queryWorksChartData')
|
|
|
loading.value = false
|
|
|
}
|
|
|
-
|
|
|
- onMounted(() => {
|
|
|
- getData()
|
|
|
+ function echarts2() {
|
|
|
let myChart = echarts.init(lineChartBanlance.value)
|
|
|
// 绘制图表
|
|
|
myChart.setOption({
|
|
@@ -45,9 +40,18 @@ export default defineComponent({
|
|
|
// show: false,
|
|
|
// },
|
|
|
tooltip: {
|
|
|
- // show: true
|
|
|
+ // trigger: 'axis',
|
|
|
+ // axisPointer: { type: 'cross' },
|
|
|
+
|
|
|
trigger: 'axis',
|
|
|
- axisPointer: { type: 'cross' },
|
|
|
+ formatter: function (params) {
|
|
|
+ var relVal = params[0].name
|
|
|
+ for (var i = 0, l = params.length; i < l; i++) {
|
|
|
+ relVal +=
|
|
|
+ '<br/>' + params[i].seriesName + ' : ' + params[i].value + props.unit
|
|
|
+ }
|
|
|
+ return relVal
|
|
|
+ },
|
|
|
},
|
|
|
grid: {
|
|
|
left: '20',
|
|
@@ -69,21 +73,43 @@ export default defineComponent({
|
|
|
},
|
|
|
},
|
|
|
boundaryGap: false,
|
|
|
- data: [
|
|
|
- '总谐波',
|
|
|
- '3次谐波',
|
|
|
- '5次谐波',
|
|
|
- '7次谐波',
|
|
|
- '9次谐波',
|
|
|
- '11次谐波',
|
|
|
- '13次谐波',
|
|
|
- '15次谐波',
|
|
|
- '17次谐波',
|
|
|
- '19次谐波',
|
|
|
- '21次谐波',
|
|
|
- '23次谐波',
|
|
|
- '25次谐波',
|
|
|
- ],
|
|
|
+ data:
|
|
|
+ props.num == 0
|
|
|
+ ? [
|
|
|
+ '总谐波',
|
|
|
+ '3次谐波',
|
|
|
+ '5次谐波',
|
|
|
+ '7次谐波',
|
|
|
+ '9次谐波',
|
|
|
+ '11次谐波',
|
|
|
+ '13次谐波',
|
|
|
+ '15次谐波',
|
|
|
+ '17次谐波',
|
|
|
+ '19次谐波',
|
|
|
+ '21次谐波',
|
|
|
+ '23次谐波',
|
|
|
+ '25次谐波',
|
|
|
+ '27次谐波',
|
|
|
+ '29次谐波',
|
|
|
+ '31次谐波',
|
|
|
+ ]
|
|
|
+ : [
|
|
|
+ '2总谐波',
|
|
|
+ '4次谐波',
|
|
|
+ '6次谐波',
|
|
|
+ '8次谐波',
|
|
|
+ '10次谐波',
|
|
|
+ '12次谐波',
|
|
|
+ '14次谐波',
|
|
|
+ '16次谐波',
|
|
|
+ '18次谐波',
|
|
|
+ '20次谐波',
|
|
|
+ '22次谐波',
|
|
|
+ '24次谐波',
|
|
|
+ '26次谐波',
|
|
|
+ '28次谐波',
|
|
|
+ '30次谐波',
|
|
|
+ ],
|
|
|
},
|
|
|
yAxis: {
|
|
|
// name: "A",
|
|
@@ -112,8 +138,8 @@ export default defineComponent({
|
|
|
symbolSize: 7,
|
|
|
smooth: false,
|
|
|
data: [
|
|
|
- 10, 2, 12, 0, 5, 10, 2, 12, 0, 5, 10, 2, 12, 0, 5, 10, 2, 12, 0,
|
|
|
- 5, 10, 2, 12, 0, 5,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0,
|
|
|
],
|
|
|
},
|
|
|
{
|
|
@@ -122,8 +148,8 @@ export default defineComponent({
|
|
|
symbolSize: 7,
|
|
|
smooth: false,
|
|
|
data: [
|
|
|
- 10, 2, 12, 0, 7, 8, 9, 7, 19, 7, 8, 9, 7, 19, 7, 8, 9, 7, 19, 7,
|
|
|
- 8, 9, 7, 19, 7, 8, 9, 7, 19,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0,
|
|
|
],
|
|
|
},
|
|
|
{
|
|
@@ -132,8 +158,8 @@ export default defineComponent({
|
|
|
symbolSize: 7,
|
|
|
smooth: false,
|
|
|
data: [
|
|
|
- 5, 3, 6, 5, 14, 5, 3, 6, 5, 14, 5, 3, 6, 5, 14, 5, 3, 6, 5, 14, 5,
|
|
|
- 3, 6, 5, 14, 5, 3, 6, 5, 14,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0,
|
|
|
],
|
|
|
},
|
|
|
],
|
|
@@ -141,13 +167,37 @@ export default defineComponent({
|
|
|
window.addEventListener('resize', () => {
|
|
|
myChart.resize()
|
|
|
})
|
|
|
+ }
|
|
|
+
|
|
|
+ const writeValue = (val) => {
|
|
|
+ val
|
|
|
+ getData()
|
|
|
+ echarts2()
|
|
|
+ }
|
|
|
+
|
|
|
+ //监听变化
|
|
|
+ watch(
|
|
|
+ () => props.num,
|
|
|
+ (newVal, oldVal, clear) => {
|
|
|
+ // 执行异步任务,并得到关闭异步任务的 id
|
|
|
+ console.log('newVal')
|
|
|
+ console.log(newVal)
|
|
|
+ let id = writeValue(newVal, oldVal)
|
|
|
+ // 如果 watch 监听被重复执行了,则会先清除上次未完成的异步任务
|
|
|
+ clear(() => clearTimeout(id))
|
|
|
+ },
|
|
|
+ { lazy: true }
|
|
|
+ )
|
|
|
+
|
|
|
+ onMounted(() => {
|
|
|
+ getData()
|
|
|
+ echarts2()
|
|
|
})
|
|
|
|
|
|
return {
|
|
|
lineChartBanlance,
|
|
|
loading,
|
|
|
- total,
|
|
|
- num,
|
|
|
+ echarts2,
|
|
|
}
|
|
|
},
|
|
|
})
|