第五章:element、echarts及axios-[基于Vue、Django、supermap iserver和gerapy的生态旅游web系统开发实例]

本文介绍了如何在Vue项目中集成ElementPlus UI库、ECharts图表库以及Axios请求库。首先,通过导入和注册相关模块实现组件的全局挂载。然后,展示了如何在模板中使用ElementPlus的表格组件展示数据。最后,通过 Axios 获取后端数据,并利用 ECharts 创建动态柱状图,根据年份区分企业新增和现有总数。
摘要由CSDN通过智能技术生成

      本章介绍如何挂载Element plus和echarts,并通过axios访问后端数据服务。

  vue中挂载Element plus、echarts和axios

//main中:
import {createApp} from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import elementplus from 'element-plus'
import 'element-plus//theme-chalk//index.css' 
import './assets/css/global.css'//自定义设置全局样式
import './assets/fonts/iconfont.css'//设置登陆页面图标
import * as echarts from 'echarts'
const app = createApp(App)
app.use(store).use(router).use(elementplus).mount('#app')
app.config.globalProperties.$echarts = echarts//全局挂载echarts
app.config.globalProperties.$axios = axios //全局挂载axios


接着便可直接使用:

// element-plus
<template>
  <div class="title">商家投诉统计</div>
  <div class="ec">
    <el-table
      :data="tableData"
      height="180"
      border
      style="width: 100%;background-color: #000000;"
      :row-style="{height: '0'}"
      :cell-style="{padding: '0',background:'#000000',color:'#aaff7f'}"
      :header-cell-style="{padding: '0',background:'#000000',color:'#9d9dea',fontSize: '16px'}"
    >
      <el-table-column
        prop="date"
        label="日期"
        width="100"
        align="center">
      </el-table-column>
      <el-table-column
        prop="number.number"
        label="对象编号"
        width="100"
        align="center">
      </el-table-column>
      <el-table-column
        prop="content"
        label="内容"
        width="180"
        align="center">
      </el-table-column>
    </el-table>
  </div>
</template>
//echats和axios
<script>
export default {
  data() {
    return {
      append: [],
      total: [],
      categories: [],
      numberdata: []
    }
  },
  created() {
  },
  mounted() {
    this.drawech()
  },
  methods: {
    //图表制作
    drawech() {
      let myChart = this.$echarts.init(document.getElementById('number'))
      this.$axios.get('/api/supervision/company')
        .then(response => {
          this.numberdata = response.data
          var a = []
          for (var i = 0; i < this.numberdata.length; i++) {
            a.push(this.numberdata[i].createyear)
          }
          var b = []
          var c = []
          var d = []
          var e = []
          for (var i = 0; i < a.length; i++) {
            if (a[i] < 2005) {
              b.push(a[i])
            }
            if (a[i] > 2005 && a[i] <= 2010) {
              c.push(a[i])
            }
            if (a[i] > 2010 && a[i] <= 2015) {
              d.push(a[i])
            }
            if (a[i] > 2015) {
              e.push(a[i])
            }
          }
          this.categories = [2010, 2015, '至今']
          this.append = [c.length, d.length, e.length]
          this.total = [b.length + c.length, b.length + c.length + d.length, b.length + c.length + d.length + e.length]
          let option = {
            tooltip: {
              trigger: 'axis',
              backgroundColor: 'rgba(255, 255, 255, 0.75)',
              axisName: {
                color: '#ffffff',
                fontSize: 10
              },
              formatter: '{b}(年)<br/>现有企业总数:{c0}个<br/>新增企业数量:{c1}个'
            },
            legend: {
              itemHeight: 10,
              itemWidth: 15,
              itemGap: 1,
              textStyle: {
                color: '#E9EEF3',
                fontSize: 10
              },
              lineStyle: {
                width: 3,
                height: 100
              },
              orient: 'vertical',
              bottom: 'bottom'
            },
            grid: {
              containLabel: true,
              bottom: '8%',
              right: '2%',
              left: '2%',
              top: '5%',
            },
            xAxis: {
              axisTick: {
                show: false
              },
              type: 'category',
              axisLabel: {
                axisName: {
                  color: '#E9EEF3',
                  fontSize: 10
                },
                margin: 2
              },
              axisLine: {
                lineStyle: {
                  color: '#E9EEF3',
                  width: 1,
                }
              },
              data: this.categories
            },
            yAxis: {
              axisTick: {
                show: false
              },
              type: 'value',
              axisLabel: {
                axisName: {
                  color: '#E9EEF3',
                  fontSize: 10
                },
                margin: 2
              },
              splitLine: {
                show: true,  //去掉网格线
                lineStyle: {
                  color: '#E9EEF3',
                  width: 0.5,
                  type: 'dotted'
                }
              },
              axisLine: {
                show: true,
                lineStyle: {
                  color: '#E9EEF3',
                  width: 1,
                }
              }
            },
            series: [{
              data: this.total,
              type: 'bar',
              name: '现有总数',
              barWidth: 20, //设置圆柱体的宽度
              itemStyle: {
                color: new this.$echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                  offset: 0,
                  color: '#4729FB' // 0% 处的颜色
                }, {
                  offset: 0.5,
                  color: '#3077F7' // 50% 处的颜色
                }, {
                  offset: 1,
                  color: '#1FB0F4' // 100% 处的颜色
                }], false)
              },
              // barGap: 0
            },
              {
                data: this.append,
                type: 'bar',
                name: '新增数量',
                barWidth: 20, //设置圆柱体的宽度
                itemStyle: {
                  color: new this.$echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                    offset: 0,
                    color: "#b67900" // 0% 处的颜色
                  }, {
                    offset: 0.5,
                    color: "#e19600" // 50% 处的颜色
                  }, {
                    offset: 1,
                    color: "#ffaa00" // 100% 处的颜色
                  }], false)
                },
                // barGap: 0
              },
            ]
          }
          window.onresize = myChart.resize
          myChart.setOption(option)
        })
        .catch(function (error) {
          console.log(error)
        })
    }
  }
}
</script>

上一章:第四章:Django绑定数据库并发布数据-[基于Vue、Django、supermap iserver和gerapy的生态旅游web系统开发实例]

下一章-第六章:vue配置supermap iserver及地图发布-[基于Vue、Django、supermap iserver和gerapy的生态旅游web系统开发实例]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值