BarChart.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div :class="className" :style="{height:height,width:width}" />
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. require('echarts/theme/macarons') // echarts theme
  7. import resize from '../mixins/resize'
  8. const animationDuration = 6000
  9. export default {
  10. mixins: [resize],
  11. props: {
  12. className: {
  13. type: String,
  14. default: 'chart'
  15. },
  16. width: {
  17. type: String,
  18. default: '100%'
  19. },
  20. height: {
  21. type: String,
  22. default: '300px'
  23. },
  24. chartData: {
  25. type: Object,
  26. required: true
  27. }
  28. },
  29. watch: {
  30. chartData: {
  31. deep: true,
  32. handler(val) {
  33. this.setOptions(val)
  34. }
  35. }
  36. },
  37. data() {
  38. return {
  39. chart: null
  40. }
  41. },
  42. mounted() {
  43. this.$nextTick(() => {
  44. this.initChart()
  45. })
  46. },
  47. beforeDestroy() {
  48. if (!this.chart) {
  49. return
  50. }
  51. this.chart.dispose()
  52. this.chart = null
  53. },
  54. methods: {
  55. initChart() {
  56. this.chart = echarts.init(this.$el, 'macarons');
  57. this.chart = echarts.init(this.$el, 'macarons')
  58. this.setOptions(this.chartData)
  59. },
  60. setOptions({ y, x ,data } = {}) {
  61. console.log(y,x,data,56)
  62. this.chart.setOption({
  63. tooltip: {
  64. trigger: 'axis',
  65. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  66. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  67. }
  68. },
  69. // 缩放问题
  70. dataZoom: [
  71. {
  72. bottom:0,
  73. type: "slider",
  74. show: true,
  75. start: 0,
  76. end: 70,
  77. handleSize: 30,
  78. zoomOnMouseWheel: true,
  79. },
  80. {
  81. type: "inside",
  82. start: 0,
  83. end: 10,
  84. }
  85. ],
  86. grid: {
  87. top: 30,
  88. left: '2%',
  89. right: '2%',
  90. bottom: 20,
  91. containLabel: true
  92. },
  93. xAxis: [{
  94. type: 'category',
  95. data: ['进口冷链食品存储、 加工类企业一线人员', '市场监管系统一线 人员(直接接触)', '市场监管系统非一线人员', '入境人员隔离点工作专班人员', '境内隔离点专班工作人员', '阳性感染着、密切 接触者等现场流调、 转运的有关工作人员', '定点医疗机构的医 护、保洁、转运司 机等工作人员',
  96. '普通医疗机构中发 热门诊的医护、保洁等工作人员','普通医疗机构除发 热门诊以外的工作人员','发热门诊患者','新住院患者、 陪护人员','医疗废弃物处理企 业的从事收运、处 理等工作人员','国际邮政快递包裹 运输、分拣装卸、 派送等二线工作人 员及快递服务点从 业人员','国内邮政快递包裹 运输、分拣装卸、 派送等一线工作人 员及快递服务点从 业人员',
  97. ],
  98. splitLine:{
  99. show:true
  100. },
  101. axisLine: {
  102. lineStyle: {
  103. color: '#9BA2B0', //x轴的颜色
  104. width:'1'
  105. },
  106. },
  107. axisLabel: {
  108. interval: 0, // 设置数据间隔
  109. formatter:function(value){
  110. var str = "";
  111. var num = 8; //每行显示字数
  112. var valLength = value.length; //该项x轴字数
  113. var rowNum = Math.ceil(valLength / num); // 行数
  114. if(rowNum > 1)
  115. {
  116. for(var i = 0; i < rowNum; i++)
  117. {
  118. var temp = "";
  119. var start = i * num;
  120. var end = start + num;
  121. temp = value.substring(start, end) + "\n";
  122. str += temp;
  123. }
  124. return str;
  125. }
  126. else
  127. {
  128. return value;
  129. }
  130. },
  131. },
  132. }],
  133. yAxis: [{
  134. type: 'value',
  135. axisTick: {
  136. show: false
  137. },
  138. axisLine: {
  139. lineStyle: {
  140. type: 'solid',
  141. color: '#9BA2B0',
  142. width:'1'
  143. }
  144. }
  145. }],
  146. series: [
  147. {
  148. type: "bar",
  149. data: [70, 150, 110, 210, 200,70, 150, 110, 210, 200,70, 150, 110, 210, 200,],
  150. barWidth: '15',
  151. itemStyle: {
  152. //这里设置柱形图圆角 [左上角,右上角,右下角,左下角]
  153. barBorderRadius:[10, 10, 10, 10],
  154. color: {
  155. x: 0, //右
  156. y: 1, //下
  157. x2: 0, //左
  158. y2: 0, //上
  159. colorStops: [{
  160. offset: 0, // 颜色的开始位置
  161. color: 'rgba(2, 197, 29, 1)' // 0% 处的颜色
  162. },
  163. {
  164. offset: 1, // 颜色的结束位置
  165. color: 'rgba(29, 233, 182, 1)' // 100% 处的颜色
  166. }
  167. ]
  168. },
  169. },}
  170. ]
  171. })
  172. }
  173. }
  174. }
  175. </script>