123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <template>
- <div shadow="never" class="homeBoxCard" v-loading="loading">
- <div class="height400" ref="lineChartBanlance" />
- </div>
- </template>
- <script>
- import { useStore } from 'vuex'
- import { defineComponent, onMounted, ref, watch } from 'vue'
- import * as echarts from 'echarts'
- export default defineComponent({
- name: 'lineChartValue',
- props: {},
- setup(props) {
- props
- const store = useStore()
- let lineChartBanlance = ref(null)
- const dataTimes = ref([])
- const lineChartArr = ref([])
- // 读取数据 func
- const loading = ref(true)
- const getData = async () => {
- dataTimes.value = store.state.realScoreLineDataTime
- lineChartArr.value = store.state.realScoreLineObj
- lineChartArr.value.forEach((value) => {
- value.type = 'line'
- value.smooth = false
- value.symbolSize = 7
- // value.markPoint = {
- // data: [
- // { type: 'max', name: 'Max' },
- // { type: 'min', name: 'Min' },
- // ],
- // }
- })
- loading.value = false
- }
-
- function echarts2() {
- let myChart = echarts.init(lineChartBanlance.value)
-
- // 绘制图表
- myChart.setOption({
- color: ['#1187FF', '#48C964', '#fe8161'],
- legend: {
- top: '0',
- },
- tooltip: {
- // show: true
- trigger: 'axis',
- axisPointer: { type: 'cross' },
- },
- grid: {
- left: '20',
- right: '40',
- top: '40',
- bottom: '30',
- containLabel: true,
- },
- xAxis: {
- axisLabel: {
- color: '#444',
- fontSize: 14,
- },
- /*改变xy轴颜色*/
- axisLine: {
- lineStyle: {
- color: '#444',
- width: 1, //这里是为了突出显示加上的
- },
- },
- boundaryGap: false,
- data: dataTimes.value,
- },
- yAxis: {
- name: store.state.realScoreLineName,
- textStyle: {
- color: 'black',
- fontSize: 10,
- },
- type: 'value',
- axisTick: {
- show: true, //去除刻度线
- },
- axisLabel: {
- color: 'black', // 文本颜色
- },
- axisLine: {
- show: true, // 去除轴线
- lineStyle: {
- color: 'black',
- },
- },
- splitNumber: 5,
- splitLine: {
- show: true,
- lineStyle: {
- color: '#9d9d9d',
- },
- },
- },
- // series: [
- // {
- // name: 'A相电流',
- // type: 'line',
- // symbolSize: 7,
- // smooth: false,
- // data: [1, 2, 6, 4, 5, 58, 6, 7, 8],
- // },
- // {
- // name: 'B相电流',
- // type: 'line',
- // symbolSize: 7,
- // smooth: false,
- // data: [1, 2, 3, 4, 9, 5, 6, 7, 8],
- // },
- // {
- // name: 'C相电流',
- // type: 'line',
- // symbolSize: 7,
- // smooth: false,
- // data: [1, 2, 3, 4, 5, 6, 6, 7, 3],
- // },
- // ],
- series: lineChartArr.value,
- })
- window.addEventListener('resize', () => {
- myChart.resize()
- })
- }
- const writeValue = (val) => {
- val
- getData()
- echarts2()
- }
- //监听变化
- watch(
- () => store.state.realScoreLineObj,
- (newVal, oldVal, clear) => {
- // 执行异步任务,并得到关闭异步任务的 id
- // console.log(newVal)
- let id = writeValue(newVal, oldVal)
- // 如果 watch 监听被重复执行了,则会先清除上次未完成的异步任务
- clear(() => clearTimeout(id))
- },
- { lazy: true }
- )
- onMounted(() => {
- // getData()
- // echarts2()
- })
- return {
- lineChartBanlance,
- loading,
- store,
- dataTimes,
- lineChartArr,
- }
- },
- })
- </script>
- <style lang="scss" scoped>
- .homeBoxCard {
- margin-bottom: 24px;
- ::v-deep(.el-card__header) {
- padding-left: 12px;
- padding-right: 12px;
- }
- ::v-deep(.el-card__body) {
- padding: 12px;
- font-size: 14px;
- line-height: 1.5715;
- }
- ::v-deep(.el-divider) {
- margin: 8px 0;
- }
- .num {
- font-size: 30px;
- color: #515a6e;
- }
- .height400 {
- height: 400px;
- }
- }
- </style>
|