NyxhChart.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <div class="app-container-Nyxh">
  3. <div id="NyxhChart" :style="{height:height,width:width}"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import { listMonthplan } from "@/api/production/monthplan";
  8. import resize from "./mixins/resize";
  9. export default {
  10. mixins: [resize],
  11. props: {
  12. width: {
  13. type: String,
  14. default: '100%'
  15. },
  16. height: {
  17. type: String,
  18. default: '200px'
  19. },
  20. year: {
  21. type: Number,
  22. }
  23. },
  24. data() {
  25. return {
  26. //显示表格数据
  27. chartsList1: [],
  28. chartsList2: [],
  29. // 查询参数
  30. queryParams: {
  31. item: 4,
  32. year: 2020
  33. },
  34. // 获取当前年份
  35. searchFormField: {
  36. year: this.getNowTime(),
  37. },
  38. chart: null
  39. }
  40. },
  41. watch: {
  42. year(newValue, oldValue) {
  43. this.queryParams.year = newValue
  44. this.getList()
  45. }
  46. },
  47. beforeDestroy() {
  48. if (!this.chart) {
  49. return
  50. }
  51. this.chart.dispose()
  52. this.chart = null
  53. },
  54. mounted() {
  55. this.$nextTick(() => {
  56. /*this.queryParams.year = this.searchFormField.year;*/
  57. this.getList()
  58. })
  59. },
  60. methods: {
  61. getList() {
  62. listMonthplan(this.queryParams).then(response => {
  63. this.chartsList1 = response.rows[0];
  64. this.chartsList2 = response.rows[1];
  65. this.chartsList3 = response.rows[2];
  66. this.initChart()
  67. });
  68. },
  69. /** 获取当前年份 */
  70. getNowTime() {
  71. var now = new Date();
  72. var year = now.getFullYear(); //得到年份
  73. var defaultDate = `${year}`;
  74. return defaultDate;
  75. this.$set(this.searchFormField, "year", defaultDate);
  76. },
  77. initChart() {
  78. // 基于准备好的dom,初始化echarts实例
  79. this.chart = this.echarts.init(document.getElementById('NyxhChart'))
  80. this.chart.setOption({
  81. color: ['#4a7cf9', '#6be5ea', '#fff4f4'],
  82. /* 周围边距 */
  83. grid: {
  84. left: '3%',
  85. right: '3%',
  86. bottom: '1%',
  87. top: '13%',
  88. containLabel: true
  89. },
  90. /* 标识 */
  91. legend: {
  92. data: ['Energy Consumption(EU)', 'Energy Consumption(AEU)'],
  93. textStyle:{
  94. color: '#ffffff'//字体颜色
  95. },
  96. right: 5,
  97. top: -5
  98. },
  99. /* 坐标轴显示 */
  100. tooltip: {
  101. trigger: 'axis',
  102. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  103. type: 'cross',
  104. label: {
  105. backgroundColor: '#a0a0a0'
  106. }
  107. }
  108. },
  109. xAxis: {
  110. type: 'category',
  111. boundaryGap: false,
  112. data: ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","YTD","TARGET"],
  113. axisLabel: {//x轴文字的配置
  114. show: true,
  115. textStyle: {
  116. color: '#ffffff',
  117. }
  118. },
  119. axisLine: {//x轴线的颜色以及宽度
  120. show: true,
  121. lineStyle: {
  122. color: '#ffffff',
  123. width: 0,
  124. type: "solid"
  125. }
  126. },
  127. },
  128. yAxis: [
  129. {
  130. type: 'value',
  131. name: 'Unit:(tec/t.BTX)',
  132. min: 0,
  133. max: 1,
  134. interval: 0.2,
  135. axisLabel: {
  136. formatter: '{value}',
  137. textStyle: {
  138. fontSize: 10,
  139. color: '#ffffffff',
  140. margin: 15
  141. },
  142. }
  143. },
  144. {
  145. type: 'value',
  146. min: 0,
  147. max: 1,
  148. interval: 0.2,
  149. axisLabel: {
  150. formatter: '{value} %',
  151. textStyle: {
  152. fontSize: 10,
  153. color: '#ffffffff',
  154. margin: 15
  155. },
  156. }
  157. }
  158. ],
  159. series: [
  160. {
  161. name: 'Energy Consumption(EU)',
  162. type: 'line',
  163. symbolSize: 5, //折线点的大小
  164. itemStyle: {
  165. normal: {
  166. areaStyle: {
  167. color: {
  168. type: 'linear',
  169. x: 0,
  170. y: 0,
  171. x2: 0,
  172. y2: 1,
  173. colorStops: [{
  174. offset: 0, color: '#4a7cf9' // 0% 处的颜色
  175. }, {
  176. offset: 1, color: 'rgba(255,255,255,0)' // 100% 处的颜色
  177. }],
  178. globalCoord: false // 缺省为 false
  179. }
  180. },
  181. lineStyle: {
  182. width: 2// 0.1的线条是非常细的了
  183. }
  184. }
  185. },
  186. data: [this.chartsList1.jan, this.chartsList1.feb, this.chartsList1.mar, this.chartsList1.apr, this.chartsList1.may, this.chartsList1.jun, this.chartsList1.jul, this.chartsList1.aug, this.chartsList1.sep, this.chartsList1.oct, this.chartsList1.nov, this.chartsList1.dec, this.chartsList1.ytd, this.chartsList1.target]
  187. },
  188. {
  189. name: 'Energy Consumption(AEU)',
  190. type: 'line',
  191. symbolSize: 5, //折线点的大小
  192. itemStyle: {
  193. normal: {
  194. areaStyle: {
  195. color: {
  196. type: 'linear',
  197. x: 0,
  198. y: 0,
  199. x2: 0,
  200. y2: 1,
  201. colorStops: [{
  202. offset: 0, color: '#4a7cf9' // 0% 处的颜色
  203. }, {
  204. offset: 1, color: 'rgba(255,255,255,0)' // 100% 处的颜色
  205. }],
  206. globalCoord: false // 缺省为 false
  207. }
  208. },
  209. lineStyle: {
  210. width: 2// 0.1的线条是非常细的了
  211. }
  212. }
  213. },
  214. data: [this.chartsList2.jan, this.chartsList2.feb, this.chartsList2.mar, this.chartsList2.apr, this.chartsList2.may, this.chartsList2.jun, this.chartsList2.jul, this.chartsList2.aug, this.chartsList2.sep, this.chartsList2.oct, this.chartsList2.nov, this.chartsList2.dec, this.chartsList2.ytd, this.chartsList2.target]
  215. }
  216. ]
  217. })
  218. }
  219. }
  220. }
  221. </script>