Echarts柱狀堆疊圖 最小高度不展示

設(shè)置了barMinHeight但是卻不生效
查了很久發(fā)現(xiàn)是版本的問(wèn)題
目前項(xiàng)目使用的版本是5.4.3耗帕,但是4.2.2之后的版本都有這個(gè)問(wèn)題

image.png

官網(wǎng)樣例上也有這個(gè)問(wèn)題新翎,可以從右上角更改版本號(hào)發(fā)現(xiàn)4.2.2之前的都沒(méi)有這個(gè)問(wèn)題
https://echarts.apache.org/examples/zh/editor.html?c=bar-y-category-stack&version=5.4.3&renderer=svg
image.png

遂決定用g2

<style scoped lang="less" type="text/scss">
.chart-box {
    position: relative;

    .empty-text {
        width: 100%;
        height: 100%;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        position: absolute;
        top: 0;
        left: 0;
        text-align: center;
        color: @gray-575859;
    }
}
</style>

<template>
    <div style="width:100%;height:100%"  class="chart-box">
        <div style="width:100%;height:100%" ref="chart"></div>
        <div class="empty-text" v-if="isNil(chart) && (chartLoading === false || chartLoading === 'false')">
            <div>
                <div style="text-align: center;">
                    <svg width="89" height="65" viewBox="0 0 89 65" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <g filter="url(#filter0_ddd_3337_6173)">
                            <path d="M12.5 8.5H76.5C78.7091 8.5 80.5 10.2909 80.5 12.5V48.5C80.5 50.7091 78.7091 52.5 76.5 52.5H12.5C10.2909 52.5 8.5 50.7091 8.5 48.5V12.5C8.5 10.2909 10.2909 8.5 12.5 8.5Z" fill="black"/>
                        </g>
                        <path d="M12.5 8.5H76.5C78.7091 8.5 80.5 10.2909 80.5 12.5V48.5C80.5 50.7091 78.7091 52.5 76.5 52.5H12.5C10.2909 52.5 8.5 50.7091 8.5 48.5V12.5C8.5 10.2909 10.2909 8.5 12.5 8.5Z" fill="white" stroke="#EBEDF0"/>
                        <path fill-rule="evenodd" clip-rule="evenodd" d="M22.5 18.5H66.5C67.6046 18.5 68.5 19.3954 68.5 20.5C68.5 21.6046 67.6046 22.5 66.5 22.5H22.5C21.3954 22.5 20.5 21.6046 20.5 20.5C20.5 19.3954 21.3954 18.5 22.5 18.5Z" fill="#D5D6D9"/>
                        <path fill-rule="evenodd" clip-rule="evenodd" d="M22.5 28.5H66.5C67.6046 28.5 68.5 29.3954 68.5 30.5C68.5 31.6046 67.6046 32.5 66.5 32.5H22.5C21.3954 32.5 20.5 31.6046 20.5 30.5C20.5 29.3954 21.3954 28.5 22.5 28.5Z" fill="#D5D6D9"/>
                        <path fill-rule="evenodd" clip-rule="evenodd" d="M22.5 38.5H44.2143C45.3189 38.5 46.2143 39.3954 46.2143 40.5C46.2143 41.6046 45.3189 42.5 44.2143 42.5H22.5C21.3954 42.5 20.5 41.6046 20.5 40.5C20.5 39.3954 21.3954 38.5 22.5 38.5Z" fill="#D5D6D9"/>
                        <defs>
                            <filter id="filter0_ddd_3337_6173" x="0.5" y="2.5" width="88" height="62" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
                                <feFlood flood-opacity="0" result="BackgroundImageFix"/>
                                <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
                                <feOffset dx="-1" dy="1"/>
                                <feGaussianBlur stdDeviation="3.5"/>
                                <feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.02 0"/>
                                <feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_3337_6173"/>
                                <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
                                <feOffset dx="1" dy="4"/>
                                <feGaussianBlur stdDeviation="2.5"/>
                                <feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.02 0"/>
                                <feBlend mode="normal" in2="effect1_dropShadow_3337_6173" result="effect2_dropShadow_3337_6173"/>
                                <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
                                <feOffset dy="4"/>
                                <feGaussianBlur stdDeviation="4"/>
                                <feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.02 0"/>
                                <feBlend mode="normal" in2="effect2_dropShadow_3337_6173" result="effect3_dropShadow_3337_6173"/>
                                <feBlend mode="normal" in="SourceGraphic" in2="effect3_dropShadow_3337_6173" result="shape"/>
                            </filter>
                        </defs>
                    </svg>

                </div>
                <div>暫無(wú)數(shù)據(jù)~</div>
            </div>
        </div>
    </div>
