echart-bar-LR.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <!-- 柱图 -->
  2. <template>
  3. <div style="height:100%;min-height: 300px;" :id="props.id" class="myChart"></div>
  4. </template>
  5. <script setup lang="ts">
  6. import { inject, onMounted, reactive } from "vue";
  7. const props = defineProps({
  8. id: {
  9. type: String,
  10. default: () => '',
  11. },
  12. lineData: {
  13. type: Object,
  14. default: () => { },
  15. },
  16. })
  17. let echartData: any = reactive({
  18. titles: '',//标题
  19. xAxisArr: [],//x轴
  20. seriesDiscount: [], //合同总金额
  21. seriesRecoveries: [] //合同已回款金额
  22. })
  23. let echart: any = null
  24. let myChart: any = null
  25. onMounted(() => {
  26. echart = inject('echart')
  27. myChart = echart.init(document.getElementById(props.id));
  28. setEchartFun();
  29. })
  30. //函数
  31. const setEchartFun = async () => {
  32. myChart.setOption(initEcharts());
  33. window.onresize = function () {
  34. myChart.resize();
  35. };
  36. }
  37. const initEcharts = () => {
  38. // 绘制图表
  39. return {
  40. tooltip: {
  41. trigger: 'axis',
  42. axisPointer: {
  43. type: 'cross',
  44. label: {
  45. backgroundColor: '#6a7985'
  46. }
  47. }
  48. },
  49. title: {
  50. // text: 'Rainfall vs Evaporation',
  51. // subtext: echartData.titles
  52. },
  53. grid: {
  54. left: '0%',
  55. right: '1%',
  56. bottom: '0%',
  57. containLabel: true
  58. },
  59. xAxis: [
  60. {
  61. type: 'value'
  62. }
  63. ],
  64. yAxis: [{
  65. type: 'category',
  66. axisTick: {
  67. show: false
  68. },
  69. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  70. }],
  71. series: [
  72. {
  73. name: 'Profit',
  74. type: 'bar',
  75. label: {
  76. show: true,
  77. position: 'inside'
  78. },
  79. emphasis: {
  80. focus: 'series'
  81. },
  82. itemStyle: { //面积图颜色设置
  83. color: {
  84. type: 'linear',
  85. x: 0,
  86. y: 0,
  87. x2: 0,
  88. y2: 1,
  89. colorStops: [
  90. {
  91. offset: 0, //offset 可取范围 0、0.1、0.2、到1
  92. color: 'rgba(250, 51, 171, 0.8)', // 0% 处的颜色
  93. },
  94. {
  95. offset: 1,
  96. color: 'rgba(206, 51, 181, 0.4)' // 100% 处的颜色
  97. }
  98. ],
  99. globalCoord: false // 缺省为 false
  100. }
  101. },
  102. data: [200, 170, 240, 244, 200, 220, 210]
  103. },
  104. {
  105. name: 'Income',
  106. type: 'bar',
  107. stack: 'Total',
  108. label: {
  109. show: true
  110. },
  111. emphasis: {
  112. focus: 'series'
  113. },
  114. itemStyle: { //面积图颜色设置
  115. color: {
  116. type: 'linear',
  117. x: 0,
  118. y: 0,
  119. x2: 0,
  120. y2: 1,
  121. colorStops: [
  122. {
  123. offset: 0, //offset 可取范围 0、0.1、0.2、到1
  124. color: 'rgba(250, 51, 171, 0.8)', // 0% 处的颜色
  125. },
  126. {
  127. offset: 1,
  128. color: 'rgba(206, 51, 181, 0.4)' // 100% 处的颜色
  129. }
  130. ],
  131. globalCoord: false // 缺省为 false
  132. }
  133. },
  134. data: [320, 302, 341, 374, 390, 450, 420]
  135. },
  136. {
  137. name: 'Expenses',
  138. type: 'bar',
  139. stack: 'Total',
  140. label: {
  141. show: true,
  142. position: 'left'
  143. },
  144. emphasis: {
  145. focus: 'series'
  146. },
  147. itemStyle: { //面积图颜色设置
  148. color: {
  149. type: 'linear',
  150. x: 0,
  151. y: 0,
  152. x2: 0,
  153. y2: 1,
  154. colorStops: [
  155. {
  156. offset: 0, //offset 可取范围 0、0.1、0.2、到1
  157. color: 'rgba(250, 51, 171, 0.8)', // 0% 处的颜色
  158. },
  159. {
  160. offset: 1,
  161. color: 'rgba(206, 51, 181, 0.4)' // 100% 处的颜色
  162. }
  163. ],
  164. borderRadius: [30, 30, 0, 0], //圓角
  165. globalCoord: false // 缺省为 false
  166. }
  167. },
  168. data: [-120, -132, -101, -134, -190, -230, -210]
  169. }
  170. ]
  171. }
  172. }
  173. </script>