美文网首页让前端飞vue. js资料集
Vue教程(五)在vue项目中使用echarts

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

作者: 凌雲木 | 来源:发表于2018-04-20 11:41 被阅读69次
    Vue上使用Echart

    1安装Echart
    cnpm install echarts --save

    PS E:\COLDDEMO\VueProject\FirstVue\myvue> 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:\COLDDEMO\VueProject\FirstVue\myvue> 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 + '<br/>' + 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:\COLDDEMO\VueProject\FirstVue\myvue> npm run dev
    > myvue@1.0.0 dev E:\COLDDEMO\VueProject\FirstVue\myvue
    > webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
    
    E:\COLDDEMO\VueProject\FirstVue\myvue\config
     95% emitting
    
     DONE  Compiled successfully in 5612ms
    

    相关文章

      网友评论

        本文标题:Vue教程(五)在vue项目中使用echarts

        本文链接:https://www.haomeiwen.com/subject/xkyakftx.html