AreaChart.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <script setup lang="ts">
  2. import VueApexCharts from 'vue3-apexcharts'
  3. import {ref, watch} from 'vue'
  4. import {useSettingsStore} from '@/pinia'
  5. import {storeToRefs} from 'pinia'
  6. const {series, max, y_formatter} = defineProps(['series', 'max', 'y_formatter'])
  7. const settings = useSettingsStore()
  8. const {theme} = storeToRefs(settings)
  9. const fontColor = () => {
  10. return theme.value === 'dark' ? '#b4b4b4' : undefined
  11. }
  12. const chart = ref(null)
  13. let chartOptions = {
  14. chart: {
  15. type: 'area',
  16. zoom: {
  17. enabled: false
  18. },
  19. animations: {
  20. enabled: false
  21. },
  22. toolbar: {
  23. show: false
  24. }
  25. },
  26. colors: ['#ff6385', '#36a3eb'],
  27. fill: {
  28. // type: ['solid', 'gradient'],
  29. gradient: {
  30. shade: 'light'
  31. }
  32. //colors: ['#ff6385', '#36a3eb'],
  33. },
  34. dataLabels: {
  35. enabled: false
  36. },
  37. stroke: {
  38. curve: 'smooth',
  39. width: 0
  40. },
  41. xaxis: {
  42. type: 'datetime',
  43. labels: {
  44. datetimeUTC: false,
  45. style: {
  46. colors: fontColor()
  47. }
  48. }
  49. },
  50. tooltip: {
  51. enabled: false
  52. },
  53. yaxis: {
  54. max: max,
  55. tickAmount: 4,
  56. min: 0,
  57. labels: {
  58. style: {
  59. colors: fontColor()
  60. },
  61. formatter: y_formatter
  62. }
  63. },
  64. legend: {
  65. labels: {
  66. colors: fontColor()
  67. },
  68. onItemClick: {
  69. toggleDataSeries: false
  70. },
  71. onItemHover: {
  72. highlightDataSeries: false
  73. }
  74. }
  75. }
  76. let instance: ApexCharts | null = chart.value
  77. const callback = () => {
  78. chartOptions = {
  79. ...chartOptions,
  80. ...{
  81. xaxis: {
  82. type: 'datetime',
  83. labels: {
  84. datetimeUTC: false,
  85. style: {
  86. colors: fontColor()
  87. }
  88. }
  89. },
  90. yaxis: {
  91. max: max,
  92. tickAmount: 4,
  93. min: 0,
  94. labels: {
  95. style: {
  96. colors: fontColor()
  97. },
  98. formatter: y_formatter
  99. }
  100. },
  101. legend: {
  102. labels: {
  103. colors: fontColor()
  104. },
  105. onItemClick: {
  106. toggleDataSeries: false
  107. },
  108. onItemHover: {
  109. highlightDataSeries: false
  110. }
  111. }
  112. }
  113. }
  114. instance?.updateOptions?.(chartOptions)
  115. }
  116. watch(theme, callback)
  117. </script>
  118. <template>
  119. <!-- Use theme as key to rerender the chart when theme changes to prevent style issues -->
  120. <VueApexCharts :key="theme" type="area" height="200" :options="chartOptions" :series="series" ref="chart"/>
  121. </template>
  122. <style scoped>
  123. </style>