elementui admin项目中使用echarts

1.引入依赖

npm install echarts --save

2.在template中写

<template>
    <div>
      <el-card>
        <div id="mychart" :style="{height:height,width:width}"></div>
      </el-card>
    </div>
</template>

3.在scrpit中导入,并使用

<script>
import * as echarts from 'echarts'
export default {
name:'echarts',
data() {
    return {
      height:'300px',
      width:'800px',
 
  }
},
methods:{
showEchart(){
      // 基于准备好的dom,初始化echarts实例
      let myChart = echarts.init(document.getElementById('mychart'))
      // 绘制图表
      myChart.setOption({
        title: {
          text: 'ECharts 入门示例'
        },
        tooltip: {},
        xAxis: {
          data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {},
        series: [
          {
            name: '销量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
          }
        ]
      });
    },
}
mounted() {
    this.showEchart()
},
}
posted @   妞妞猪  阅读(194)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示