定制网站ElementUI中使用ECharts

中使用ECharts

一、引入ECharts

2.1、直接引入echarts (安装echarts项目依赖)

npm install echarts --save
  • 1

2.2、全局引入

(定制网站我们安装完成之后,可以在main.js定制网站中全局引入 echarts)

import echarts from "echarts";Vue.prototype.$echarts = echarts;
  • 1
  • 2

2.3、我们可以将Echar封装成组件的形式,方便调用

封装在组件中:封装成 Echarts.vue 文件放在ElementUI中

<template>  <div ref="chartDom" ></div></template><script>import * as echarts from 'echarts';import debounce from "lodash/debounce";import { addListener, removeListener} from "resize-detector";export default {  props: {    option: {      type: Object,      default: ()=> {}    }  },  watch: {    // option(val) {    //   this.chart.setOption(val);    // },    option: {      handler(val) {        this.chart.setOption(val);      },      deep: true    }  },  created() {    this.resize = debounce(this.resize, 300);  },  mounted() {    this.renderChart();    addListener(this.$refs.chartDom, this.resize);  },  beforeDestroy() {    removeListener(this.$refs.chartDom, this.resize);    this.chart.dispose();    this.chart = null;  },  methods:{    resize(){      this.chart.resize();    },    renderChart() {      this.chart = echarts.init(this.$refs.chartDom);      this.chart.setOption(this.option);    }  },}</script><style></style>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52

2.4、此时我们可以通过Echart官网引入我们需要的图

Echart官网 https://echarts.apache.org/zh/index.html

例如:以所选的折柱混合图为例

引入(需要引入Echarts刚刚封装好的组件)

从Echart官网获取对应图的代码

引入代码:

<template>    <div>        <el-row>          <Echarts :option="option" style="height: 400px;width: 630px" />        </el-row>  </div></template><script>    //引入Echart的包import Echarts from "../../components/charts/Echarts";       export default {  components:{    Echarts,  },  data(){    return{      option:{  		tooltip: {    	trigger: 'axis',    	axisPointer: {      	type: 'cross',      	crossStyle: {        color: '#999'      }    }  },  toolbox: {    feature: {      dataView: { show: true, readOnly: false },      magicType: { show: true, type: ['line', 'bar'] },      restore: { show: true },      saveAsImage: { show: true }    }  },  legend: {    data: ['Evaporation', 'Precipitation', 'Temperature']  },  xAxis: [    {      type: 'category',      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],      axisPointer: {        type: 'shadow'      }    }  ],  yAxis: [    {      type: 'value',      name: 'Precipitation',      min: 0,      max: 250,      interval: 50,      axisLabel: {        formatter: '{value} ml'      }    },    {      type: 'value',      name: 'Temperature',      min: 0,      max: 25,      interval: 5,      axisLabel: {        formatter: '{value} °C'      }    }  ],  series: [    {      name: 'Evaporation',      type: 'bar',      tooltip: {        valueFormatter: function (value) {          return value + ' ml';        }      },      data: [        2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3      ]    },    {      name: 'Precipitation',      type: 'bar',      tooltip: {        valueFormatter: function (value) {          return value + ' ml';        }      },      data: [        2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3      ]    },    {      name: 'Temperature',      type: 'line',      yAxisIndex: 1,      tooltip: {        valueFormatter: function (value) {          return value + ' °C';        }      },      data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]    }  ]};  },  created: function () {  },  methods:{        }}</script><style scoped></style>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119

二、效果展示

网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发