lineChart.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <div :class="className" :style="{height:height,width:width}" />
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts';
  6. import chartMixin from '@/mixins/ChartMixin';
  7. export default {
  8. mixins: [chartMixin],
  9. props: {
  10. className: {
  11. type: String,
  12. default: 'chart'
  13. },
  14. width: {
  15. type: String,
  16. default: '100%'
  17. },
  18. height: {
  19. type: String,
  20. default: '100%'
  21. },
  22. chartData: {
  23. type: Object,
  24. required: true
  25. }
  26. },
  27. data() {
  28. return {
  29. chart: null
  30. }
  31. },
  32. watch: {
  33. chartData: {
  34. deep: true,
  35. handler(val) {
  36. this.setOptions(val)
  37. }
  38. }
  39. },
  40. mounted() {
  41. this.$nextTick(() => {
  42. this.initChart()
  43. })
  44. },
  45. beforeDestroy() {
  46. if (!this.chart) {
  47. return
  48. }
  49. this.chart.dispose()
  50. this.chart = null
  51. },
  52. methods: {
  53. initChart() {
  54. this.chart = echarts.init(this.$el, 'macarons')
  55. this.setOptions(this.chartData)
  56. },
  57. setOptions({
  58. date,
  59. gjzs,
  60. yxgj
  61. } = {}) {
  62. this.chart.setOption({
  63. title: {
  64. text: '件',
  65. left: "12",
  66. top: 'top',
  67. textStyle: {
  68. color: "#FFFFFF",
  69. fontWeight: '400',
  70. fontSize: 12,
  71. lineHeight: 24, // 行高
  72. }
  73. },
  74. xAxis: {
  75. data: date,
  76. boundaryGap: false,
  77. axisTick: {
  78. show: false
  79. },
  80. splitLine: {
  81. show: false,
  82. lineStyle: {
  83. color: '#464D71',
  84. width: 1,
  85. type: 'solid'
  86. }
  87. },
  88. axisLabel: {
  89. color: '#fff' // 标签颜色设置为白色,增加可读性
  90. }
  91. },
  92. grid: {
  93. left: 10,
  94. right: 10,
  95. bottom: 20,
  96. top: 30,
  97. containLabel: true,
  98. },
  99. tooltip: {
  100. trigger: 'axis',
  101. axisPointer: {
  102. type: 'cross'
  103. },
  104. padding: [5, 10]
  105. },
  106. yAxis: {
  107. axisLine: {
  108. show: false //隐藏y坐标轴
  109. },
  110. axisTick: {
  111. show: false //隐藏y刻度
  112. },
  113. splitLine: {
  114. show: false,
  115. lineStyle: {
  116. color: '#464D71',
  117. width: 1,
  118. type: 'solid'
  119. }
  120. },
  121. axisLabel: {
  122. color: '#fff' // 标签颜色设置为白色,增加可读性
  123. },
  124. splitArea: {
  125. show: false,
  126. areaStyle: {
  127. color: [
  128. '#1E586B',
  129. ]
  130. }
  131. },
  132. },
  133. legend: {
  134. icon: 'circle',
  135. itemHeight: 5,
  136. itemWidth: 5,
  137. textStyle: {
  138. color: '#ffffff' // 设置图例文字颜色为深灰色
  139. },
  140. data: ['告警总数', '越线告警']
  141. },
  142. series: [{
  143. name: '告警总数',
  144. itemStyle: {
  145. normal: {
  146. color: '#FFAB2B',
  147. lineStyle: {
  148. color: '#FFAB2B',
  149. width: 1
  150. }
  151. }
  152. },
  153. symbol: 'none',
  154. // smooth: true,
  155. type: 'line',
  156. data: gjzs,
  157. areaStyle: {
  158. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  159. offset: 0,
  160. color: '#FFAB2B'
  161. },
  162. {
  163. offset: 0.6,
  164. color: '#FAAD1470'
  165. },
  166. {
  167. offset: 1,
  168. color: '#FAAD1410'
  169. }
  170. ],
  171. false)
  172. },
  173. },
  174. {
  175. name: '越线告警',
  176. smooth: true,
  177. type: 'line',
  178. itemStyle: {
  179. normal: {
  180. color: '#00FEFE',
  181. lineStyle: {
  182. color: '#00FEFE',
  183. width: 1
  184. },
  185. }
  186. },
  187. symbol: 'none',
  188. data: yxgj,
  189. areaStyle: {
  190. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  191. offset: 0,
  192. color: '#00F2F3'
  193. },
  194. {
  195. offset: 0.6,
  196. color: '#2B98F770'
  197. },
  198. {
  199. offset: 1,
  200. color: '#2B98F710'
  201. }
  202. ],
  203. false
  204. )
  205. },
  206. }
  207. ]
  208. }, true)
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="less" scoped>
  214. </style>