1
0

AnalysisBar.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 } = useECharts(chartRef as Ref<HTMLDivElement>);
  14. onMounted(() => {
  15. setOptions({
  16. tooltip: {
  17. trigger: 'axis',
  18. backgroundColor: 'rgba(0, 0, 0, .6)',
  19. axisPointer: {
  20. // 坐标轴指示器,坐标轴触发有效
  21. type: 'shadow', // 默认为直线,可选为:'line' | 'shadow'
  22. },
  23. },
  24. legend: {
  25. itemWidth: 15,
  26. right: 10,
  27. data: ['产品一', '产品二', '产品三'],
  28. },
  29. grid: {
  30. left: '3%',
  31. right: '4%',
  32. bottom: '3%',
  33. containLabel: true,
  34. },
  35. xAxis: [
  36. {
  37. type: 'category',
  38. axisTick: {
  39. inside: true, // 刻度朝内
  40. },
  41. data: ['付费用户', '免费用户', '自主'],
  42. },
  43. ],
  44. yAxis: [
  45. {
  46. type: 'value',
  47. axisTick: {
  48. inside: true, // 刻度朝内
  49. },
  50. },
  51. ],
  52. series: [
  53. {
  54. name: '产品一',
  55. type: 'bar',
  56. itemStyle: {
  57. color: '#3ca0f6',
  58. },
  59. data: [3200, 3320, 3010],
  60. animationDuration: 4000,
  61. },
  62. {
  63. name: '产品二',
  64. type: 'bar',
  65. itemStyle: {
  66. color: '#7dd9b9',
  67. },
  68. data: [1200, 2600, 1010],
  69. animationDuration: 4000,
  70. },
  71. {
  72. name: '产品三',
  73. type: 'bar',
  74. itemStyle: {
  75. color: '#e6a23c',
  76. },
  77. data: [862, 2500, 964],
  78. animationDuration: 4000,
  79. },
  80. ],
  81. });
  82. });
  83. return { chartRef };
  84. },
  85. });
  86. </script>