首页 > 其他分享 >Vue2 下 Echarts的使用

Vue2 下 Echarts的使用

时间:2022-10-05 16:59:01浏览次数:55  
标签:option data Echarts VueEcharts Vue2 使用 组件 type echarts

Vue2 下 Echarts的使用

1、安装组件

npm install echarts vue-echarts --save

2、使用

2.1、配置为全局组件方式

全局配置为公有组件

// main.js
import "echarts"
import VueEcharts from "vue-echarts"

Vue.component("VueEcharts",VueEcharts)
<template>
	<VueEcharts :option="option" style="width:500px;height:400px"></VueEcharts>
</template>
<script>
	export default {
        data(){
            return {
                option:{}
            }
        },
        methods:{
            getList(){
                //
                this.axios.get(".....").then(res=>{
                    const d = res.data;
                    this.option = {
                        xAxis: {
                                type: 'category',
                                data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                              },
                              yAxis: {
                                type: 'value'
                              },
                              series: [
                                {
                                  data: [120, 200, 150, 80, 70, 110, 130],
                                  type: 'bar'
                                }
                              ]
                   }
                })
            }
        }
    }
</script>

2.2、一般页面使用方式

先引用组件,再注册,之后用标签(子组件)方式来使用

<template>
	<VueEcharts :option="option" style="width:500px;height:400px"></VueEcharts>
</template>
<script>
    // 引入Echarts组件
    import "echarts"
	import VueEcharts from "vue-echarts"
	export default {
        // 注册组件
        components: {
            VueEcharts,
        },
        data(){
            return {
                option:{}
            }
        },
        methods:{
            getList(){
                //
                this.axios.get(".....").then(res=>{
                    const d = res.data;
                    this.option = {
                        xAxis: {
                                type: 'category',
                                data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                              },
                              yAxis: {
                                type: 'value'
                              },
                              series: [
                                {
                                  data: [120, 200, 150, 80, 70, 110, 130],
                                  type: 'bar'
                                }
                              ]
                   }
                })
            }
        }
    }
</script>

2.3 图表格式

通过修改 属性 option来修改图表的格式。它的格式可能参考下面的链接,动态值要结合当前程序动态生成。

3、参考链接

https://echarts.apache.org/zh/index.html

标签:option,data,Echarts,VueEcharts,Vue2,使用,组件,type,echarts
From: https://www.cnblogs.com/LaughM/p/16755824.html

相关文章

  • k8s使用Sidecar方式采集日志
    1、创建configmapvimlogstash-cm.yamlapiVersion:v1kind:ConfigMapmetadata:name:logstashconf-consulnamespace:fat-sdata:logstash.conf:|-in......
  • 使用socat代理socket
    1、安装yuminstall-ysocat2、转发TCPnohupsocatTCP4-LISTEN:30000,reuseaddr,forkTCP4:192.145.30.8:10000>>socat.log2>&1&3、转发UDPnohupsocat......
  • WPF-UI框架MahApps.Metro使用教程
    一,MahApps.Metro安装1,项目中引用“MahApps.Metro.dll”【失败】我是在网上下载了一个dll,不知道是不是版本问题,使用时一直报错2,在NuGet中安装最新版本的dll右击项目-->......
  • Git小乌龟的安装及使用
    https://www.jianshu.com/p/33108325fc871安装git2安装TortoiseGit和语言包3github官网,代码托管4代码开发流程 1切换到master分支 2获取master分支最新代码 3创建子分支 4......
  • 网页录像录音功能的实现之MediaRecorder的使用
    前面介绍了通过H5实现在网页内打开摄像头和麦克风,实现截图和图像预览的相关知识。getUserMediaAPI及HTML5调用摄像头和麦克风一个简单的demo 实现摄像头的调用及视频录......
  • 使用npm安装一些包失败了的看过来(npm国内镜像介绍)
    镜像使用方法(三种办法任意一种都能解决问题,建议使用第三种,将配置写死,下次用的时候配置还在):1.通过config命令npmconfigset://registry.npm.taobao.org(如果上面配置正确这......
  • (新人)关于我是如何使用Jeesite框架的
    第一步由于jeesite官网的源码包是在码云上的,所以咱们下载之前必须拥有自己的码云账号并且登录。第二步登录码云账号后,我们通过此链接https://jeesite.com/来到jeesite官......
  • 09_使用SDL播放PCM
    通过命令ffpay播放PCM可以使用ffplay播放《08_音频录制02_编程》中录制好的PCM文件,测试一下是否录制成功。播放PCM需要指定相关参数:ar:采样率ac:声道数f:采样格式,sam......
  • 1303_通过keyfreq统计emacs中的功能按键使用频率
    全部学习汇总:​​GreyZhang/editors_skills:SummaryforsomecommoneditorskillsIused.(github.com)​​很多人学习emacs似乎是因为看了陈斌的一年之文,我虽然不是因......
  • (JAVA)偶然看见有人在使用PropertyDescriptor,所以自己测试了一下性能
    packagecom.example.commons.test;importjava.beans.IntrospectionException;importjava.beans.PropertyDescriptor;importjava.lang.invoke.MethodHandle;importjava......