VaChart.vue 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <component :is="chartComponent" ref="chart" class="va-chart" :chart-options="chartOptions" :chart-data="data" />
  3. </template>
  4. <script setup lang="ts">
  5. import { computed, ref } from 'vue'
  6. import type { TChartOptions } from 'vue-chartjs/dist/types'
  7. import { defaultConfig, chartTypesMap } from './vaChartConfigs'
  8. import { TChartData } from '../../data/types'
  9. const props = defineProps<{
  10. data: TChartData
  11. options?: TChartOptions<'line' | 'bar' | 'bubble' | 'doughnut' | 'pie'>
  12. type: keyof typeof chartTypesMap
  13. }>()
  14. const chart = ref()
  15. const chartComponent = computed(() => chartTypesMap[props.type])
  16. const chartOptions = computed(() => ({
  17. ...defaultConfig,
  18. ...props.options,
  19. }))
  20. </script>
  21. <style lang="scss">
  22. .va-chart {
  23. width: 100%;
  24. height: 100%;
  25. display: flex;
  26. align-items: center;
  27. justify-content: center;
  28. > * {
  29. height: 100%;
  30. width: 100%;
  31. }
  32. canvas {
  33. width: 100%;
  34. height: auto;
  35. min-height: 320px;
  36. }
  37. }
  38. </style>