</template>

<script>
import _ from 'lodash';
import {
    numberCheckProcess,
    numFormat,
    calculateMaxIntegerValue,
    calculateMaxIntegerValue2,
    numberUnitProcess, singleSort,
} from "@/utils/utils";
import moment from "moment";

export default {
    props: {
        chartData: {
            type: Object,
            default: function () {
                return {
                    legend: ['已交付額度', '凍結(jié)額度', '當(dāng)月凈增預(yù)算', '預(yù)算執(zhí)行率'],
                    dateTime: ['2024-01', '2024-02', '2024-03', '2024-04', '2024-05', '2024-06', '2024-07'],
                    data: [
                        [310000, 300000, 290000, 300000, 350000, 400000, 410000],//已交付額度
                        [1000, 200000, 190000, 200000, 250000, 300000, 310000],//凍結(jié)額度
                        [110000, 100000, 90000, 100000, 150000, 200000, 210000],//當(dāng)月凈增預(yù)算
                        // [630000, 600000, 480000, 600000, 750000, 900000, 930000],//當(dāng)月凈增預(yù)算

                        [60, 80, 90, 20, 30, 45, 75],//預(yù)算執(zhí)行率
                    ],
                }
            }
        },
        dateFormatStyle: {
            type: String,
            default: 'MM-DD',
        },
        chartLoading: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            chart: null,
            chartInfo: null,
        }
    },
    watch: {
        splitDragWidth: {
            watch: true,
            handler() {
                this.chartResize();
            }
        },
        capacityViewContentWidth: {
            watch: true,
            handler() {
                this.chartResize();
            }
        },
        chartData: {
            immediate: true,
            handler() {
                this.chartInfo = this.chartData;
            },
        },
        option: {
            immediate: true,
            handler(option) {
                this.$nextTick(() => {
                    if (this.isNil(this.chartInfo)) {
                        // 數(shù)據(jù)為空,銷毀 echart 示例
                        try {
                            this.chart.dispose();
                        } catch (e) {
                            this.chart = null;
                        } finally {
                            this.chart = null;
                        }
                        return;
                    }
                    if (!this.isNilOrEmpty(_.get(this.chartInfo, 'data'))) {
                        // 渲染圖表
                        try {
                            this.chart.setOption(option);
                        } catch (e) {
                            this.initChart();
                        }
                    } else {
                        try {
                            this.chart.dispose();
                        } catch (e) {
                            this.chart = null;
                        } finally {
                            this.chart = null;
                        }
                    }
                });
            }
        },
    },
    computed: {
        splitDragWidth() {
            return this.$store.getters['splitDrag/splitDragWidth'];
        },
        capacityViewContentWidth() {
            return this.$store.getters['capacityViewContentWidth'];
        },
        /**
         *
         * 圖表繪制采樣:
         * 'average' 取過(guò)濾點(diǎn)的平均值
         * 'max' 取過(guò)濾點(diǎn)的最大值(本期使用)
         * 'min' 取過(guò)濾點(diǎn)的最小值
         * 'sum' 取過(guò)濾點(diǎn)的和
         *
         */
        option() {
            let color = [
                "#3F82E6",
                "#28C692",
                "#F5BD05",
            ];
            
            let legend = [];
            let xData = [];
            let series = [];
            let max1 = null;
            let max2 = null;
            if (!_.isNil(this.chartInfo)) {
                xData = this.chartInfo.dateTime;
                legend = this.chartInfo.legend;
                // 結(jié)果集二維數(shù)組
                let data = _.get(this.chartInfo, 'data', []);
                //堆疊柱狀圖
                for(let index = 0; index < (data.length - 1); index++){
                    let barEntry = {
                        name: legend[index],
                        type: 'bar',
                        stack: 'budget',
                        label: {
                            show: true,
                            formatter: (params) => numFormat(params.value)
                        },
                        barMinHeight: 15,//TODO? 最小高度不生效
                        // yAxisIndex: index,
                        // symbol: 'emptyCircle',
                        // symbolSize: 0,
                        // smooth: true,
                        // lineStyle: {
                        //     width: 1.5,
                        // },
                        // sampling: 'max',
                        data: data[index],
                        // emphasis: {
                        //     itemStyle: {
                        //         borderWidth: 4
                        //     }
                        // }
                    };
                    series.push(barEntry);                    
                }
                //折線圖
                let lineData = data[data.length-1]
                let lineEntry = {
                    name: legend[data.length-1],
                    type: 'line',
                    yAxisIndex: 1,
                    // symbol: 'emptyCircle',
                    symbolSize: 0,
                    smooth: true,
                    lineStyle: {
                        width: 1.5,
                    },
                    sampling: 'max',
                    data: lineData,
                    emphasis: {
                        itemStyle: {
                            borderWidth: 4
                        }
                    }
                };
                series.push(lineEntry);
                let stackTotalNum = this.sumArrays(data.slice(0, data.length - 1))
                max1 = calculateMaxIntegerValue(_.max(_.map(stackTotalNum, (o) => {
                    return !this.isNil(numberCheckProcess(o, true)) ? +o : Number.MIN_VALUE;
                })));

                max2 = calculateMaxIntegerValue2(_.max(_.map(data[data.length - 1], (o) => {
                    return !this.isNil(numberCheckProcess(o, true)) ? +o : Number.MIN_VALUE;
                })), 10000);
            }
            return {
                color: color,
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                    },
                },
                legend: {
                    type: 'scroll',
                    orient: 'horizontal',
                    bottom: 0,
                    itemGap: 25,
                    itemWidth: 16,
                    itemHeight: 8,
                    textStyle: {
                        fontFamily: 'PingFang SC',
                        fontStyle: 'normal',
                        fontWeight: 400,
                        fontSize: 12,
                        lineHeight: 18,
                        textAlign: 'center',
                        color: '#252626',
                    },
                    data: legend,
                },
                grid: {
                    left: 0,
                    right: 10,
                    bottom: 20,
                    top: 30,
                    containLabel: true
                },
                xAxis: [{
                    type: 'category',
                    boundaryGap: true,
                    axisLine: {
                        lineStyle: {
                            color: '#252626',
                        },
                    },
                    axisLabel: {
                        interval: 'auto',
                        showMinLabel: true,
                        showMaxLabel: true,
                        textStyle: {
                            fontFamily: 'PingFang SC',
                            fontStyle: 'normal',
                            fontWeight: 400,
                            fontSize: 12,
                            lineHeight: 18,
                            textAlign: 'center',
                            color: '#252626',
                        },
                        formatter: (param) => {
                            if (param === _.nth(xData, 0)) {
                                let year = _.nth(_.split(param, '-'), 0);
                                let date = moment(new Date(param)).format(this.dateFormatStyle);
                                return date + '\n{year| (' + year + ')}';
                            } else {
                                return moment(new Date(param)).format(this.dateFormatStyle);
                            }
                        },
                        rich: {
                            year: {
                                color: '#898A8C',
                            }
                        },
                    },
                    data: xData,
                }],
                yAxis: [
                    {
                        type: 'value',
                        position: 'left',
                        name: '元',
                        offset: 0,
                        min: 0,
                        max: max1,
                        interval: Math.ceil(max1 / 5),
                        axisLine: {
                            show: false,
                        },
                        axisTick: {
                            show: false,
                        },
                        splitLine: {
                            show: true,
                            lineStyle: {
                                color: '#CED3E0',
                                type: 'dashed',
                            },
                        },
                        axisLabel: {
                            textStyle: {
                                fontFamily: 'PingFang SC',
                                fontStyle: 'normal',
                                fontWeight: 400,
                                fontSize: 12,
                                lineHeight: 18,
                                textAlign: 'center',
                                color: color[0],
                            },
                            formatter: (value) => {
                                let data = numberUnitProcess(value, 2, true);
                                return data.data + data.unit;
                            },
                        },
                    },
                    {
                        type: 'value',
                        name: '百分比',
                        position: 'right',
                        offset: 0,
                        min: 0,
                        max: max2,
                        interval: _.round(max2 / 5, 5),
                        axisLine: {
                            show: false,
                        },
                        axisTick: {
                            show: false,
                        },
                        splitLine: {
                            show: false,
                            lineStyle: {
                                color: '#CED3E0',
                                type: 'dashed',
                            },
                        },
                        axisLabel: {
                            formatter: function(value){
                                return value + '%'
                            },
                            textStyle: {
                                fontFamily: 'PingFang SC',
                                fontStyle: 'normal',
                                fontWeight: 400,
                                fontSize: 12,
                                lineHeight: 18,
                                textAlign: 'center',
                                color: color[1],
                            },
                        },
                        formatter: (value) => {
                            let data = numberUnitProcess(value, 2, true);
                            return data.data + data.unit;
                        },
                    },
                ],
                series: series,
            };
        },
    },
    methods: {
        // 初始化圖表
        initChart() {
            if (this.chart == null) {
                // noinspection all
                this.chart = echarts.init(this.$refs.chart);
                this.chart.resize();
                this.chart.setOption(this.option);
            } else {
                try {
                    this.chart.dispose();
                } catch (e) {
                    this.chart = null;
                } finally {
                    this.chart = null;
                    this.initChart();
                }
            }
        },
        
        // 圖表 resize
        chartResize() {
            try {
                this.chart.resize();
            } catch (e) {
                this.chart = null;
            }
        },
        handleWindowFocus(event) {
            if(event.isTrusted && !_.isNil(this.chart)) {
                this.chartResize();
            }
        },

        /*
        *二維數(shù)組里每列加和
        *輸入:[
        *       [1, 2, 3],
        *       [4, 5, 6],
        *       [7, 8, 9]
        *   ]
        * 輸出:[12, 15, 18]
        */
        sumArrays(arr) {
            if (arr.length === 0) {
                return [];
            }

            // 獲取第一個(gè)子數(shù)組的長(zhǎng)度涉馅,假定所有子數(shù)組長(zhǎng)度相同
            const len = arr[0].length;

            // 初始化結(jié)果數(shù)組
            const result = new Array(len).fill(0);

            for (let i = 0; i < arr.length; i++) {
                for (let j = 0; j < len; j++) {
                    result[j] += arr[i][j];
                }
            }

            return result;
        },
        
        // 工具方法
        keys(object) {
            return _.keys(object);
        },
        get(object, key) {
            return _.get(object, key);
        },
        getDefault(object, key) {
            return _.get(object, key, '');
        },
        getDefaultDe(object, key, de) {
            return _.get(object, key, de);
        },
        nth(array, n) {
            return _.nth(array, n);
        },
        isNil(data) {
            return _.isNil(data) || _.trim(data) === '';
        },
        indexOf(data, str) {
            if (_.isNil(data) || _.trim(data) === '') {
                return -1;
            }
            return data.indexOf(str);
        },
        length(object, key) {
            let data = _.get(object, key, []);
            if (_.isNil(data) || !_.isArray(data)) {
                return 0;
            } else {
                return data.length;
            }
        },
        moment(datetime, format) {
            return moment.unix(datetime).format(format);
        },
        numFormat(num) {
            return numFormat(num);
        },
        numberCheckProcess(data, isReturnNull = true) {
            return numberCheckProcess(data, isReturnNull);
        },
        toString(data) {
            return _.toString(data);
        },
        includes(arr, item) {
            return _.includes(arr, item);
        },
        isNilOrEmpty(data) {
            return _.isNil(data) || _.trim(data) === '' || !_.isArray(data) || data.length === 0;
        },
    },
    mounted() {
        window.addEventListener('resize', this.chartResize);
        window.addEventListener('focus', this.handleWindowFocus);
    },
    beforeDestroy() {
        if (this.chart != null) {
            this.chart.dispose();
            this.chart = null;
        }
        window.removeEventListener('resize', this.chartResize);
        window.removeEventListener('focus', this.handleWindowFocus);
    }
}
</script>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子肄方,更是在濱河造成了極大的恐慌,老刑警劉巖蹬癌,帶你破解...
    沈念sama閱讀 211,817評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件权她,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡逝薪,警方通過(guò)查閱死者的電腦和手機(jī)隅要,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,329評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)董济,“玉大人步清,你說(shuō)我怎么就攤上這事÷采觯” “怎么了廓啊?”我有些...
    開封第一講書人閱讀 157,354評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)询微。 經(jīng)常有香客問(wèn)我崖瞭,道長(zhǎng),這世上最難降的妖魔是什么撑毛? 我笑而不...
    開封第一講書人閱讀 56,498評(píng)論 1 284
  • 正文 為了忘掉前任书聚,我火速辦了婚禮,結(jié)果婚禮上藻雌,老公的妹妹穿的比我還像新娘雌续。我一直安慰自己,他們只是感情好胯杭,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,600評(píng)論 6 386
  • 文/花漫 我一把揭開白布驯杜。 她就那樣靜靜地躺著,像睡著了一般做个。 火紅的嫁衣襯著肌膚如雪鸽心。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,829評(píng)論 1 290
  • 那天居暖,我揣著相機(jī)與錄音顽频,去河邊找鬼。 笑死太闺,一個(gè)胖子當(dāng)著我的面吹牛糯景,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 38,979評(píng)論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼蟀淮,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼最住!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起怠惶,我...
    開封第一講書人閱讀 37,722評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤涨缚,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后甚疟,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體仗岖,經(jīng)...
    沈念sama閱讀 44,189評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,519評(píng)論 2 327
  • 正文 我和宋清朗相戀三年览妖,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了轧拄。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,654評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡讽膏,死狀恐怖檩电,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情府树,我是刑警寧澤俐末,帶...
    沈念sama閱讀 34,329評(píng)論 4 330
  • 正文 年R本政府宣布,位于F島的核電站奄侠,受9級(jí)特大地震影響卓箫,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜垄潮,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,940評(píng)論 3 313
  • 文/蒙蒙 一烹卒、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧弯洗,春花似錦旅急、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,762評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至逃贝,卻和暖如春谣辞,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背沐扳。 一陣腳步聲響...
    開封第一講書人閱讀 31,993評(píng)論 1 266
  • 我被黑心中介騙來(lái)泰國(guó)打工潦闲, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人迫皱。 一個(gè)月前我還...
    沈念sama閱讀 46,382評(píng)論 2 360
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親卓起。 傳聞我的和親對(duì)象是個(gè)殘疾皇子和敬,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,543評(píng)論 2 349

推薦閱讀更多精彩內(nèi)容