摘要:深夜學姐問我在中柱狀圖如何自定義頂部亮點先看效果圖我們可以看到圖中圖表不僅有漸變色,同時柱狀圖頂部位置有一個不相同的頂部亮點圖片接下來,我們一起來實現一下這個效果部分部分獲取元素左側名稱列表號
先看效果圖
我們可以看到圖中圖表不僅有漸變色,同時柱狀圖頂部位置有一個不相同的頂部亮點(圖片)
接下來,我們一起來實現一下這個效果
<div id="ParkingLotLoadRanking" ref="ParkingLotLoadRanking" style="height:16.875rem;width:25%;">div>
// 獲取DOM元素 let myChart = echarts.init(document.getElementById("ParkingLotLoadRanking")); // 左側名稱列表 let className = ["1號停車場", "2號停車場", "3號停車場", "4號停車場", "5號停車場", "6號停車場", "7號停車場"] let data = [50, 28, 17, 38, 90, 73, 39] let serviceCount = [50, 28, 17, 38, 90, 73, 39] // 頂部亮點圖列表 在Echarts中如果想使用Base64位圖片必須在前邊加上 "image://",否則不生效 let circleList = [ "image://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAhCAYAAAC4JqlRAAAFdklEQVRYhY1YTY/bRBh+/BHbiRN7l02bqst+st1dVT0gceXABYk7PfYPwIELv4IfABJ3euuBCxKCKxckBEKi2y1F6Xa3abTZT+fLHxnbaMZje+zE3Y70aiLPzPs888w778xEin/8EO9YJKGbVDEkrvhdWdSKBumGehGJReBVdVZyApsPk/roicSdi4aKb4sUEK38jeLEHIdVRQWOnsgLgORCLWsKzFUDqlmHXEvGRzMCMnEx6XmIgpCDRaU6saMnMTYfRpmMQgzIJdCiNTebqHc6kHUbMYkQBT7ikCReFBWypkNSZUS+A/f0FOOjMSdRtlgglikgypwCK8z0FQPWzgYkpQn/8grT3jFmo0ggjMxhrSWjsWqhcXcP9c4Yo5fH8AYugFDQOSVBx8apAqkzRQBXYd1bhnF7G8HVNZznV4hDhZNWuIkEQm4EkhLC3luGtrwEb9DF8MUV+560R7xmpFXMB1kCYu+1obc3MD7qY9qbAagDqHFTKwhQkBnicIbrgyEaqy6am9uQ5Fdwnp8LfaW0F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Zt2W06Pd92G3QITY9r1PEHTe/43wHWzfk8OAP8D28XBfaJJ48oAAAAASUVORK5CYII=" ] // 設置每個狀圖顏色 var colorList = ["#FCD298", "#24FDE7", "#24FDE7", "#24FDE7", "#24FDE7", "#24FDE7", "#24FDE7"]; // 設置默認值 var defaultData = [100, 100, 100, 100, 100, 100, 100] let option = { grid: { left: "5%", right: "5%", bottom: "5%", top: "10%", containLabel: true }, backgroundColor: "rgb(49,69,81)", xAxis: { show: false, type: "value" }, yAxis: [{ type: "category", inverse: true, axisLabel: { show: true, textStyle: { color: "#B9E4E6" }, }, splitLine: { show: false }, axisTick: { show: false }, axisLine: { show: false }, data: className }, { type: "category", inverse: true, axisTick: "none", axisLine: "none", show: true, axisLabel: { textStyle: { color: "#fff", fontSize: "12" }, formatter: function (value) { return value + " %"; }, }, data: data } ], series: [{ name: "停放車輛數", type: "bar", zlevel: 1, itemStyle: { data: serviceCount, normal: { barBorderRadius: 0, color: function (params) { // 大于等于50%的是黃色 反之為藍色 var colorList = [ ["rgba(252, 210, 152, .2)", "rgba(252, 210, 152, 1)"], ["rgba(36, 253, 231, .2)", "rgba(36, 253, 231, 1)"], ]; var colorItem if (params.data >= 50) { colorItem = colorList[0]; } else { colorItem = colorList[1]; } // 設置線條漸變色 return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{ offset: 0, color: colorItem[0] }, { offset: 1, color: colorItem[1] } ], false); } }, }, barWidth: 4, data: data }, { name: "背景", type: "bar", barWidth: 4, barGap: "-100%", data: defaultData, itemStyle: { normal: { color: "#1B375E", barBorderRadius: 0, } }, }, { name: "XXX", type: "pictorialBar", symbol: function (params, value) { // 設置圖片 if (params >= 50) return circleList[0] return circleList[1] }, symbolPosition: "end", symbolSize: [30, 30], symbolOffset: [10, 0], z: 20, data: data } ] }; myChart.setOption(option); window.onresize = () => { myChart.resize(); };
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/122166.html
摘要:柱狀圖頂部數據展示柱狀圖自定義主題柱形圖默認參數最小高度改為默認自適應柱間距離,默認為柱形寬度的,可設固定值類目間柱形距離,默認為類目間距的,可設固定值各異柱條邊線柱條邊線圓角,單位,默認為柱條邊線線寬,單位,默認為默認自適應,水平布局為, 柱狀圖頂部數據展示 itemStyle: { normal: { label: { show: true ...
摘要:弄了一堆線方塊和函數,感覺挺玄乎,然并卵。我們直接寫個項目看看。一個比較拽的應用就是圖表和游戲,我們從淺入深,先玩圖表,圖表我們今天說一個最簡單柱狀圖。第三件事,數據我用的模擬,實際項目一般是后臺提供。 弄了一堆線方塊和函數,感覺挺玄乎,然并卵。我們直接寫個項目看看。 canvas一個比較拽的應用就是圖表和游戲,我們從淺入深,先玩圖表,圖表我們今天說一個最簡單柱狀圖。showImg(h...
摘要:而可視化圖表,則是強大功能的表現之一。效果動畫效果圖片顯示不出來,可以到最下面找地址分析可以這個圖表由軸數據條形和標題組成。這里就需要監聽事件,當鼠標的位置位于柱狀的面積內,觸發事件。 前言 canvas 強大的功能讓它成為了 HTML5 中非常重要的部分,至于它是什么,這里就不需要我多作介紹了。而可視化圖表,則是 canvas 強大功能的表現之一。 現在已經有了很多成熟的圖表插件都是...
閱讀 2090·2021-11-24 09:39
閱讀 1557·2021-10-11 10:59
閱讀 2501·2021-09-24 10:28
閱讀 3379·2021-09-08 09:45
閱讀 1271·2021-09-07 10:06
閱讀 1670·2019-08-30 15:53
閱讀 2065·2019-08-30 15:53
閱讀 1424·2019-08-30 15:53