zoukankan      html  css  js  c++  java
  • echarts设置柱状图数值在顶部,并且添加百分比,且为0时不显示

    series --> label 中添加属性 fromatter

    position: 'top'在顶部显示

     

    option = {
        legend: {
            itemWidth: 15,
            itemHeight: 4,
            fontSize: 12,
            data: ['同比', '环比'],
            right: 55,
            top: 10,
            orient: 'vertical',
    
        },
        tooltip: {},
        // 设置图标距离上下左右的距离
        grid: {
            top: 75,
            left: 10,
            right: 50,
            'auto',
            height:'auto'
        },
        xAxis: {
    
            type: 'category',
            //x轴文字配置
            axisLabel: {
                show: true,
                inside: false,
                // align:'left',
                margin: 20,
                textStyle: {
                    color: '#1a1a1a',
                    fontSize: '14'
                }
            },
            axisTick: {
                show: false
            }, //去掉x轴刻度线
            data: [],
            axisLine: {
                show: true,
                length: 2,
                lineStyle: {
                    color: "#B5B2B5"
                },
            }
        },
        yAxis: {
            //y轴不显示
            show: false,
            inverse: false, //是否反向坐标
            axisLine: {
                show: false,
            },
            // y轴刻度不显示
            axisLabel: {
                formatter: function () {
                    return "";
                }
            },
            splitLine: {
                show: false
            },
            splitArea: {
                show: false
            }
        },
        series: [{
                name: '同比',
                type: 'bar',
                barGap: '50%',
                barCategoryGap: '20%',
                barWidth: '15%',
                // stack: 'one',
                data: [],
                itemStyle: {
                    normal: {
                        label: {
                            show: true, //开启显示
                            position: 'top', //在上方显示
                            formatter: function (val) {
                                if (val.value !== 0) {
                                  return val.value+'%';
                                }  else {
                                  return '';
                                }
                              },
                            textStyle: { //数值样式
                                color: '#1a1a1a',
                                fontSize: 12
                            }
                        },
                        barBorderRadius: 100,
                        color: new echarts.graphic.LinearGradient(
                            0, 1, 0, 0,
                            [{
                                    offset: 0,
                                    color: '#f89741'
    
                                },
                                {
                                    offset: 1,
                                    color: '#fa6206'
                                }
                            ]
                        )
                    }
                },
            }, {
                name: '环比',
                type: 'bar',
                barGap: '50%',
                barWidth: '15%',
                barCategoryGap: '20%',
                data: [],
                itemStyle: {
                    normal: {
                        label: {
                            show: true, //开启显示
                            position: 'top', //在上方显
                            formatter: function (val) {
                                if (val.value !== 0) {
                                  return val.value+'%';
                                } else {
                                  return '';
                                }
                              },
                            textStyle: { //数值样式
                                color: '#1a1a1a',
                                fontSize: 12
                            }
                        },
                        barBorderRadius: 100,
                        color: new echarts.graphic.LinearGradient(
                            0, 1, 0, 0,
                            [{
                                    offset: 0,
                                    color: '#42d3f7'
                                    // color: '#0c7be3'
    
    
                                },
                                {
                                    offset: 1,
                                    //  color: '#42d3f7'
                                    color: '#0c7be3'
                                }
                            ]
                        )
                    }
                },
            },
    
        ]
    };

  • 相关阅读:
    js中箭头函数和普通函数this的区别
    jquery DOM操作(一)
    jquery选择器详细说明
    javascript 中关于function中的prototype
    html5一些容易忽略的细节
    javascript 原生得到document.Element的方法
    关于spring autowrie的5种方式
    关于FileSystemXmlApplicationContext和ClassPathXmlApplicationContext路径问题
    【Unity Shader】(十) ------ UV动画原理及简易实现
    【Unity Shader】(九) ------ 高级纹理之渲染纹理及镜子与玻璃效果的实现
  • 原文地址:https://www.cnblogs.com/cyhsmile/p/12565670.html
Copyright © 2011-2022 走看看