echartLineDate.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div class="echart-line" ref="echartLines"></div>
  3. </template>
  4. <script setup lang="ts">
  5. import { nextTick, onMounted, ref } from 'vue'
  6. import * as echarts from 'echarts';
  7. let props = defineProps({
  8. //图表配置项
  9. echartOption: {
  10. type: Object as any
  11. },
  12. //图表数据
  13. ecahrtData: {
  14. type: Object as any
  15. }
  16. })
  17. let echartLines = ref(null)
  18. function getOption() {
  19. nextTick(() => {
  20. let myChart = echarts.init(echartLines.value);
  21. let option = {
  22. tooltip: props.echartOption.tooltip,
  23. grid: props.echartOption.grid,
  24. legend: props.echartOption.legend,
  25. xAxis: [{
  26. type: 'category',
  27. boundaryGap: false,
  28. axisLine: { //坐标轴轴线相关设置。数学上的x轴
  29. show: true,
  30. lineStyle: {
  31. color: 'rgba(4, 49, 79)',
  32. },
  33. },
  34. axisLabel: { //坐标轴刻度标签的相关设置
  35. textStyle: {
  36. color: '#7ec7ff',
  37. padding: 5,
  38. fontSize: 12
  39. },
  40. formatter: function (data) {
  41. return data
  42. }
  43. },
  44. splitLine: {
  45. show: false,
  46. },
  47. axisTick: {
  48. show: false,
  49. },
  50. data: props.ecahrtData.xData
  51. }],
  52. yAxis:props.echartOption.yAxis,
  53. series: props.echartOption.series.map((el, index) => {
  54. return {
  55. name: el.name,
  56. type: el.type,
  57. symbol: el.symbol, // 默认是空心圆(中间是白色的),改成实心圆
  58. showAllSymbol: el.showAllSymbol,
  59. symbolSize: el.symbolSize,
  60. smooth: el.smooth,
  61. lineStyle: el.lineStyle,
  62. itemStyle: el.itemStyle,
  63. areaStyle: el.areaStyle,
  64. data: props.ecahrtData[el.data]
  65. }
  66. })
  67. };
  68. myChart.setOption(option);
  69. window.onresize = function () {
  70. myChart.resize();
  71. };
  72. });
  73. }
  74. onMounted(() => {
  75. getOption()
  76. })
  77. </script>
  78. <style lang="less" scoped>
  79. .echart-line {
  80. width: 100%;
  81. height: 100%;
  82. }
  83. </style>