ChartCostLine.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-10-26 17:53:37
  4. * @LastEditTime: 2021-11-29 09:29:48
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 成本分析柱状图
  7. * @FilePath: \hyyfScreen\src\views\Production\board\ChartCostLine.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(0,215,233)",
  52. data: [],
  53. },
  54. {
  55. ...commonSeriesItem,
  56. name: "饲料成本",
  57. color: "rgb(255,255,160)",
  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. axisLine: {
  115. show: true,
  116. lineStyle: {
  117. color: "#fff",
  118. },
  119. },
  120. data: this.xAxisData,
  121. },
  122. ],
  123. //[
  124. yAxis: {
  125. // type: "category",
  126. // inverse: true,
  127. // axisLabel: {
  128. // // formatter: '{value} °C'
  129. // show: true
  130. // },
  131. // axisLine: {
  132. // show: true,
  133. // lineStyle: {
  134. // color: '#6e7079',
  135. // }
  136. // },
  137. axisTick: {
  138. show: false,
  139. },
  140. // splitLine:{
  141. // show:false
  142. // }
  143. axisLine: {
  144. show: true,
  145. lineStyle: {
  146. color: "#fff",
  147. },
  148. },
  149. type: "value",
  150. name: "元",
  151. },
  152. // {
  153. // type: 'value',
  154. // name: '湿度',
  155. // axisLabel: {
  156. // formatter: '{value} RH'
  157. // },
  158. // axisLine: {
  159. // show: false,
  160. // lineStyle: {
  161. // color: '#6e7079',
  162. // }
  163. // },
  164. // axisTick:{
  165. // show:false
  166. // },
  167. // // splitLine:{
  168. // // show:false
  169. // // }
  170. // }
  171. //],
  172. // dataset: [
  173. // {
  174. // dimensions: ['num'],
  175. // source: [
  176. // [32541],
  177. // [82467],
  178. // [54363],
  179. // [64642],
  180. // [40257],
  181. // [95422]
  182. // ]
  183. // },
  184. // {
  185. // transeform: {
  186. // type: 'sort',
  187. // config: {
  188. // dimension: 'num',
  189. // order: 'desc'
  190. // }
  191. // }
  192. // }
  193. // ],
  194. series: seriesData,
  195. };
  196. const _this = this;
  197. this.myChart.setOption(options);
  198. this.myChart.on("click", function(param) {
  199. _this.$emit("changeCostIndex", param.dataIndex);
  200. });
  201. },
  202. },
  203. mounted() {
  204. this.myChart = this.$echarts.init(document.getElementById("costHistogram"));
  205. // this.init();
  206. },
  207. watch: {
  208. data(value) {
  209. console.log("成本分析柱状图数据", value);
  210. this.init();
  211. },
  212. },
  213. };
  214. </script>
  215. <style scoped>
  216. .cost-histogram {
  217. width: 90%;
  218. height: 50%;
  219. }
  220. #costHistogram {
  221. width: 100%;
  222. height: 100%;
  223. }
  224. </style>