TrendLine.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <div ref="chartRef" :style="{ height, width }" />
  3. </template>
  4. <script lang="ts">
  5. import { defineComponent, onMounted, ref, Ref } from 'vue';
  6. import { useECharts } from '/@/hooks/web/useECharts';
  7. import { basicProps } from './props';
  8. export default defineComponent({
  9. name: 'AnalysisLine',
  10. props: basicProps,
  11. setup() {
  12. const chartRef = ref<HTMLDivElement | null>(null);
  13. const { setOptions, echarts } = useECharts(chartRef as Ref<HTMLDivElement>);
  14. onMounted(() => {
  15. setOptions({
  16. // title: {
  17. // text: '产品成交额',
  18. // },
  19. tooltip: {
  20. trigger: 'axis',
  21. padding: 3,
  22. backgroundColor: 'rgba(0, 0, 0, .6)',
  23. borderColor: '#777',
  24. borderWidth: 1,
  25. },
  26. legend: {
  27. show: false,
  28. },
  29. grid: {
  30. left: '3%',
  31. right: '4%',
  32. bottom: '3%',
  33. containLabel: true,
  34. },
  35. xAxis: {
  36. type: 'category',
  37. boundaryGap: false,
  38. axisTick: {
  39. inside: true, // 刻度朝内
  40. },
  41. data: [
  42. '一月',
  43. '二月',
  44. '三月',
  45. '四月',
  46. '五月',
  47. '六月',
  48. '七月',
  49. '八月',
  50. '九月',
  51. '十月',
  52. '十一月',
  53. '十二月',
  54. ],
  55. },
  56. yAxis: {
  57. type: 'value',
  58. axisTick: {
  59. inside: true, // 刻度朝内
  60. },
  61. },
  62. series: [
  63. {
  64. name: '产品一',
  65. type: 'line',
  66. itemStyle: {
  67. color: '#5B8FF9',
  68. },
  69. areaStyle: {
  70. // 线性渐变,前4个参数分别是x0,y0,x2,y2(范围0~1);相当于图形包围盒中的百分比。如果最后一个参数是‘true’,则该四个值是绝对像素位置。
  71. // @ts-ignore
  72. color: new echarts.graphic.LinearGradient(
  73. 0,
  74. 0,
  75. 0,
  76. 1,
  77. [
  78. {
  79. offset: 0,
  80. color: '#5B8FF9',
  81. },
  82. {
  83. offset: 1,
  84. color: 'rgba(118,168,248, 0)',
  85. },
  86. ],
  87. false
  88. ),
  89. shadowColor: 'rgba(118,168,248, 0.9)', // 阴影颜色
  90. shadowBlur: 20, // shadowBlur设图形阴影的模糊大小。配合shadowColor,shadowOffsetX/Y, 设置图形的阴影效果。
  91. },
  92. // areaStyle: {},
  93. data: [134, 330, 132, 101, 90, 230, 210, 150, 230, 400, 232, 234],
  94. animationDuration: 3000,
  95. },
  96. ],
  97. });
  98. });
  99. return { chartRef };
  100. },
  101. });
  102. </script>