echarts實現(xiàn)排名柱狀圖的示例代碼
通過echarts實現(xiàn)排名柱狀圖,效果圖如下,下方是完整代碼,可以直接在echarts示例中運行。在線運行
在echarts中想要實現(xiàn)個性化的label,通常會在 formatter 中實現(xiàn),但是要想有顏色或背景色就不能用 div 了,這個時候就要借助 rich 了,首先需要在 rich 中定義變量,如例子中的 one,可以隨便定義,只要在 formatter 中使用一樣的名字就行,一定要有 "|" ,不然不會被解析,更多可移步官方富文本標(biāo)簽。
let ydata = ['上海', '北京', '深圳', '天津', '河南', '新疆', '澳門']; let xdata = [12, 13, 14, 15, 16, 17, 18]; option = { tooltip: { trigger: "axis", }, grid: { left: "80", right: "20", bottom: "20", top: "20", containLabel: false, }, xAxis: { type: "value", show: false, }, yAxis: { type: "category", data: ydata, axisLine: { show: false, }, axisTick: { show: false, }, axisLabel: { margin: 70, width: 60, align: "left", overflow: "truncate", formatter: function (value, index) { let ind = index + 1; if (ind == ydata.length) { return "{one|" + (ydata.length - index) + "} {a|" + value + "}"; } else if (ind + 1 == ydata.length) { return "{two|" + (ydata.length - index) + "} {b|" + value + "}"; } else if (ind + 2 == ydata.length) { return ( "{three|" + (ydata.length - index) + "} {c|" + value + "}" ); } if (ydata.length - index > 9) { return ( "{five|" + (ydata.length - index) + "} {d|" + value + "}" ); } return "{four|" + (ydata.length - index) + "} {d|" + value + "}"; }, rich: { a: { color: "#59c9f9", }, b: { color: "#59c9f9", }, c: { color: "#59c9f9", }, d: { color: "#59c9f9", }, // 第一名 one: { backgroundColor: "#E86452", color: "white", width: 12, height: 16, padding: [1, 0, 0, 5], borderRadius: 10, fontSize: 11, }, // 第二名 two: { backgroundColor: "#FF9845", color: "white", width: 12, height: 16, padding: [1, 0, 0, 5], borderRadius: 10, fontSize: 11, }, // 第三名 three: { backgroundColor: "#F6BD16", color: "white", width: 12, height: 16, padding: [1, 0, 0, 5], borderRadius: 10, fontSize: 11, }, // 一位數(shù) four: { backgroundColor: "rgba(0,0,0,0.15)", color: "white", width: 12, height: 16, padding: [1, 0, 0, 5], borderRadius: 10, fontSize: 11, }, // 兩位數(shù) five: { backgroundColor: "rgba(0,0,0,0.15)", color: "white", width: 16, height: 16, padding: [1, 0, 0, 1], borderRadius: 10, fontSize: 11, }, }, }, }, series: [{ type: "bar", showBackground: true, label: { show: true, position: "right", color: "rgba(0,0,0,0.45)", }, barWidth: 20, itemStyle: { color: "#5B8FF9", }, data: xdata, }, ], };
到此這篇關(guān)于echarts實現(xiàn)排名柱狀圖的示例代碼的文章就介紹到這了,更多相關(guān)echarts 排名柱狀圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Vue使用echarts繪制柱狀圖和折線圖
- vue實現(xiàn)echarts餅圖/柱狀圖點擊事件實例
- echarts柱狀圖坐標(biāo)軸內(nèi)容顯示不全的兩種解決辦法
- ECharts柱狀圖關(guān)閉鼠標(biāo)hover時的高亮樣式詳解
- echarts實現(xiàn)3d柱狀圖的2種方式舉例
- Vue使用Echarts畫柱狀圖詳解
- pyecharts如何實現(xiàn)顯示數(shù)據(jù)為百分比的柱狀圖
- 使用echarts柱狀圖實現(xiàn)select下拉刷新數(shù)據(jù)
- Python繪制柱狀圖可視化神器pyecharts
- Python可視化神器pyecharts繪制柱狀圖
相關(guān)文章
javascript對象的property和prototype是這樣一種關(guān)系
javascript對象的property和prototype是這樣一種關(guān)系...2007-03-03JavaScript仿淘寶實現(xiàn)固定右側(cè)側(cè)邊欄
這篇文章主要為大家詳細(xì)介紹了如何利用JavaScript實現(xiàn)仿淘寶固定右側(cè)側(cè)邊欄效果,文中示例代碼介紹的非常詳細(xì),感興趣的小伙伴們可以參考一下2022-03-03javascript輕量級庫createjs使用Easel實現(xiàn)拖拽效果
這篇文章主要介紹了javascript輕量級庫createjs使用Easel實現(xiàn)拖拽效果的相關(guān)資料,需要的朋友可以參考下2016-02-02