LineChart.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <script setup lang="ts">
  2. import { computed } from "vue";
  3. import { Line } from "vue-chartjs";
  4. import {
  5. Chart as ChartJS,
  6. Title,
  7. Tooltip,
  8. Legend,
  9. LineElement,
  10. PointElement,
  11. CategoryScale,
  12. LinearScale,
  13. LineController
  14. } from "chart.js";
  15. ChartJS.register(
  16. Title,
  17. Tooltip,
  18. Legend,
  19. LineElement,
  20. PointElement,
  21. CategoryScale,
  22. LinearScale,
  23. LineController
  24. );
  25. const props = defineProps({
  26. chartId: { type: String, default: "line-chart" },
  27. datasetIdKey: { type: String, default: "label" },
  28. width: { type: Number, default: 200 },
  29. height: { type: Number, default: 200 },
  30. cssClasses: { default: "", type: String },
  31. styles: { type: Object, default: () => {} },
  32. plugins: { type: Object, default: () => {} },
  33. data: { type: Object, default: () => {} },
  34. options: { type: Object, default: () => {} }
  35. });
  36. const chartStyles = computed(() => ({
  37. position: "relative",
  38. height: props.height,
  39. ...props.styles
  40. }));
  41. const chartOptions = computed(() => ({
  42. responsive: true,
  43. maintainAspectRatio: false,
  44. resizeDelay: 10,
  45. ...props.options
  46. }));
  47. </script>
  48. <template>
  49. <Line
  50. :ref="`chart-${chartId}`"
  51. :chart-options="chartOptions"
  52. :chart-data="data"
  53. :chart-id="chartId"
  54. :dataset-id-key="datasetIdKey"
  55. :plugins="plugins"
  56. :css-classes="cssClasses"
  57. :styles="chartStyles"
  58. :width="width"
  59. :height="height"
  60. />
  61. </template>