/api/trends has 1 pie of median
parent
b8c78fe55e
commit
6be00d6423
|
|
@ -143,18 +143,31 @@ func (router Router) APITrends(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
slices.Sort(months)
|
||||
|
||||
fmt.Fprintln(w, "<!DOCTYPE html>")
|
||||
catToMonth := map[string][]int{}
|
||||
for _, month := range months {
|
||||
balances := monthsToDeltas[month].Balances().WithBPIs(bpis)
|
||||
chart := view.NewChart("pie")
|
||||
for category, balance := range balances {
|
||||
chart.AddY(category, []int{int(balance[ledger.USD])})
|
||||
catToMonth[category] = append(catToMonth[category], int(balance[ledger.USD]))
|
||||
}
|
||||
fmt.Fprintln(w, "<h2>", month, "</h2>")
|
||||
}
|
||||
|
||||
chart := view.NewChart("pie")
|
||||
ttl := 0
|
||||
for cat, month := range catToMonth {
|
||||
for i := 0; i < len(months)-len(month); i++ {
|
||||
month = append(month, 0)
|
||||
}
|
||||
slices.Sort(month)
|
||||
median := month[len(month)/2]
|
||||
ttl += median
|
||||
if median > 50 {
|
||||
chart.AddY(cat, []int{median})
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(w, "<!DOCTYPE html><h2>Median Spending ($", ttl, ")</h2>")
|
||||
if err := chart.Render(w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (router Router) APIAmend(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
|||
|
|
@ -124,6 +124,9 @@ func (pie *Pie) AddX(v interface{}) {
|
|||
|
||||
func (pie *Pie) Render(w io.Writer) error {
|
||||
pie.AddSeries("", pie.series)
|
||||
pie.SetGlobalOptions(charts.WithLegendOpts(opts.Legend{
|
||||
Show: false,
|
||||
}))
|
||||
return pie.Pie.Render(w)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue