echarts实现数据可视化

1.在全局安装echarts

cnpm install echarts -S

2.全局引用

import echarts from 'echarts'
Vue.prototype.$echarts = echarts;

3.使用$echarts.init

<div style='width:800px;height=800px' red="chart"></div>

let myChart = this.$echarts.init(this.$refs.chart);    使用ref设置   $refs获取图表设置的位置并进行初始化 
//this.chart = this.$echarts.init(document.getElementById(this.id))

4.获取数据

let option = ...;  //数据的设置
myChart.setOption(option);

5.将图表挂载到页面上

 mounted() {
    this.init()
  },

6.主题的使用

//下载主题存为theme.js文件

//在使用echarts页面引入该文件
import {theme} from './Theme.js'

//在初始化组件时设置主题
let myChart = this.$echarts.init(this.$refs.chart,'macarons');

:legend="[‘零售额’,‘零售量’]"

<el-card>
	<template slot="header">
		{{ user.county }} 网络零售重点行业排名
	</template>
	<el-table :data="tableData" class="line2-table">
		<el-table-column label="行业" prop="industry"></el-table-column>
		<el-table-column label="零售额占比" prop="amountRate">
			<template v-slot="scope">
				{{ scope.row.amountRate !== null ?scope.row.amountRate+'%':'-' }}
			</template>
		</el-table-column>
		<el-table-column label="零售量占比" prop="countRate">
			<template v-slot="scope">
				{{ scope.row.countRate !== null ?scope.row.countRate+'%':'-' }}
			</template>
		</el-table-column>
	</el-table>
</el-card>

legend:图例

mixins:[resize];

.map() ==> 返回一个新的数组 pieData

.forEach() ==> 遍历数组,没有返回值

//PieData的处理:
if (temp && temp.name && temp.name.length) {
    let total = 0
    temp.value.forEach(item => { total = total + item })     //遍历数组计算总数

    this.pieData = temp.name.map((item, index) => {
        return {
            name: item,
            value: (temp.value[index] / total * 100).toFixed(2)       //求出各部分的占比
        }
    })

    this.pieBar = temp ? [temp.name, temp.value] : null
}

tooltip设置

tooltip: {
    formatter (params) {
        return params.seriesName + '<br>' + params.marker + params.name + ':' + params.data.value + '%'
    }
},  //hover时提示的信息   

watch – 用来监测Vue实例上的数据变动。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值