赞
踩
(1)series中data置空,数据从后端获取
(2)其他界面设置信息在前端写定
1)推荐使用ref
(2)chart指向ref, 初始化视图
(3) 向后端发送请求获取数据
每次数据更改都需要执行setOption()操作
(4)执行初始化数据
(5)在mounted()中执行
(1)不推荐使用id绑定DOM,使用ref
(2)this.nextTick()
(3)初始化视图和数据的顺序
(4)数据更改后setOption()
<template> <div> <div ref="myChart" class="containEcharts"></div> </div> </template> <script> let baseURL = "http://localhost:8888"; import { optionThird } from "../../../../static/staticData/options"; export default { name: "echartsCloud", data() { return { chart: null }; }, mounted() { this.$nextTick(function() { this.initView(); this.initData(); }); }, methods: { initData() { this.selectEchartsCloud(); }, initView() { this.chart = this.$echarts.init(this.$refs.myChart); }, // 查询云词 selectEchartsCloud() { this.$http({ url: baseURL + "/echartsCloud/selectEchartsCloud", methods: "post" }) .then(response => { optionThird.series[0].data = response.data; console.log(optionThird); this.chart.setOption(optionThird); }) .catch(function(error) { console.log(error); }); } } }; </script> <style scoped> .containEcharts { float: left; width: 550px; height: 250px; border: 1px solid #eee; border-radius: 5%; } </style>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。