当前位置: 首页 > article >正文

echarts的使用

1. 普通版

其实主要就是option1,option1就是画的图

echats不能响应刷新,要想实时刷新监听刷新的值重新调用一下方法即可

html
<div class="echart" style="width: 100%;height: calc(100% - 130px)" ref="main1"></div>

 
js
import * as echarts from "echarts";

 mounted() {
    this.initDayEcharts();
},

initDayEcharts() {
      const option1 = {
        legend: {
          textStyle: {
            color: '#ffffff'
          },
          y: 'bottom',
        },
        grid: {
          left: '5%',
          right: '5%',
          top: '10%',
          bottom: '15%',
          containLabel: true
        },
        xAxis: {
          type: 'value',
          axisLabel: {
            textStyle: {
              color: '#ffffff'
            }
          },
        },
        yAxis: {
          type: 'category',
          data: this.inAndOutWarehouseToday.name,
          axisLabel: {
            textStyle: {
              color: '#ffffff'
            }
          },
        },
        series: [
          {
            name: '入库数',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            color: '#4F89FC',
            //动态条形图宽度
            barWidth: 20 ,
            data: this.inAndOutWarehouseToday.inNum
          },
          {
            name: '出库数',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            color: '#A5DC65',
            barWidth: 20,
            data: this.inAndOutWarehouseToday.outNum
          }
        ]
      };

      // 获取DOM元素
      const main1 = echarts.init(this.$refs.main1);
      // 设置图表配置项和数据
      main1.setOption(option1);

    },

2. 可跳转路径版+赋值版

注意样式要给宽度,不然看不到

<div id="roadElectricity"  style="flex: 1;height: 400px;width: 500px"></div>


js
  mounted() {
    this.getRouteElectromechanical()
  },
 methods: {
a    sync getRouteElectromechanical(params) {
      let queryParams = Object.assign({}, {name: '机电设施路段机电统计'}, params)
      let {data: data} = await commonListData(queryParams)
      console.log("data===",data)

      let res = data || []
      let roadElectricity = this.$echarts.init(document.getElementById('roadElectricity'))
      let  option = {
        series: [
          {
            type: 'pie',
            data: [
              {
                value: 0,
                name: '服务区监控'
              },
              {
                value: 0,
                name: '路段监控系统'
              },
              {
                value: 0,
                name: '站级监控系统'
              },
            ],
            radius: '50%'
          }
        ]
      };
      if (res.length > 0) {
        console.log("机电设施路段机电统计=", res)
        option.series[0].data = res.map(item => Object.assign({}, {value: item.count, name: item.asset_type_name}))
      }

      roadElectricity.setOption(option)

      roadElectricity.on("click", (params) => {
        console.log('params=', params)
        this.$router.push({
          path: '/account/asset/account/search/assetDetail',
          query: Object.assign({}, {
                assetTypeId: 1037 ,
                assetTypeName: params.name
              }
          )
        })
      })
    },

}

this.$echarts是全局定义的,都差不多

main.js

import * as echarts from 'echarts'

Vue.prototype.$echarts = echarts

2. 的一句代码解析

for (let i = 0; i < reoption.series[0].data = res.map(item => Object.assign({}, {value: item.count, name: item.asset_type_name}))

非简写

for (let i = 0; i < res.length; i++) {
  let item = res[i];
  let newItem = {value: item.count, name: item.asset_type_name};
  option.series[0].data.push(newItem);
}


http://www.kler.cn/a/137383.html

相关文章:

  • Go——二、变量和数据类型
  • 爬虫的http和https基础
  • 如何在公网环境下使用笔记本的Potplayer访问本地群晖webdav中的影视资源
  • 蓝桥杯物联网_STM32L071_1_CubMxkeil5基础配置
  • Docker部署FLASK Unicorn并配置Nginx
  • 【Django-02】 Model模型和模型描述对象Meta
  • 类型体系与基本数据类型(题目)
  • WinEdt 11.1编辑器的尝鲜体验
  • vscode c++ 报错identifier “string“ is undefined
  • 海外IP代理科普——API代理是什么?怎么用?
  • 一个快递包裹的跨国之旅
  • Flutter 使用 device_info_plus 遇到的问题
  • Python基础学习019--跳过
  • Django——模型层补充
  • ES Kibana 安装
  • 开发手账(一)
  • 为什么STM32在中国这么出名?
  • SpringBoot 注解开发
  • 深入了解Java 8 新特性:Stream流的实践应用(二)
  • FFmpeg常用命令行讲解及实战一