Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Irvan Alfian Adi Nugroho
TA
Commits
0ced6439
Commit
0ced6439
authored
11 months ago
by
Irvan Alfian Adi N
Browse files
Options
Download
Email Patches
Plain Diff
update chart
parent
fd854c8b
main
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/chart/page.vue
+110
-0
src/app/chart/page.vue
src/layouts/main.layout.vue
+6
-0
src/layouts/main.layout.vue
with
116 additions
and
0 deletions
+116
-0
src/app/chart/page.vue
0 → 100644
View file @
0ced6439
<route
lang=
"yaml"
>
meta:
layout: main.layout
</route>
<
script
setup
lang=
"ts"
>
import
{
Bar
,
Doughnut
}
from
'
vue-chartjs
'
;
import
{
Chart
as
ChartJS
,
Title
,
Tooltip
,
Legend
,
BarElement
,
CategoryScale
,
LinearScale
,
DoughnutController
,
ArcElement
,
type
ChartOptions
,
type
ChartData
}
from
'
chart.js
'
;
import
{
DateTime
}
from
'
luxon
'
;
import
{
useHttp
}
from
'
@/composables/http/http
'
;
import
{
computed
}
from
'
vue
'
;
ChartJS
.
register
(
Title
,
Tooltip
,
Legend
,
BarElement
,
CategoryScale
,
LinearScale
);
ChartJS
.
register
(
DoughnutController
,
ArcElement
,
Tooltip
,
Legend
);
// Fetch data for the bar chart
const
{
data
:
barChartData
,
isLoading
:
isLoadingBarChart
}
=
useHttp
<
R
<
{
month
:
string
,
total_transaction
:
string
}[]
>>
(
'
/chart
'
);
// Fetch data for the doughnut chart
const
{
data
:
doughnutChartData
,
isLoading
:
isLoadingDoughnutChart
}
=
useHttp
<
R
<
{
tipe_pengaduan
:
string
|
null
,
count
:
string
}[]
>>
(
'
/chart-tipe
'
);
// Bar chart options and data
const
barChartOptions
:
ChartOptions
<
'
bar
'
>
=
{
responsive
:
true
,
maintainAspectRatio
:
true
,
};
const
barChartDataComputed
=
computed
<
ChartData
<
'
bar
'
>>
(()
=>
({
labels
:
barChartData
.
value
?.
data
?.
map
((
v
)
=>
DateTime
.
fromISO
(
v
.
month
).
toFormat
(
'
MMMM
'
))
||
[],
datasets
:
[
{
label
:
'
Laporan
'
,
data
:
barChartData
.
value
?.
data
?.
map
((
v
)
=>
+
v
.
total_transaction
)
||
[],
backgroundColor
:
'
#0fb2a9
'
,
},
],
}));
// Doughnut chart options and data
const
doughnutChartOptions
:
ChartOptions
<
'
doughnut
'
>
=
{
responsive
:
true
,
maintainAspectRatio
:
true
,
};
const
doughnutChartDataComputed
=
computed
<
ChartData
<
'
doughnut
'
>>
(()
=>
{
const
data
=
doughnutChartData
.
value
?.
data
||
[];
return
{
labels
:
data
.
map
((
item
)
=>
item
.
tipe_pengaduan
||
'
Unknown
'
),
// Ganti null dengan 'Unknown'
datasets
:
[
{
data
:
data
.
map
((
item
)
=>
+
item
.
count
),
backgroundColor
:
[
'
#FF6384
'
,
'
#36A2EB
'
,
'
#FFCE56
'
,
'
#FF5733
'
,
'
#C70039
'
],
},
],
};
});
</
script
>
<
template
>
<div
class=
"max-w-screen-xl mx-auto space-y-5"
>
<div
class=
"text-center font-semibold text-2xl"
>
Grafik Laporan Kejadian di Lingkungan UNS Berdasarkan Laporan Masuk
</div>
<div
class=
"chart-container"
>
<Bar
v-if=
"!isLoadingBarChart"
:style=
"
{ height: '400px', width: '100%' }"
:options="barChartOptions"
:data="barChartDataComputed"
/>
<div
v-else
>
Loading bar chart...
</div>
</div>
<div
class=
"text-center text-2xl font-semibold"
>
Grafik Laporan Kejadian di Lingkungan UNS Berdasarkan Tipe Pengaduan
</div>
<div
class=
"chart-container"
>
<Doughnut
v-if=
"!isLoadingDoughnutChart"
:style=
"
{ height: '400px', width: '400px' }"
:options="doughnutChartOptions"
:data="doughnutChartDataComputed"
/>
<div
v-else
>
Loading doughnut chart...
</div>
</div>
</div>
</
template
>
<
style
scoped
>
.chart-container
{
display
:
flex
;
justify-content
:
center
;
align-items
:
center
;
margin
:
0
auto
;
}
@media
(
max-width
:
768px
)
{
.chart-container
{
flex-direction
:
column
;
}
}
</
style
>
This diff is collapsed.
Click to expand it.
src/layouts/main.layout.vue
View file @
0ced6439
...
...
@@ -85,6 +85,12 @@ const menuOptions = computed(() => [
key
:
'
/reports
'
,
show
:
[
'
admin_unit
'
].
includes
(
profile
.
value
?.
data
?.
role
as
string
),
icon
:
renderIcon
(
DocumentOutline
)
},
{
label
:
'
Grafik
'
,
key
:
'
/chart
'
,
show
:
[
'
admin
'
].
includes
(
profile
.
value
?.
data
?.
role
as
string
),
icon
:
renderIcon
(
DocumentOutline
)
}
])
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help