add chart tab kepesertaan

This commit is contained in:
2024-06-27 15:56:43 +07:00
parent 2a25c60cc2
commit 1c7e223195
3 changed files with 286 additions and 73 deletions

View File

@@ -12,6 +12,9 @@ import (
)
type TabKepersertaanServices interface {
GetTotalKepesertaanMCU(mcuID string) (models.Piechart, error)
GetKepesertaanByGender(mcuID string) (models.Piechart, error)
GetKepesertaanByUmur(mcuID string) (models.Piechart, error)
}
type TabKepersertaanHandler struct {
@@ -28,88 +31,47 @@ func (tkh *TabKepersertaanHandler) HandleShowTabKepesertaan(c echo.Context) erro
logger, _ := zap.NewProduction()
logger.Info("Tab Kepesertaan")
chTotalPesertaID := utils.GenerateRandomID("totalPesertaID")
chGenderPesertaID := utils.GenerateRandomID("genderPesertaID")
chUmurPesertaID := utils.GenerateRandomID("umurPesertaID")
id := c.Param("id")
logger.Info("Params", zap.Any("id", id))
option := models.Piechart{
Title: struct {
Text string `json:"text"`
SubText string `json:"subtext"`
Left string `json:"left"`
}{
Text: "Testing",
SubText: "Total Peserta 560",
Left: "center",
},
Tooltip: struct {
Trigger string `json:"trigger"`
}{
Trigger: "item",
},
Legend: struct {
Top string `json:"top"`
Left string `json:"left"`
Orient string `json:"orient"`
}{
Top: "bottom",
Left: "center",
Orient: "horizontal",
},
Series: []models.Series{
{
Label: struct {
Position string `json:"position"`
Formatter string `json:"formatter"`
}{
Position: "inner",
Formatter: "{d}%",
},
Name: "Access From",
Type: "pie",
Radius: []string{"20%", "50%"},
ItemStyle: struct {
BorderRadius int `json:"borderRadius"`
BorderColor string `json:"borderColor"`
BorderWidth int `json:"borderWidth"`
}{
BorderRadius: 10,
BorderColor: "#fff",
BorderWidth: 2,
},
Data: []models.SeriesData{
{Value: 506, Name: "Sudah MCU : 506 Peserta"},
{Value: 54, Name: "Belum MCU : 54 Peserta"},
},
Emphasis: struct {
ItemStyle struct {
ShadowBlur int `json:"shadowBlur"`
ShadowOffsetX int `json:"shadowOffsetX"`
ShadowColor string `json:"shadowColor"`
} `json:"itemStyle"`
}{
ItemStyle: struct {
ShadowBlur int `json:"shadowBlur"`
ShadowOffsetX int `json:"shadowOffsetX"`
ShadowColor string `json:"shadowColor"`
}{
ShadowBlur: 10,
ShadowOffsetX: 0,
ShadowColor: "rgba(0, 0, 0, 0.5)",
},
},
},
},
peserta, err := tkh.TabKepersertaanServices.GetTotalKepesertaanMCU(id)
if err != nil {
return err
}
json, err := json.MarshalIndent(option, "", " ")
gender, err := tkh.TabKepersertaanServices.GetKepesertaanByGender(id)
if err != nil {
return err
}
umur, err := tkh.TabKepersertaanServices.GetKepesertaanByUmur(id)
if err != nil {
return err
}
totaljson, err := json.MarshalIndent(peserta, "", " ")
if err != nil {
return err
}
genderjson, err := json.MarshalIndent(gender, "", " ")
if err != nil {
return err
}
umurjson, err := json.MarshalIndent(umur, "", " ")
if err != nil {
return err
}
content := corporate_mcudetail.TabKepesertaan(
chart.ShowChart("alpha", string(json)),
chart.ShowChart("beta", string(json)),
chart.ShowChart("delta", string(json)),
chart.ShowChart(chTotalPesertaID, string(totaljson)),
chart.ShowChart(chGenderPesertaID, string(genderjson)),
chart.ShowChart(chUmurPesertaID, string(umurjson)),
)
return utils.View(c, content)