重点是@open方法里使用$nextTick拿到最新的dom,在里面加载echarts
- //html
stop="getIfStorage"> -
- <el-dialog title="图表数据" :visible.sync="ifStorageShowOpen" @open="open()" width="1400px" append-to-body>
- <div id="chart" style="height: 600px" ref="chart">div>
- el-dialog>
-
-
- //data
- ifStorageShowOpen: false,
- chart: null,// echarts图表实例
-
-
- //js
- getIfStorage () {
- this.ifStorageShowOpen = true
- },
- open () {
- this.$nextTick(() => {
- this.initChart();
- })
- },
- // 初始化echarts
- initChart () {
- this.chart = this.$echarts.init(this.$refs.chart)
- // 设置图表option(配置项)绘制图表
- // 绘制图表
- this.chart.setOption({
- title: {
- text: '商品销售数据'
- },
- tooltip: {},
- xAxis: {
- data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
- },
- yAxis: {
- type: 'value'
- },
- backgroundColor: '#dddddd',
- color: ['#72ccff', '#d4a4eb'],
- series: [
- {
- name: '销量',
- type: 'bar', // 柱状图
- data: [5, 20, 36, 10, 10, 20]
- },
- {
- name: '利润',
- smooth: true,
- type: 'line', // 折线图
- data: [2, 23, 5, 54, 9, 33]
- }
- ]
- })
- },
上一篇文章,