Echarts 之bar 柱形图

实现步骤:

一、引入Echars

npm install echarts

二、main.js中导入

// 图表--插件
import echarts from 'echarts'
 
Vue.use(echarts)
 
Vue.prototype.$echarts = echarts

三、html代码

<div id="shtBarChart" style="width:100%;height:100%"></div>

四、js代码

let titleFontSize = document.getElementById('shtBarChart').offsetWidth;
let myChart = this.$echarts.init(document.getElementById('shtBarChart'));
let option = {
    grid:{   //绘图区调整
        x:15,  //左留白
        y:10,   //上留白
        x2:15,  //右留白
        y2:10   //下留白
    },
    xAxis: {
        show:false,//隐藏x轴刻度
        splitLine:{ show: false }, //去除网格线
        axisLine: { show: false },
        axisTick: { show: false },
    },
    yAxis: {
        type: 'category',
        inverse: true,//是否排序
        splitLine:{ show: false }, //去除网格线
        axisLine: { show: false },
        axisTick: { show: false },
    },
    series: [
        {
            type: 'bar',
            barWidth: 11,
            barCategoryGap:'10%',/*多个并排柱子设置柱子之间的间距*/
            showBackground: true,//y轴背景
            label: {
                show: true,
                position:[6,-10],//设置文字显示位置
                formatter: '{b| '+'{b}'+'}'+'{c|'+'{c}'+'}',
                
                textStyle:{     //图例文字的样式
                    align:'left',
                    verticalAlign:'middle',//对齐方式
                    rich:{
                        b:{
                            fontSize:14,
                            fontWeight:700,
                            color:'#424F65',
                            width:200,//设置宽度
                        },
                        c:{
                            fontSize:14,
                            fontWeight:700,
                            color:'#00BCFF',
                            width:80,//设置宽度
                            align: 'right',//对齐方式
                            
                        },
                    },
                },
            },
            itemStyle: {
                barBorderRadius: [titleFontSize/2],//设置图形边界弧度
                color: new this.$echarts.graphic.LinearGradient(0, 0, 1, 0,
                    [
                        {offset: 0, color: '#39D7DE'},
                        {offset: 1, color: '#675AFF'}
                    ]
                ),
            },
            data: this.shPool,
        },
    ]
};
myChart.setOption(option)

显示结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值