From c5e9c324b8b5e87931b21c8a3cdd9accbe767544 Mon Sep 17 00:00:00 2001 From: Pulkit Kathuria Date: Wed, 27 Mar 2024 17:57:27 +0900 Subject: [PATCH] (fix) metric on stack bar --- README.md | 2 -- pkg/bar_chart.go | 29 ++++++----------------------- pkg/chart.go | 3 +-- 3 files changed, 7 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 8b29025..6e8930f 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,6 @@ Extra params for `bar` chart. | :-------- | :------- | :----- | :--------- | :------------------------- | | `style` | | string | `vertical` | `vertical` or `horizontal` | | `grid` | | string | `show` | `show` or `hide` | -| `zmetric` | | string | `vertical` | when `z` data is provided | | `data` | Required | Type | Description | @@ -166,7 +165,6 @@ https://instachart.coveritup.app/bar?title=Bar+Chart https://instachart.coveritup.app/bar?title=Bar+Chart &subtitle=Sleeping+hours &metric=hours -&zmetric=days &theme=dark &data={ "x": ["Monday", "Friday", "Sunday"], diff --git a/pkg/bar_chart.go b/pkg/bar_chart.go index 40c6ce8..b56407b 100644 --- a/pkg/bar_chart.go +++ b/pkg/bar_chart.go @@ -114,29 +114,9 @@ func (c *BarChart) GetStacked(xData []string, yData [][]float64, zData [][]float } titleSizes := GetTitleSizes(req) opt := charts.ChartOption{ - Title: titleSizes, - XAxis: charts.NewXAxisOption(xData), - Legend: charts.NewLegendOption(names), - YAxisOptions: []charts.YAxisOption{ - { - Formatter: "{value}" + req.Metric, - Color: charts.Color{ - R: 84, - G: 112, - B: 198, - A: 255, - }, - }, - { - Formatter: "{value}" + req.ZMetric, - Color: charts.Color{ - R: 250, - G: 200, - B: 88, - A: 255, - }, - }, - }, + Title: titleSizes, + XAxis: charts.NewXAxisOption(xData), + Legend: charts.NewLegendOption(names), SeriesList: series, } opt.YAxisOptions = []charts.YAxisOption{ @@ -144,6 +124,9 @@ func (c *BarChart) GetStacked(xData []string, yData [][]float64, zData [][]float SplitLineShow: showGrid, }, } + opt.ValueFormatter = func(f float64) string { + return fmt.Sprintf("%s %s", NumberToK(&f), req.Metric) + } opt.Type = req.Output opt.Theme = req.Theme opt.Legend.Padding = charts.Box{ diff --git a/pkg/chart.go b/pkg/chart.go index 30b05fe..f94e4e2 100644 --- a/pkg/chart.go +++ b/pkg/chart.go @@ -46,7 +46,6 @@ type ChartRequest struct { ChartTitle string `json:"title" query:"title" form:"title"` ChartSubtitle string `json:"subtitle" query:"subtitle" form:"subtitle"` Metric string `json:"metric" query:"metric" form:"metric"` - ZMetric string `json:"zmetric" query:"zmetric" form:"zmetric"` Theme string `json:"theme" query:"theme" form:"theme" default:"light"` Width int `json:"width" query:"width" form:"width" default:"1024"` Height int `json:"height" query:"height" form:"height" default:"768"` @@ -116,7 +115,7 @@ func IsMiniChart(req *ChartRequest) bool { func GetPaddings(req *ChartRequest) charts.Box { paddings := charts.Box{ Top: 10, - Bottom: 10, + Bottom: 20, Left: 10, Right: 10, }