CostHistogram.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-10-12 09:10:42
  4. * @LastEditTime: 2021-11-28 17:16:27
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 成本分析的柱状图
  7. * @FilePath: \hyyfClient\src\views\PdcData\analysis\CostHistogram.vue
  8. -->
  9. <template>
  10. <div class="cost-histogram">
  11. <div id="costHistogram"></div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. data: {
  18. type: Array,
  19. default: () => [],
  20. },
  21. xAxisData: {
  22. type: Array,
  23. default: () => [],
  24. },
  25. },
  26. data() {
  27. return {
  28. myChart: null,
  29. };
  30. },
  31. methods: {
  32. init() {
  33. const commonSeriesItem = {
  34. name: "Forest",
  35. type: "bar",
  36. barGap: 0,
  37. emphasis: {
  38. focus: "series",
  39. },
  40. };
  41. let seriesData = [
  42. {
  43. ...commonSeriesItem,
  44. name: "公摊成本",
  45. color: "rgb(112,182,3)",
  46. data: [],
  47. },
  48. {
  49. ...commonSeriesItem,
  50. name: "兽药成本",
  51. color: "rgb(232,56,92)",
  52. data: [],
  53. },
  54. {
  55. ...commonSeriesItem,
  56. name: "饲料成本",
  57. color: "rgb(123,0,255)",
  58. data: [],
  59. },
  60. ];
  61. this.data.forEach((item) => {
  62. seriesData[0].data.push(item.gtValue);
  63. seriesData[1].data.push(item.syValue);
  64. seriesData[2].data.push(item.slValue);
  65. });
  66. let options = {
  67. // title: {
  68. // text: '存栏变动',
  69. // x: 10,
  70. // y: 0
  71. // },
  72. tooltip: {
  73. trigger: "axis",
  74. // formatter: (value) => {
  75. // return value + "元";
  76. // },
  77. },
  78. // legend: {
  79. // data: ['头']
  80. // },
  81. // color: ['#3aa0ff', '#4dcb73', '#fad337', '#f2637b', '#975fe4'],
  82. grid: {
  83. left: "3%",
  84. right: "4%",
  85. bottom: "3%",
  86. containLabel: true,
  87. },
  88. xAxis: [
  89. // {
  90. // type: "value",
  91. // name: "元",
  92. // boundaryGap: [0, 0.01],
  93. // axisPointer: {
  94. // type: "shadow",
  95. // },
  96. // axisLine: {
  97. // show: true,
  98. // lineStyle: {
  99. // color: "#6e7079",
  100. // },
  101. // },
  102. // axisTick: {
  103. // show: false,
  104. // },
  105. // },
  106. {
  107. type: "category",
  108. axisTick: {
  109. show: false,
  110. },
  111. axisPointer: {
  112. type: "none",
  113. },
  114. data: this.xAxisData,
  115. },
  116. ],
  117. //[
  118. yAxis: {
  119. // type: "category",
  120. // inverse: true,
  121. // axisLabel: {
  122. // // formatter: '{value} °C'
  123. // show: true
  124. // },
  125. // axisLine: {
  126. // show: true,
  127. // lineStyle: {
  128. // color: '#6e7079',
  129. // }
  130. // },
  131. // axisTick:{
  132. // show:false
  133. // },
  134. // splitLine:{
  135. // show:false
  136. // }
  137. type: "value",
  138. name: "元",
  139. },
  140. // {
  141. // type: 'value',
  142. // name: '湿度',
  143. // axisLabel: {
  144. // formatter: '{value} RH'
  145. // },
  146. // axisLine: {
  147. // show: false,
  148. // lineStyle: {
  149. // color: '#6e7079',
  150. // }
  151. // },
  152. // axisTick:{
  153. // show:false
  154. // },
  155. // // splitLine:{
  156. // // show:false
  157. // // }
  158. // }
  159. //],
  160. // dataset: [
  161. // {
  162. // dimensions: ['num'],
  163. // source: [
  164. // [32541],
  165. // [82467],
  166. // [54363],
  167. // [64642],
  168. // [40257],
  169. // [95422]
  170. // ]
  171. // },
  172. // {
  173. // transeform: {
  174. // type: 'sort',
  175. // config: {
  176. // dimension: 'num',
  177. // order: 'desc'
  178. // }
  179. // }
  180. // }
  181. // ],
  182. series: seriesData,
  183. };
  184. const _this = this;
  185. this.myChart.setOption(options);
  186. this.myChart.on("click", function(param) {
  187. _this.$emit("changeCostIndex", param.dataIndex);
  188. });
  189. },
  190. },
  191. mounted() {
  192. this.myChart = this.$echarts.init(document.getElementById("costHistogram"));
  193. // this.init();
  194. },
  195. watch: {
  196. data(value) {
  197. console.log("成本分析柱状图数据", value);
  198. this.init();
  199. },
  200. },
  201. };
  202. </script>
  203. <style scoped>
  204. .cost-histogram {
  205. display: inline-block;
  206. width: 90%;
  207. height: 300px;
  208. }
  209. #costHistogram {
  210. width: 100%;
  211. height: 100%;
  212. }
  213. </style>