ECharts 柱状图 改变柱子颜色+柱子上方显示文字与图标

左手的ㄟ右手 2021-11-08 21:10 5904阅读 0赞

ECharts,对柱状图进行一些自定义:

1.柱子颜色自定义

2.柱子上方显示文本

3.柱子上方显示图标

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3BhbnppbmE_size_16_color_FFFFFF_t_70

具体代码如下:

  1. <template>
  2. <div>
  3. <div id="main" style="width: 1000px;height:600px;"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import echarts from 'echarts'
  8. export default {
  9. name: "echart",
  10. mounted() {
  11. this.drawChart()
  12. },
  13. methods: {
  14. drawChart() {
  15. var myChart = echarts.init(document.getElementById('main'));
  16. var option = {
  17. title: {
  18. text: '柱状图'
  19. },
  20. tooltip: {
  21. trigger:'axis',
  22. axisPointer:{
  23. type:'shadow',
  24. label:true
  25. }
  26. },
  27. legend: {
  28. data:['aaa','散点图'],
  29. top:10
  30. },
  31. grid: {
  32. left: '5%',
  33. right: '5%',
  34. bottom: '5%',
  35. containLabel: true
  36. },
  37. toolbox:{
  38. show: true,
  39. feature: {
  40. magicType: {
  41. show: true,
  42. type: ['line', 'bar', 'stack']
  43. },
  44. restore: {
  45. show: true
  46. },
  47. saveAsImage: {
  48. show: true
  49. }
  50. }
  51. },
  52. xAxis: [
  53. {
  54. type: 'category',
  55. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  56. name: '月份',
  57. axisLine: {
  58. show: true,
  59. symbol: ['none', 'arrow'],
  60. symbolSize: [8, 8],
  61. symbolOffset: [0, 7],
  62. lineStyle: {
  63. color: '#333',
  64. width: 1,
  65. type: 'solid',
  66. }
  67. }
  68. }
  69. ],
  70. yAxis: {},
  71. series: [
  72. {
  73. name: 'aaa',
  74. type: 'bar',
  75. data: [5, 20, 36, 13, 16, 8,32],
  76. itemStyle:{
  77. normal:{
  78. color: function (params){
  79. var colorList = ['#7f8da9','#fec514','#db4c3c'];
  80. if(params.value>20){
  81. return colorList[2];
  82. }else if(params.value>10){
  83. return colorList[1];
  84. }else{
  85. return colorList[0];
  86. }
  87. }
  88. },
  89. },
  90. markPoint: {
  91. symbol:'circle',
  92. // symbol:'image://http://echarts.baidu.com/images/favicon.png',
  93. itemStyle:{
  94. normal:{
  95. label:{
  96. show:true,
  97. color:'#fff',
  98. formatter: function (param) {
  99. if(param.data.coord[1]>20){
  100. return '优秀'
  101. }else if (param.data.coord[1]>10){
  102. return '良好'
  103. } else {
  104. return '不达标'
  105. }
  106. // return param.name
  107. }
  108. },
  109. color:'#BD60F6'
  110. }
  111. },
  112. symbolSize:[50, 50],
  113. symbolOffset:[0,-35],
  114. data:[
  115. {name:'啦啦',coord:[0,5]},
  116. {name:'天天',coord:[1,20]},
  117. {name:'委婉',coord:[2,36]},
  118. {name:'444',coord:[3,13]},
  119. {name:'555',coord:[4,16]},
  120. {name:'寄快递',coord:[5,8]},
  121. {name:'看看',coord:[6,32]},
  122. ],
  123. },
  124. markLine: {
  125. data: [
  126. {type: 'average', name: '平均值'}
  127. ]
  128. }
  129. },
  130. ]
  131. };
  132. // 使用刚指定的配置项和数据显示图表。
  133. myChart.setOption(option);
  134. }
  135. }
  136. }
  137. </script>
  138. <style lang="scss" scoped>
  139. </style>

发表评论

表情:
评论列表 (有 0 条评论,5904人围观)

还没有评论,来说两句吧...

相关阅读