Skip to content

Commit

Permalink
(fix) metric on stack bar
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Mar 27, 2024
1 parent a9bc9df commit c5e9c32
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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"],
Expand Down
29 changes: 6 additions & 23 deletions pkg/bar_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,36 +114,19 @@ 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{
{
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{
Expand Down
3 changes: 1 addition & 2 deletions pkg/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit c5e9c32

Please sign in to comment.