文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Vue中如何使用echarts可视化组件

2023-06-20 18:12

关注

这篇文章将为大家详细讲解有关Vue中如何使用echarts可视化组件,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

找到脚手架项目所在地址,执行cnpm install echarts,安装echarts组件

Vue中如何使用echarts可视化组件

(E:\demo\vuepro)这是我的项目地址,vuepro为项目名

按需导入,以加快打开速度

//引入echarts组件    import echarts from "echarts"    // 引入基本模板    let echart = require('echarts/lib/echarts')    // 引入柱状图组件    require('echarts/lib/chart/bar')    // 引入提示框和title组件    require('echarts/lib/component/tooltip')    require('echarts/lib/component/title')

准备div标签 容纳报表图形

div的 id用于绑定echarts插件

 <div id="chart" > </div>

script标签的内容

//引入echarts组件    import echarts from "echarts"    // 引入基本模板    let echart = require('echarts/lib/echarts')    // 引入柱状图组件    require('echarts/lib/chart/bar')    // 引入提示框和title组件    require('echarts/lib/component/tooltip')    require('echarts/lib/component/title')            export default{                name: 'App',                data(){                  return{                     chartColumn:null                  }                },                methods:{                  initData(){                    let dt=document.querySelector("#boss")                    this.chartColumn=echart.init(dt)                    this.chartColumn.setOption(                       //Examples中的模板                    )                  }                },                mounted(){                    this.initData()                }             }

为了方便大家的使用,我在这里放一个在Vue中引入echarts可视化组件的完整模板,大家直接复制使用即可

<template>    <div id="boss" >            </div></template><script>    //引入echarts组件    import echarts from "echarts"    // 引入基本模板    let echart = require('echarts/lib/echarts')    // 引入柱状图组件    require('echarts/lib/chart/bar')    // 引入提示框和title组件    require('echarts/lib/component/tooltip')    require('echarts/lib/component/title')            export default{                name: 'App',                data(){                  return{                     chartColumn:null                  }                },                methods:{                  initData(){                    let dt=document.querySelector("#boss")                                this.chartColumn=echart.init(dt)                    this.chartColumn.setOption(                       //Examples中模板                    )                              }                },                mounted(){                    this.initData()                }             }</script><style></style>

案例:

<template>    <div id="boss" >    </div></template><script>    import echarts from "echarts"    // 引入基本模板    let echart = require('echarts/lib/echarts')    // 引入柱状图组件    require('echarts/lib/chart/bar')    // 引入提示框和title组件    require('echarts/lib/component/tooltip')    require('echarts/lib/component/title')            export default{                name: 'App',                data(){                  return{                     chartColumn:null                  }                },                methods:{                  initData(){                    let dt=document.querySelector("#boss")                    this.chartColumn=echart.init(dt)                    this.chartColumn.setOption(                    //以下为echarts可视化组件                      {                          tooltip: {                              trigger: 'axis',                              axisPointer: {            // Use axis to trigger tooltip                                  type: 'shadow'        // 'shadow' as default; can also be 'line' or 'shadow'                              }                          },                          legend: {                              data: ['Direct', 'Mail Ad', 'Affiliate Ad', 'Video Ad', 'Search Engine']                          },                          grid: {                              left: '3%',                              right: '4%',                              bottom: '3%',                              containLabel: true                          },                          xAxis: {                              type: 'value'                          },                          yAxis: {                              type: 'category',                              data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']                          },                          series: [                              {                                  name: 'Direct',                                  type: 'bar',                                  stack: 'total',                                  label: {                                      show: true                                  },                                  emphasis: {                                      focus: 'series'                                  },                                  data: [320, 302, 301, 334, 390, 330, 320]                              },                              {                                  name: 'Mail Ad',                                  type: 'bar',                                  stack: 'total',                                  label: {                                      show: true                                  },                                  emphasis: {                                      focus: 'series'                                  },                                  data: [120, 132, 101, 134, 90, 230, 210]                              },                              {                                  name: 'Affiliate Ad',                                  type: 'bar',                                  stack: 'total',                                  label: {                                      show: true                                  },                                  emphasis: {                                      focus: 'series'                                  },                                  data: [220, 182, 191, 234, 290, 330, 310]                              },                              {                                  name: 'Video Ad',                                  type: 'bar',                                  stack: 'total',                                  label: {                                      show: true                                  },                                  emphasis: {                                      focus: 'series'                                  },                                  data: [150, 212, 201, 154, 190, 330, 410]                              },                              {                                  name: 'Search Engine',                                  type: 'bar',                                  stack: 'total',                                  label: {                                      show: true                                  },                                  emphasis: {                                      focus: 'series'                                  },                                  data: [820, 832, 901, 934, 1290, 1330, 1320]                              }                          ]                      }                      //组件到此结束                    )                  }                },                mounted(){                    this.initData()                }             }</script><style></style>

显示效果:

Vue中如何使用echarts可视化组件

关于Vue中如何使用echarts可视化组件就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     807人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     351人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     314人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     433人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     221人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