摘要:深夜学姐问我在中柱状图如何自定义顶部亮点先看效果图我们可以看到图中图表不仅有渐变色,同时柱状图顶部位置有一个不相同的顶部亮点图片接下来,我们一起来实现一下这个效果部分部分获取元素左侧名称列表号
先看效果图
我们可以看到图中图表不仅有渐变色,同时柱状图顶部位置有一个不相同的顶部亮点(图片)
接下来,我们一起来实现一下这个效果
<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+1obc3MD7qY9qbAagDqHFTKwhQkBnicIbrgyEaqy6am9uQ5Fdwnp8LfaW0FpcgX3NzvcXARy/6cAchB9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HTe/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(); };
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/122166.html
摘要:柱状图顶部数据展示柱状图自定义主题柱形图默认参数最小高度改为默认自适应柱间距离,默认为柱形宽度的,可设固定值类目间柱形距离,默认为类目间距的,可设固定值各异柱条边线柱条边线圆角,单位,默认为柱条边线线宽,单位,默认为默认自适应,水平布局为, 柱状图顶部数据展示 itemStyle: { normal: { label: { show: true ...
摘要:弄了一堆线方块和函数,感觉挺玄乎,然并卵。我们直接写个项目看看。一个比较拽的应用就是图表和游戏,我们从浅入深,先玩图表,图表我们今天说一个最简单柱状图。第三件事,数据我用的模拟,实际项目一般是后台提供。 弄了一堆线方块和函数,感觉挺玄乎,然并卵。我们直接写个项目看看。 canvas一个比较拽的应用就是图表和游戏,我们从浅入深,先玩图表,图表我们今天说一个最简单柱状图。showImg(h...
摘要:而可视化图表,则是强大功能的表现之一。效果动画效果图片显示不出来,可以到最下面找地址分析可以这个图表由轴数据条形和标题组成。这里就需要监听事件,当鼠标的位置位于柱状的面积内,触发事件。 前言 canvas 强大的功能让它成为了 HTML5 中非常重要的部分,至于它是什么,这里就不需要我多作介绍了。而可视化图表,则是 canvas 强大功能的表现之一。 现在已经有了很多成熟的图表插件都是...
阅读 2063·2021-11-24 09:39
阅读 1496·2021-10-11 10:59
阅读 2454·2021-09-24 10:28
阅读 3340·2021-09-08 09:45
阅读 1242·2021-09-07 10:06
阅读 1579·2019-08-30 15:53
阅读 2032·2019-08-30 15:53
阅读 1395·2019-08-30 15:53