echarts.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view style="height: 350upx;width:100%;">
  3. <l-echart ref="detailedChart"></l-echart>
  4. </view>
  5. </template>
  6. <script setup>
  7. import * as echarts from "echarts";
  8. import { onLoad, onShow, onHide, onLaunch, onResize } from "@dcloudio/uni-app";
  9. import { defineComponent, ref, onMounted, nextTick,watch } from "vue";
  10. const props = defineProps({
  11. xAxisDataList: {
  12. type: Object,
  13. default: null,
  14. },
  15. seriesDataList: {
  16. type: Object,
  17. default: null,
  18. },
  19. });
  20. let myChart;
  21. const detailedChart = ref(null);
  22. let option = {
  23. tooltip: {
  24. trigger: "axis",
  25. },
  26. legend: {
  27. show: false,
  28. // data: ["邮件营销"],
  29. },
  30. grid: {
  31. top: "20%",
  32. left: "3%",
  33. right: "8%",
  34. bottom: "3%",
  35. containLabel: true,
  36. },
  37. xAxis: {
  38. type: "category",
  39. boundaryGap: true,
  40. axisLabel: {
  41. color: "rgba(0,0,0,0.4)",
  42. fontSize:props.xAxisDataList.length>10?8:10, //标签字体大小
  43. rotate: -30, //文字过多时,倾斜角度
  44. },
  45. axisLine: {
  46. show: true,
  47. lineStyle: {
  48. color: "rgba(0,0,0,0.4)",
  49. },
  50. },
  51. axisTick: {
  52. show: false,
  53. },
  54. data: props.xAxisDataList,
  55. },
  56. yAxis: {
  57. type: "value",
  58. name: '工时(小时)',
  59. color: "rgba(0,0,0,0.4)",
  60. axisLabel: {
  61. color: "rgba(0,0,0,0.4)",
  62. },
  63. axisLine: {
  64. show: true,
  65. lineStyle: {
  66. color: "rgba(0,0,0,0.4)",
  67. },
  68. },
  69. splitLine: {
  70. lineStyle: {
  71. color: "rgba(0,0,0,0.1)",
  72. },
  73. },
  74. },
  75. series: [
  76. {
  77. name: "工时",
  78. type: "bar",
  79. stack: "总量",
  80. smooth: true,
  81. itemStyle: {
  82. color: "rgba(73, 185, 245, 1)",
  83. },
  84. areaStyle: {
  85. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  86. {
  87. offset: 0,
  88. color: "rgba(73, 185, 245, 1)",
  89. },
  90. {
  91. offset: 1,
  92. color: "rgba(73, 185, 245, 0.4)",
  93. },
  94. ]),
  95. },
  96. data: props.seriesDataList,
  97. },
  98. ],
  99. };
  100. function initEcharts() {
  101. myChart = detailedChart.value;
  102. myChart.init(echarts, (myChart) => {
  103. myChart.setOption(option);
  104. });
  105. }
  106. onLoad(() => {
  107. nextTick(() => {
  108. initEcharts();
  109. });
  110. });
  111. onResize(() => {
  112. myChart.resize();
  113. });
  114. </script>