vertival-bar-line-chart.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <div class="chart" :id="id"></div>
  3. </template>
  4. <script>
  5. import util from "@/helper/util.js";
  6. import partten from "@/helper/partten.js";
  7. import * as echarts from "echarts";
  8. export default {
  9. name: "multiple-bar-chart",
  10. componentName: "multiple-bar-chart",
  11. props: {
  12. width: {
  13. type: String,
  14. default: "100%",
  15. },
  16. height: {
  17. type: String,
  18. default: "800px",
  19. },
  20. // 传入数据
  21. bardata: {
  22. type: Object,
  23. default: () => {
  24. return {
  25. area: ["风场1", "风场2", "风场3", "风场4", "风场5", "风场6", "风场7", "风场8", "风场9"],
  26. legend: ["实际电量", "计划检修损失", "非计划检修损失", "限电损失", "受累损失", "性能损失"],
  27. data: [
  28. [1320, 1302, 901, 634, 1390, 1330, 1320, 1000, 500],
  29. [320, 302, 301, 334, 390, 330, 320, 100, 50],
  30. [320, 302, 301, 334, 390, 330, 320, 100, 50],
  31. [1320, 1302, 901, 634, 1390, 1330, 1320, 1000, 500],
  32. [320, 302, 301, 334, 390, 330, 320, 100, 50],
  33. [320, 302, 301, 334, 390, 330, 320, 100, 50],
  34. [1320, 1302, 901, 634, 1390, 1330, 1320, 1000, 500],
  35. [320, 302, 301, 334, 390, 330, 320, 100, 50],
  36. ],
  37. };
  38. },
  39. },
  40. lineData: {
  41. type: Array,
  42. default: () => [200, 350, 400, 500, 600, 700, 800, 900, 1200],
  43. },
  44. // 单位
  45. units: {
  46. type: Array,
  47. default: () => ["健康趋势", "风机健康状态数量"],
  48. },
  49. },
  50. data() {
  51. return {
  52. id: "",
  53. chart: null,
  54. color: ["#323E6F", "#1DA0D7", "#02BB4C", "#DB5520", "#EDB32F", "#EDEB2F"],
  55. };
  56. },
  57. methods: {
  58. initChart() {
  59. let option = {
  60. color: this.color,
  61. grid: {
  62. left: 40,
  63. right: 16,
  64. bottom: 16,
  65. top: 40,
  66. containLabel: true,
  67. },
  68. tooltip: {
  69. trigger: "item",
  70. backgroundColor: "rgba(0,0,0,0.4)",
  71. textStyle: {
  72. color: "#fff",
  73. fontSize: util.vh(16),
  74. },
  75. formatter: function(param) {
  76. return param.name + "<br >" + param.marker + param.seriesName + ":" + param.value;
  77. },
  78. },
  79. xAxis: [
  80. {
  81. type: "category",
  82. axisLabel: {
  83. color: partten.getColor("gray"),
  84. },
  85. axisLine: {
  86. show: false,
  87. },
  88. axisTick: {
  89. show: false,
  90. },
  91. data: this.bardata.area,
  92. },
  93. ],
  94. yAxis: [
  95. {
  96. type: "value",
  97. name: this.units[0],
  98. axisLabel: {
  99. formatter: "{value} ",
  100. color: partten.getColor("gray"),
  101. },
  102. axisLine: {
  103. type: "dashed",
  104. lineStyle: {
  105. color: partten.getColor("gray"),
  106. },
  107. width: 5,
  108. },
  109. axisTick: {
  110. show: false,
  111. },
  112. splitLine: {
  113. lineStyle: {
  114. type: "dashed",
  115. dashOffset: 10,
  116. color: partten.getColor("gray") + 80,
  117. },
  118. },
  119. },
  120. {
  121. type: "value",
  122. name: this.units[1],
  123. axisLabel: {
  124. formatter: "{value} ",
  125. color: partten.getColor("gray"),
  126. align: "left",
  127. },
  128. axisLine: {
  129. show: false,
  130. },
  131. axisTick: {
  132. show: false,
  133. },
  134. splitLine: {
  135. show: false,
  136. },
  137. },
  138. ],
  139. series: [],
  140. };
  141. option.series.push({
  142. name: this.units[0],
  143. type: "line",
  144. data: this.lineData,
  145. smooth: false, //平滑展示
  146. yAxisIndex: 0,
  147. lineStyle: {
  148. color: partten.getColor("green"),
  149. },
  150. itemStyle: {
  151. color: partten.getColor("green"),
  152. },
  153. });
  154. for (var i = 0; i < this.bardata.legend.length; i++) {
  155. option.series.push({
  156. name: this.bardata.legend[i],
  157. type: "bar",
  158. stack: "总量",
  159. yAxisIndex: 1,
  160. // barWidth: "60%",
  161. label: {
  162. show: false,
  163. position: "insideRight",
  164. },
  165. data: this.bardata.data[i],
  166. });
  167. }
  168. this.chart.setOption(option);
  169. },
  170. },
  171. created() {
  172. this.id = "pie-chart-" + util.newGUID();
  173. },
  174. mounted() {
  175. this.$nextTick(() => {
  176. this.$el.style.width = this.width;
  177. this.$el.style.height = this.height;
  178. this.chart = echarts.init(this.$el);
  179. this.initChart();
  180. });
  181. },
  182. updated() {
  183. this.initChart();
  184. },
  185. };
  186. </script>
  187. <style lang="less">
  188. .chart {
  189. width: 100%;
  190. height: 100%;
  191. display: inline-block;
  192. }
  193. </style>