在这里插入图片描述

<div ref="myChart" :style="{width: '800px', height: '500px'}"></div>
methods:{
	showEcharts(){
              // 基于准备好的dom,初始化echarts实例
              let myChart = this.$echarts.init(this.$refs.myChart);
              // 绘制图表
              myChart.setOption({
            	legend: {
                   selectedMode: true,//可点击
                   data: ['注册用户',  '累计用户量'],
                   bottom: 0	
               },
               grid: {
                   left: 100
               },
               xAxis: [
                   {
                       type: 'category',
                       data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
                       splitLine: {//不显示分割线
                           show: false
                       }
                   }

               ],
               yAxis: [
                   {
                       type: 'value',
                       name: '注册用户',
                       splitLine: {//显示分割线
                           show: true
                       }
                   },
                   {
                       type: 'value',
                       name: '累计用户量',
//	                        axisLabel: {
//	                            formatter: '{value} °C'
//	                        },
                       splitLine: {
                           show: true
                       }
                   }
               ],
               series: [
                   {
                       name: '注册用户',
                       type: 'bar',
                       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],
                       itemStyle: {
          					color:'rgba(132, 136, 211, 1)'
          				}
                   },
                   {
                       name: '累计用户量',
                       type: 'line',
                       yAxisIndex: 1,//索引从0开始
                       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],
                       itemStyle: {
                       	color:'rgba(91, 245, 204, 1)'
                       }
                   }
               ]
              });
                //建议加上以下这一行代码,不加,当浏览器窗口缩小时,echarts显示不全。
                window.addEventListener('resize', function() {
					myChart.resize()
				});              			
	}			
},		
Logo

前往低代码交流专区

更多推荐