欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Echarts柱狀圖修改柱子顏色漸變及柱子圓角效果實例

 更新時間:2024年09月27日 11:02:17   作者:涼豆菌  
在ECharts中,可以通過修改series.itemStyle.normal屬性來定制柱狀圖的柱子樣式,包括圓角和背景色漸變,文中通過代碼介紹的非常詳細,需要的朋友可以參考下

前言

修改柱狀圖柱子背景色漸變和圓角,可通過修改series.itemStyle.normal.barBorderRadius屬性實現(xiàn)圓角設置,series.itemStyle.normal.color:new echarts.graphic.LinearGradient()來設置漸變色柱子。

效果圖:

代碼如下:

series: [{
    data: data,
    type: 'bar',
    barWidth: '40%',
    itemStyle: {
        normal: {
            //這里設置柱形圖圓角 [左上角,右上角,右下角,左下角]
            barBorderRadius:[5, 5, 0, 0],
            color: new echarts.graphic.LinearGradient(
                0, 1, 0, 0, [{//只要修改前四個參數(shù)就ok
                        offset: 0,
                        color: '#c6e6ca'
                    }, //柱圖漸變色
                    {
                        offset: 1,
                        color: '#45ac53'
                    }
                ]
            ),
        },            
    },
}]

附:Echarts繪制橫向柱狀圖(圓角+漸變)

圓角配置

series: [
    {
        name: '數(shù)量',
        type: 'bar',
        data: barData,
        barWidth: 14,
        itemStyle: {
            emphasis: {
                barBorderRadius: 7
            },
            normal: {
                barBorderRadius: 7
            }
        }
    }
]

漸變實現(xiàn)

設置itemStyle的color為new echarts.graphic.LinearGradient()線性漸變即可. 這個API在官方文檔里面都沒找到, 經(jīng)過測試前四個參數(shù)設置為0, 0, 1, 0可以從左到右漸變. 設置為0,0,0,1可以從上到下漸變. 第5個參數(shù)數(shù)組表示開始的顏色和結束的顏色.

itemStyle: {
    emphasis: {
        barBorderRadius: 7
    },
    normal: {
        barBorderRadius: 7,
        color: new echarts.graphic.LinearGradient(
            0, 0, 1, 0,
            [
                {offset: 0, color: '#3977E6'},
                {offset: 1, color: '#37BBF8'}

            ]
        )
    }
}

完整代碼如下

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="ECharts">
<title>Echarts繪制橫向柱狀圖(圓角+漸變)</title>
<script src="https://cdn.bootcss.com/echarts/3.5.4/echarts.min.js"></script>
</head>
<body>
<div id="main" style="width: 1000px;height:400px;"></div>
<script type="text/javascript">
     var myChart = echarts.init(document.getElementById('main'));
 
    //初始化數(shù)據(jù)
    var category = ['小王', '小李', '小趙', '小馬', '小劉', '小張', '小齊'];
    var barData = [3100, 2142, 1218, 581, 431, 383, 163];
 
    var option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'value',
            axisLine: {
                show: false
            },
            axisTick: {
                show: false
            }
        },
        yAxis: {
            type: 'category',
            data: category,
            splitLine: {show: false},
            axisLine: {
                show: false
            },
            axisTick: {
                show: false
            },
            offset: 10,
            nameTextStyle: {
                fontSize: 15
            }
        },
        series: [
            {
                name: '數(shù)量',
                type: 'bar',
                data: barData,
                barWidth: 14,
                barGap: 10,
                smooth: true,
                label: {
                    normal: {
                        show: true,
                        position: 'right',
                        offset: [5, -2],
                        textStyle: {
                            color: '#F68300',
                            fontSize: 13
                        }
                    }
                },
                itemStyle: {
                    emphasis: {
                        barBorderRadius: 7
                    },
                    normal: {
                        barBorderRadius: 7,
                        color: new echarts.graphic.LinearGradient(
                            0, 0, 1, 0,
                            [
                                {offset: 0, color: '#3977E6'},
                                {offset: 1, color: '#37BBF8'}
 
                            ]
                        )
                    }
                }
            }
        ]
    };
    myChart.setOption(option);
</script>
</body>
</html>

總結 

到此這篇關于Echarts柱狀圖修改柱子顏色漸變及柱子圓角的文章就介紹到這了,更多相關Echarts柱狀圖顏色漸變圓角內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論