vertival-bar-line-chart.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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: ["#05bb4c", "#4b55ae", "#e17e23", "#02BB4C", "#EDB32F", "#EDEB2F"],
  55. // color: ["#323E6F", "#1DA0D7", "#02BB4C", "#DB5520", "#EDB32F", "#EDEB2F"],
  56. };
  57. },
  58. methods: {
  59. initChart() {
  60. let option = {
  61. color: this.color,
  62. grid: {
  63. left: 40,
  64. right: 16,
  65. bottom: 16,
  66. top: 40,
  67. containLabel: true,
  68. },
  69. tooltip: {
  70. trigger: "item",
  71. backgroundColor: "rgba(0,0,0,0.4)",
  72. textStyle: {
  73. color: "#fff",
  74. fontSize: util.vh(16),
  75. },
  76. formatter: function(param) {
  77. return param.name + "<br >" + param.marker + param.seriesName + ":" + param.value;
  78. },
  79. },
  80. xAxis: [
  81. {
  82. type: "category",
  83. axisLabel: {
  84. color: partten.getColor("gray"),
  85. },
  86. axisLine: {
  87. show: false,
  88. },
  89. axisTick: {
  90. show: false,
  91. },
  92. data: this.bardata.area,
  93. },
  94. ],
  95. yAxis: [
  96. {
  97. type: "value",
  98. name: this.units[0],
  99. axisLabel: {
  100. formatter: "{value} ",
  101. color: partten.getColor("gray"),
  102. },
  103. axisLine: {
  104. type: "dashed",
  105. lineStyle: {
  106. color: partten.getColor("gray"),
  107. },
  108. width: 5,
  109. },
  110. axisTick: {
  111. show: false,
  112. },
  113. splitLine: {
  114. lineStyle: {
  115. type: "dashed",
  116. dashOffset: 10,
  117. color: partten.getColor("gray") + 80,
  118. },
  119. },
  120. },
  121. {
  122. type: "value",
  123. name: this.units[1],
  124. axisLabel: {
  125. formatter: "{value} ",
  126. color: partten.getColor("gray"),
  127. align: "left",
  128. },
  129. axisLine: {
  130. show: false,
  131. },
  132. axisTick: {
  133. show: false,
  134. },
  135. splitLine: {
  136. show: false,
  137. },
  138. },
  139. ],
  140. series: [],
  141. };
  142. if (this.lineData.length > 0)
  143. option.series.push({
  144. name: this.units[0],
  145. type: "line",
  146. data: this.lineData,
  147. smooth: false, //平滑展示
  148. yAxisIndex: 0,
  149. lineStyle: {
  150. // color: partten.getColor("green"),
  151. color: '#323E6F'
  152. },
  153. itemStyle: {
  154. // color: partten.getColor("green"),
  155. color: '#323E6F'
  156. },
  157. });
  158. for (var i = 0; i < this.bardata.legend.length; i++) {
  159. option.series.push({
  160. name: this.bardata.legend[i],
  161. type: "bar",
  162. stack: "总量",
  163. yAxisIndex: 1,
  164. // barWidth: "60%",
  165. label: {
  166. show: false,
  167. position: "insideRight",
  168. },
  169. data: this.bardata.data[i],
  170. });
  171. }
  172. this.chart.setOption(option);
  173. },
  174. },
  175. created() {
  176. this.id = "pie-chart-" + util.newGUID();
  177. },
  178. mounted() {
  179. this.$nextTick(() => {
  180. this.$el.style.width = this.width;
  181. this.$el.style.height = this.height;
  182. this.chart = echarts.init(this.$el);
  183. this.initChart();
  184. });
  185. },
  186. updated() {
  187. this.initChart();
  188. },
  189. };
  190. </script>
  191. <style lang="less">
  192. .chart {
  193. width: 100%;
  194. height: 100%;
  195. display: inline-block;
  196. }
  197. </style>