@@ -30,110 +30,54 @@ Now create file `ApartsPie.vue` in the `custom` folder of your project:
3030
3131``` html title="./custom/ApartsPie.vue"
3232<template >
33- <div class =" max-w-sm w-full bg-white rounded-lg shadow dark:bg-gray-800 p-4 md:p-4 mb-5" >
34- <div id =" pie-chart" ></div >
35- </div >
36- </template >
37-
38- <script setup lang =" ts" >
39- import { onMounted , ref , Ref } from ' vue' ;
40- import ApexCharts from ' apexcharts' ;
41- import { callApi } from ' @/utils' ;
42- import adminforth from ' @/adminforth' ;
43-
44-
45- const data: Ref <any []> = ref ([]);
46-
47- const POSSIBLE_COLORS = [" #1C64F2" , " #16BDCA" , " #9061F9" , " #F0A936" , " #F55252" , " #3B82F6" , " #10B981" , " #F472B6" , " #6B7280" ];
48-
49- const chatOptions = {
50- series: [],
51- colors: POSSIBLE_COLORS ,
52- chart: {
53- height: 200 ,
54- width: " 100%" ,
55- type: " pie" ,
56- events: {
57- dataPointSelection : function (event , chartContext , config ) {
58- if (config .selectedDataPoints [0 ].length ) {
59- const selectedRoomsCount = data .value [config .dataPointIndex ].rooms ;
60- adminforth .list .updateFilter ({field: ' number_of_rooms' , operator: ' eq' , value: selectedRoomsCount});
61- } else {
62- // clear filter
63- adminforth .list .updateFilter ({field: ' number_of_rooms' , value: undefined });
64- }
65- }
66- },
67- },
68-
69- stroke: {
70- colors: [" white" ],
71- lineCap: " " ,
72- },
73- plotOptions: {
74- pie: {
75- labels: {
76- show: true ,
77- },
78- size: " 100%" ,
79- dataLabels: {
80- offset: - 25
81- }
82- },
83- },
84- labels: [" Direct" , " Organic search" , " Referrals" ],
85- dataLabels: {
86- enabled: true ,
87- style: {
88- fontFamily: " Inter, sans-serif" ,
89- },
90- },
91- legend: {
92- position: " right" ,
93- fontFamily: " Inter, sans-serif" ,
94- },
95- yaxis: {
96- labels: {
97- formatter : function (value ) {
98- return value + " %"
99- },
100- },
101- },
102- xaxis: {
103- labels: {
104- formatter : function (value ) {
105- return value + " %"
106- },
107- },
108- axisTicks: {
109- show: false ,
110- },
111- axisBorder: {
112- show: false ,
113- },
114- },
115- }
116-
117- onMounted (async () => {
118- try {
119- data .value = await callApi ({path: ' /api/aparts-by-room-percentages' , method: ' GET' });
120- } catch (error) {
121- adminforth .alert ({
122- message: ` Error fetching data: ${ error .message } ` ,
123- variant: ' danger' ,
124- timeout: ' unlimited'
125- });
126- return ;
127- }
128-
129- chatOptions .series = data .value .map ((item ) => item .percentage );
130- chatOptions .labels = data .value .map ((item ) => ` ${ item .rooms } rooms` );
131- const chart = new ApexCharts (document .getElementById (" pie-chart" ), chatOptions);
132- chart .render ();
133-
134- })
135-
136- </script >
33+ <div class =" max-w-sm w-full bg-white rounded-lg shadow dark:bg-gray-800 p-4 md:p-4 mb-5" >
34+ <PieChart
35+ :data =" data"
36+ :options =" {
37+ chart: {
38+ height: 250,
39+ },
40+ dataLabels: {
41+ enabled: true,
42+ },
43+ plotOptions: {
44+ pie: {
45+ dataLabels: {
46+ offset: -10,
47+ minAngleToShowLabel: 10,
48+ },
49+ expandOnClick: true,
50+ },
51+ },
52+ }"
53+ />
54+ </div >
55+ </template >
56+
57+ <script setup lang =" ts" >
58+ import { onMounted , ref , Ref } from ' vue' ;
59+ import { PieChart } from ' @/afcl' ;
60+ import { callApi } from ' @/utils' ;
61+ import adminforth from ' @/adminforth' ;
62+
63+
64+ const data: Ref <any []> = ref ([]);
65+
66+
67+ onMounted (async () => {
68+ try {
69+ data .value = await callApi ({path: ' /api/aparts-by-room-percentages' , method: ' GET' });
70+ } catch (error) {
71+ adminforth .alert ({
72+ message: ` Error fetching data: ${ error .message } ` ,
73+ variant: ' danger' ,
74+ timeout: ' unlimited'
75+ });
76+ return ;
77+ }
78+ })
79+
80+ </script >
13781```
13882
13983
0 commit comments