axios vue 动态date_vue结合axios动态引用echarts

父组件pie.vue

import EchartsCoponent from '@/components/EchartsComponent'

export default {

name: 'echarts',

data () {

return {

rightData:[]

}

},

mounted() {

this.bindData();

},

methods: {

bindData() {

this.$axios

.get('static/data/piedata.json')

.then(res => {

let pro = res.data;

this.$store.dispatch('axiostest', pro);

this.rightData = this.$store.state.MsgRight;

})

.catch(err => {

console.log(err);

});

}

},

components: {

EchartsCoponent

}

}

子组件EchartsComponent.vue:

// 引入echarts

import echarts from 'echarts';

export default {

name: 'EchartsComponents',

props: {

// 接收父组件传递过来的信息

chartData: {

type: Array,

default: () => []

}

},

data() {

return {};

},

methods: {

drawChart() {

const vm = this;

// 基于准备好的dom,初始化echarts实例

var myChart = echarts.init(document.getElementById(this.echarts));

// 绘制图表

let options ={

//标题设置

title: {

text: 'ECharts测试',

x: 'center',

y: 'bottom',

textStyle: {

fontSize: 16,

fontWeight: 'bolder',

color: '#999'

}

},

// 鼠标移动到图上的文字显示

tooltip: {

trigger: 'item',

formatter: '{a}
{b}: {c} ({d}%)'

},

series: [

{

name: '销量',

type: 'pie',

radius: ['50%', '65%'], //变成空心圆,分别类似于x,y

// data: [5, 20, 36, 10, 10, 20]

label: {

normal: {

show: false, //隐藏指示文字

position: 'center'

},

emphasis: {

show: true,

textStyle: {

fontSize: '15',

fontWeight: 'bold'

}

}

},

//饼图的指示线

labelLine: {

normal: {

show: false

}

},

data: this.chartData

}

]

}

myChart.setOption(options)

this.autoActive(myChart, options)

},

autoActive(chart, option) {

this.intervalFun(chart, option)

},

intervalFun(chart, option) {

let dataIndex = -1

let dataLen = option.series[0].data.length

this.interval = setInterval(() => {

chart.dispatchAction({

type: 'downplay',

seriesIndex: 0,

dataIndex

})

dataIndex = (dataIndex + 1) % dataLen

chart.dispatchAction({

type: 'highlight',

seriesIndex: 0,

dataIndex

})

}, 1000)

}

},

computed: {

echarts() {

return 'echarts' + Math.random() * 100000;

}

},

mounted: function() {

const vm = this;

vm.$nextTick(() => {

vm.drawChart();

});

},

created: () => {}

};

.xiao-ring {

float: left;

margin: 0 auto;

text-align: center;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值