Index.vue 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <script setup>
  2. import { Head } from '@inertiajs/inertia-vue3'
  3. import AppCardStatistic from '@/components/AppCardStatistic.vue'
  4. import AppLayout from '@/layouts/AppLayout.vue'
  5. defineProps({
  6. cardStatistics: Array,
  7. barStatistics: Array,
  8. barHorizontalStatistics: Array,
  9. })
  10. const colors = [
  11. '#349dcf',
  12. '#00b2da',
  13. '#00c7dd',
  14. '#1fdbdb',
  15. '#57eed3',
  16. '#88ffc9',
  17. '#96ed9a',
  18. '#a8d96c',
  19. '#bbc242',
  20. '#cda91d',
  21. ]
  22. const barChart = (chartData) => {
  23. const colors = ['#349dcf', '#a8d96c']
  24. const data = {
  25. datasets: [],
  26. }
  27. let id = 0
  28. for (const key in chartData) {
  29. data.datasets.push({
  30. label: key,
  31. backgroundColor: colors[id],
  32. data: chartData[key],
  33. })
  34. id++
  35. }
  36. return data
  37. }
  38. const barChartOption = {
  39. maintainAspectRatio: false,
  40. datasetFill: false,
  41. }
  42. const barHorizontalChart = (chartData) => {
  43. const labels = []
  44. const data = []
  45. for (const obj of chartData) {
  46. labels.push([obj.label1, obj.label2])
  47. data.push(obj.data)
  48. }
  49. return {
  50. labels: labels,
  51. datasets: [
  52. {
  53. data: data,
  54. backgroundColor: colors,
  55. },
  56. ],
  57. }
  58. }
  59. const barHorizontalChartOption = {
  60. maintainAspectRatio: false,
  61. datasetFill: false,
  62. indexAxis: 'y',
  63. plugins: {
  64. legend: {
  65. display: false,
  66. },
  67. },
  68. }
  69. const pieChart = (chartData) => {
  70. const labels = []
  71. const data = []
  72. for (const key in chartData) {
  73. labels.push(key)
  74. data.push(chartData[key])
  75. }
  76. return {
  77. labels: labels,
  78. datasets: [
  79. {
  80. data: data,
  81. backgroundColor: colors,
  82. },
  83. ],
  84. }
  85. }
  86. const pieChartOption = {
  87. maintainAspectRatio: false,
  88. datasetFill: false,
  89. }
  90. </script>
  91. <template>
  92. <AppLayout>
  93. <Head title="Dashboard" />
  94. <div class="grid">
  95. <div class="col-12 flex flex-wrap justify-content-between card-statistic">
  96. <div v-for="cardStatistic in cardStatistics" class="flex-grow-1">
  97. <AppCardStatistic :data="cardStatistic" />
  98. </div>
  99. </div>
  100. <div v-for="barStatistic in barStatistics" class="col-12 md:col-6">
  101. <Card>
  102. <template #title>
  103. <div class="flex flex-column">
  104. <span>{{ barStatistic.title }}</span>
  105. <span v-if="barStatistic.description" class="text-base font-normal">{{ barStatistic.description }}</span>
  106. </div>
  107. </template>
  108. <template v-if="Object.keys(barStatistic.data).length" #content>
  109. <Chart
  110. type="bar"
  111. :width="600"
  112. :height="300"
  113. :data="barChart(barStatistic.data)"
  114. :options="barChartOption"
  115. />
  116. </template>
  117. </Card>
  118. </div>
  119. <!-- <div v-for="barHorizontalStatistic in barHorizontalStatistics" class="col-12 md:col-6">
  120. <Card>
  121. <template #title>
  122. <div class="flex flex-column">
  123. <span>{{ barHorizontalStatistic.title }}</span>
  124. <span v-if="barHorizontalStatistic.description" class="text-base font-normal">{{
  125. barHorizontalStatistic.description
  126. }}</span>
  127. </div>
  128. </template>
  129. <template #content>
  130. <Chart
  131. type="bar"
  132. :width="600"
  133. :height="300"
  134. :data="barHorizontalChart(barHorizontalStatistic.data)"
  135. :options="barHorizontalChartOption"
  136. />
  137. </template>
  138. </Card>
  139. </div> -->
  140. <!-- <div v-for="pieStatistic in pieStatistics" class="col-12 md:col-6">
  141. <Card>
  142. <template #title>
  143. <div class="flex flex-column">
  144. <span>{{ pieStatistic.title }}</span>
  145. <span v-if="pieStatistic.description" class="text-base font-normal">{{ pieStatistic.description }}</span>
  146. </div>
  147. </template>
  148. <template #content>
  149. <Chart
  150. type="pie"
  151. :width="600"
  152. :height="300"
  153. :data="pieChart(pieStatistic.data)"
  154. :options="pieChartOption"
  155. />
  156. </template>
  157. </Card>
  158. </div> -->
  159. </div>
  160. </AppLayout>
  161. </template>
  162. <style scoped>
  163. .card-statistic {
  164. gap: 1rem;
  165. }
  166. </style>