• echarts 实现3D立体柱状图示例


    该示例有如下几个特点:

            ①实现tooltip自定义样式echarts 实现tooltip提示框样式自定义-CSDN博客

            ②数据为0时,顶部四边形不展示

            ③legend图标设置为自定义图片

    【第②也是一个难点,我没有找到其他解决办法,暂时就把color写成函数进行判断,数据为0时设置颜色透明,若有其他更好的解决办法,相互交流呀~】

    代码如下:

    1. <script>
    2. import Echart from "@/components/Echart/index.vue";
    3. import * as echarts from "echarts";
    4. export default {
    5. name: "aircraftDistributionChart",
    6. props: ["width", "height"],
    7. components: {
    8. Echart
    9. },
    10. data() {
    11. return {
    12. type: 0,
    13. options: {},
    14. xAxisData: ["机场1", "机场2"],
    15. legendData: [],
    16. seriesData: {
    17. "飞机1": [
    18. 3,
    19. 5
    20. ],
    21. "飞机2": [
    22. 4,
    23. 2
    24. ],
    25. "飞机3": [
    26. 0,
    27. 4
    28. ]
    29. },
    30. title: "飞机分布",
    31. loadingStyle: null,
    32. data: [],
    33. clientWidth: document.body.clientWidth,
    34. colorList: [
    35. {
    36. offset0: "#00FCFF",
    37. offset1: "#00A8FF",
    38. },
    39. {
    40. offset0: "#FFE8D6",
    41. offset1: "#FFA800",
    42. },
    43. {
    44. offset0: "#A1C1FF",
    45. offset1: "#654BFF",
    46. },
    47. {
    48. offset0: "#05FF00",
    49. offset1: "#EAFFD6",
    50. },
    51. {
    52. offset0: "#FFC7DB",
    53. offset1: "#FF1485",
    54. },
    55. {
    56. offset0: "#FFB8B2",
    57. offset1: "#FF7165",
    58. },
    59. {
    60. offset0: "#E8CCFF",
    61. offset1: "#AF82FB",
    62. },
    63. {
    64. offset0: "#CAF6FB",
    65. offset1: "#2DDBF0",
    66. },
    67. {
    68. offset0: "#FFF8CB",
    69. offset1: "#FFEA53",
    70. },
    71. {
    72. offset0: "#FCC2EE",
    73. offset1: "#F970D7",
    74. },
    75. ],
    76. };
    77. },
    78. mounted() {
    79. this.getData();
    80. },
    81. methods: {
    82. async getDetailInfo(e) {},
    83. async getData() {
    84. let that = this;
    85. let data = JSON.parse(JSON.stringify(this.seriesData));
    86. let tempData = Object.keys(data);
    87. this.legendData = [];
    88. this.seriesData = [];
    89. for (let i = 0; i < tempData.length; i++) {
    90. let temKey = tempData[i];
    91. let leg = {
    92. name: tempData[i],
    93. icon: "path://M 869.188 431.844 H 726.763 L 471.95 118.25 h -117.563 l 117.563 313.594 H 231.875 L 131.469 352.25 H 62 l 59.175 236.419 h 350.775 l -117.563 313.594 h 117.563 l 254.813 -313.594 h 196.031 c 16.875 0 39.2062 0 39.2062 -39.2062 c 0 -52.0875 -40.6125 -117.563 -92.8125 -117.563 Z",
    94. };
    95. let arr = [
    96. {
    97. name: temKey,
    98. type: "bar",
    99. barWidth: 16,
    100. itemStyle: {
    101. normal: {
    102. color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
    103. {
    104. //只要修改前四个参数就ok
    105. offset: 0,
    106. color: that.colorList[i].offset0,
    107. }, //柱图渐变色
    108. {
    109. offset: 1,
    110. color: that.colorList[i].offset1,
    111. },
    112. ]),
    113. barBorderRadius: [0, 0, 0, 0],
    114. opacity: "1",
    115. },
    116. },
    117. data: data[temKey],
    118. barGap: "20%",
    119. },
    120. {
    121. name: temKey,
    122. tooltip: {
    123. show: false,
    124. },
    125. type: "pictorialBar",
    126. itemStyle: {
    127. normal: {
    128. color: function (params) {
    129. if (params.value == 0) {
    130. return "rgba(255,255,255,0)";
    131. } else {
    132. return new echarts.graphic.LinearGradient(
    133. 0,
    134. 1,
    135. 0,
    136. 0,
    137. [
    138. {
    139. //只要修改前四个参数就ok
    140. offset: 0,
    141. color: that.colorList[i].offset0,
    142. }, //柱图渐变色
    143. {
    144. offset: 1,
    145. color: that.colorList[i].offset1,
    146. },
    147. ]
    148. );
    149. }
    150. },
    151. borderWidth: 1,
    152. borderColor: "rgba(0,252,255,0.6)",
    153. opacity: "1",
    154. shadowColor: "rgb(0,0,0,0.1)",
    155. shadowOffsetX: "0.5",
    156. shadowOffsetY: "0.5",
    157. },
    158. },
    159. symbol: "rect",
    160. symbolRotate: 45,
    161. symbolSize: ["12", "12"],
    162. symbolOffset: [(tempData.length - 1) * -9.5 + i * 19, "-8"],
    163. symbolPosition: "end",
    164. data: data[temKey],
    165. z: 3,
    166. },
    167. ];
    168. this.legendData.push(leg);
    169. this.seriesData = this.seriesData.concat(arr);
    170. }
    171. this.creatChart();
    172. },
    173. // 根据屏幕宽度处理数据
    174. handleWidth(data) {
    175. return ((this.clientWidth / 1920) * data).toFixed(0);
    176. },
    177. creatChart() {
    178. this.options = {
    179. tooltip: {
    180. trigger: "axis",
    181. axisPointer: {
    182. type: "shadow"
    183. },
    184. textStyle: {
    185. align: "left"
    186. },
    187. className: "custom-tooltip-box",
    188. formatter: function (params) {
    189. let tip = "";
    190. for (let i = 0; i < params.length; i++) {
    191. let a = "";
    192. a = `
    193. ${params[i].seriesName}
    194. ${params[i].value}
    195. `;
  • tip = tip + a;
  • }
  • let height = params.length * 3.3 + 5;
  • return `
    ${height}rem">
  • ${params[0].name}
    ${tip}`
    ;
  • }
  • },
  • legend: {
  • type: "scroll",
  • data: this.legendData,
  • align: "left",
  • right: 10,
  • textStyle: {
  • color: "#ffffff"
  • },
  • pageTextStyle: {
  • color: "#35ffff",
  • fontSize: this.handleWidth(12)
  • },
  • pageIconColor: "#aaa",
  • pageIconInactiveColor: "#555657",
  • textStyle: {
  • color: "#C7F1FF",
  • fontSize: this.handleWidth(12)
  • },
  • itemWidth: 20,
  • itemHeight: 20,
  • itemGap: 15,
  • // 暂时设置不能点击
  • selectedMode: false
  • },
  • grid: {
  • top: "25%",
  • left: "5%",
  • right: "5%",
  • bottom: "6%",
  • containLabel: true
  • },
  • xAxis: [
  • {
  • type: "category",
  • nameTextStyle: {
  • color: "#5C6C75"
  • },
  • offset: 6,
  • axisLine: {
  • show: true,
  • lineStyle: {
  • color: "#355d8d" // 坐标轴线线的颜色
  • }
  • },
  • splitLine: {
  • show: false
  • },
  • axisTick: {
  • show: false
  • },
  • axisLabel: {
  • show: true,
  • textStyle: {
  • color: "#fff" //X轴文字颜色
  • },
  • fontSize: "12", //x轴字体大小
  • rotate: 15
  • },
  • data: this.xAxisData
  • }
  • ],
  • yAxis: [
  • {
  • type: "value",
  • name: "单位:架",
  • nameTextStyle: {
  • fontSize: this.handleWidth(12),
  • color: "#FFFFFF99"
  • },
  • axisLabel: {
  • show: true,
  • margin: 14,
  • fontSize: 12,
  • textStyle: {
  • color: "#FFFFFF99"
  • }
  • },
  • axisTick: {
  • show: false
  • },
  • axisLine: {
  • show: false
  • },
  • splitLine: {
  • show: true,
  • lineStyle: {
  • color: "#87C2FF66",
  • width: 0.7,
  • type: "dashed"
  • }
  • }
  • }
  • ],
  • series: this.seriesData
  • }
  • }
  • }
  • };
  • script>
  • <style lang="scss" scoped>
  • .content {
  • width: 100%;
  • height: 100%;
  • margin-top: 1.5rem;
  • }
  • ::v-deep .custom-tooltip-box {
  • padding: 0 !important;
  • border: none !important;
  • background-color: transparent !important;
  • // 给子盒子自定义样式
  • .custom-tooltip-style {
  • width: 18rem;
  • min-height: 8rem;
  • background: url("../../../../assets/images/tooltip-bg-big1.png") no-repeat
  • center center;
  • background-size: 100% 100%;
  • color: #fff;
  • display: flex;
  • flex-direction: column;
  • justify-content: space-around;
  • padding: 1rem 2rem;
  • font-size: 1.4rem;
  • .span {
  • display: flex;
  • justify-content: space-between;
  • margin-top: 0.5rem;
  • :last-child {
  • font-weight: 600;
  • font-size: 1.4rem;
  • }
  • }
  • }
  • }
  • style>
  • 效果图如下:

    该示例中的属性可在官网中查阅,若有其他疑问可私信留言互相交流学习~

  • 相关阅读:
    java建材公司管理系统计算机毕业设计MyBatis+系统+LW文档+源码+调试部署
    AI对室内设计师带来哪些新的机会以及影响 优漫动游
    JAVA毕业设计102—基于Java+Springboot+vue的个人理财管理系统(源码+数据库)
    406. 根据身高重建队列
    BC范式分解问题,有没有会的朋友
    Linux中shell命令取别名
    java-php-net-python-税务局征收管理系统计算机毕业设计程序
    关于视频封装格式和视频编码格式的简介
    SpringBoot中拦截器的使用
    10. Spring源码篇之BeanPostProcessor
  • 原文地址:https://blog.csdn.net/SM_Cute/article/details/134507592