栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Vue.js

Vue教程(五)在vue项目中使用echarts

Vue.js 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Vue教程(五)在vue项目中使用echarts

Vue上使用Echart

1安装Echart
cnpm install echarts --save

PS E:COLDDEMOVueProjectFirstVuemyvue> cnpm install echarts --save
√ Installed 1 packages
√ linked 1 latest versions
√ Run 0 scripts
√ All packages installed (2 packages installed from npm registry, used 7s, speed 1.41MB/s, json 2(18.66kB), tarball 9.22MB)
PS E:COLDDEMOVueProjectFirstVuemyvue> npm list echarts

2项目页面引用Echart
import echarts from 'echarts'

export default {  name: 'Home',
  mounted(){    this.SetEchart();
  },
  data () {    return {      msg: 'Welcome to 凌云木 Vue.js App'
    }
  },  methods: {
    SetEchart(){        // 基于准备好的dom,初始化echarts实例
        let myChart = this.$echarts.init(document.getElementById('myChart'))        // 绘制图表
      var   option = {    title: {        text: '郑州月最低生活费组成(单位:元)',    
    },    tooltip : {        trigger: 'axis',        axisPointer : {            // 坐标轴指示器,坐标轴触发有效
            type : 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
        },        formatter: function (params) {            var tar = params[1];            return tar.name + '
' + tar.seriesName + ' : ' + tar.value;         }     },    grid: {        left: '3%',        right: '4%',        bottom: '3%',        containLabel: true     },    xAxis: {        type : 'category',        splitLine: {show:false},        data : ['总费用','房租','水电费','交通费','伙食费','日用品数']     },    yAxis: {        type : 'value'     },    series: [         {            name: '辅助',            type: 'bar',            stack:  '总量',            itemStyle: {                normal: {                    barBorderColor: 'rgba(0,0,0,0)',                    color: 'rgba(0,0,0,0)'                 },                emphasis: {                    barBorderColor: 'rgba(0,0,0,0)',                    color: 'rgba(0,0,0,0)'                 }             },            data: [0, 1700, 1400, 1200, 300, 0]         },         {            name: '生活费',            type: 'bar',            stack: '总量',            label: {                normal: {                    show: true,                    position: 'inside'                 }             },            data:[3900, 2200, 300, 200, 900, 300]         }     ] };         myChart.setOption(option);     }   } }

3启动项目
npm run dev

PS E:COLDDEMOVueProjectFirstVuemyvue> npm run dev> myvue@1.0.0 dev E:COLDDEMOVueProjectFirstVuemyvue
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

E:COLDDEMOVueProjectFirstVuemyvueconfig 95% emitting

 DONE  Compiled successfully in 5612ms



作者:凌雲木
链接:https://www.jianshu.com/p/45c32c65417a


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/240887.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号