vue-clii中使用echarts画折线图

一、npm安装echarts

npm install echarts --save

二、在需要的vue页面引入

 import echarts from 'echarts'

 

三、给div一个id

  <div id="areaBox" style="width: 60%;height: 60vh"> </div>

四、data里面定义

 data(){

        return{

            // 指定图表的配置项和数据

            areaBox : {

                tooltip: {              //设置tip提示

                    trigger: 'axis'

                },

                legend: {               //设置区分(哪条线属于什么)

                    data:['面积(亩)']

                },

                color: ['#00ff00'],       //设置区分(每条线是什么颜色,和 legend 一一对应)

                xAxis: {                //设置x轴

                    type: 'category',

                    boundaryGap: false,     //坐标轴两边不留白

                    data: ['高先甸', '毕武庄', '横古', '曹庄子', '将军庄', '高家围', '石桥沽',],

                    name: '村庄名称',           //X轴 name

                    nameTextStyle: {        //坐标轴名称的文字样式

                        color: '#FA6F53',

                        fontSize: 16,

                        padding: [0, 0, 0, 20]

                    },

                    axisLine: {             //坐标轴轴线相关设置。

                        lineStyle: {

                            // color: '#FA6F53',

                        }

                    }

                },

                yAxis: {

                    name: '',

                    nameTextStyle: {

                        color: '#FA6F53',

                        fontSize: 16,

                        padding: [0, 0, 10, 0]

                    },

                    axisLine: {

                        lineStyle: {

                            // color: '#FA6F53',

                        }

                    },

                    type: 'value'

                },

                series: [

                {

                    name: '面积(亩)',

                    data:  [220, 232, 201, 234, 290, 230, 220],

                    type: 'line',               // 类型为折线图

                    lineStyle: {                // 线条样式 => 必须使用normal属性

                        normal: {

                            color: '#00ff00',

                        }

                    },

                },

            ]

            },

五、methods里面定义方法

 getEcharts(){

            this.chartLineAreaBox = echarts.init(document.getElementById('areaBox'))

            // 使用刚指定的配置项和数据显示图表。

            this.chartLineAreaBox.setOption(this.areaBox)

        }

六、mounted里面调用

 this.getEcharts()

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值