首页 > 其他分享 >vue 中安装并使用echart

vue 中安装并使用echart

时间:2023-01-06 00:14:47浏览次数:35  
标签:vue echart lib component import 安装 echarts 加载

本文为博主原创,转载请注明出处:

1.安装echart 依赖:

  安装命令: 

npm install echarts --save

  在vscode 的终端窗口进行执行,如图所示:

   执行完之后,查看 项目中的echart 版本依赖是否添加成功:

  package-lock.json 中有具体的echart 依赖信息:

             

   package.json 的  dependencies 中有 echart 的依赖

                           

2. 在页面中使用echart:

  在vue 页面中 定义绑定的 标签元素

<div style="width:1200px;height:300px" ref="chart"></div>

  引入echart 依赖:

// 引入基本模板
import echarts from “echarts/lib/echarts”;

//引入环形图
import “echarts/lib/chart/bar”;
//引入折现图
import “echarts/lib/chart/line”;
// 引入提示框组件、标题组件、工具箱组件。
import “echarts/lib/component/tooltip”;
import “echarts/lib/component/title”;
import “echarts/lib/component/legend”;

  在method 中定义加载的参数:


 methods: {
   initCharts () {
        let myChart = echarts.init(this.$refs.chart);
        // 绘制图表
        myChart.setOption({
          //此处插入echart实例中的option内部内容
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: [1500, 2300, 2240, 2180, 1350, 1470, 2600],
            type: 'line'
          }
        ]

          });
      },
}

3. 在 mounted 函数中定义加载

 mounted() {
    this.initCharts();
  },

  需要注意的是,不可放在 create 中去加载图表,放在create 中会出现dom元素还没有加载结束就进行图表挂在,会报 dom 不存在的异常

4. 加载示例

 

标签:vue,echart,lib,component,import,安装,echarts,加载
From: https://www.cnblogs.com/zjdxr-up/p/17029220.html

相关文章

  • django-1.1环境安装
    环境安装1.创建虚拟环境mkvirtualenvdjango_py3_1.11-ppython3注意需要联网2.安装Django使用django1.11.11版本,注意需要联网pipinstalldjango==1.11.113.......
  • vue项目的起手
    vue-cil的安装npminstall-g@vue/cli创建一个vue项目vuecreatehelloword运行vue项目cdhellowordnpmrunserve安装element-uinpmielement-ui-Sel......
  • docker 安装nacos(未完成)
    1、创建nacos数据库sql语句在下面dockerrm-fnacosdockerpullnacos/nacos-server:1.3.1dockerrun-d-p8848:8848-p9848:9848\--namenacos\--envMODE=s......
  • jmeter-插件安装
    去官网下载插件https://jmeter-plugins.org/install/Install/参照https://www.cnblogs.com/hcx990214/p/16637150.html......
  • docker 安装mysql
    1、dockerrm-fmysqlmkdir-p/root/cloud/mysql/logmkdir-p/root/cloud/mysql/datamkdir-p/root/cloud/mysql/confcd/root/cloud/mysql/conf/vimy.cnf[......
  • Linux下安装Jdk
    Linux下安装Jdk安装包下载JDK各版本下载地址:JDK下载地址java-8u202安装包:点击下载开始安装在Linux中安装jdk非常简单,只需将对应的安装包解压到需要安装的目录即可。#......
  • Windows安装pytorch
    新手第一次安装,记录自己安装经过。1.安装anaconda直接在anaconda官网上选择相应版本安装包安装即可。anaconda自带python,为避免和已有python冲突,可将已有......
  • 树莓派系统烧录安装
    系统烧录先格式化,格式化后要重新插拔一下,之后选择系统烧录官网下载镜像https://www.raspberrypi.com/software/operating-systems/使用ImageWriter烧录系统开启ssh......
  • linux 下 mongodb 安装
    linux下mongodb安装地址https://www.mongodb.com/try/download/community选择版本和环境需要下载2个包,mongod和shellpackage选择service复制链接,再选择sh......
  • Camille:隐私合规检测工具-安装
     清单:Mac系统、夜神模拟器3.8.5.7、安卓7.1、X86架构、frida-server-16.0.8-android-x86。--------mac安装frdia的版本和模拟器安装的frida版本要一致。 模拟器开启d......