diff --git a/README.md b/README.md index 91b9859..4482c14 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,9 @@ ## `GET /line` -| Query | Required | Type | Default | -| :----- | :------- | :------ | :------ | -| `fill` | | boolean | `false` | +| Query | Required | Type | Default | Description | +| :----- | :------- | :----- | :------ | :----------------- | +| `line` | | string | `fill` | `fill` or `nofill` | | `data` | Required | Type | diff --git a/go.mod b/go.mod index 7ab8394..84726e6 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/mcuadros/go-defaults v1.2.0 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.8.4 - github.com/vicanso/go-charts/v2 v2.6.1 + github.com/vicanso/go-charts/v2 v2.6.3 github.com/wcharczuk/go-chart/v2 v2.1.1 ) diff --git a/go.sum b/go.sum index 7d82eb5..7bd09a9 100644 --- a/go.sum +++ b/go.sum @@ -97,8 +97,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= -github.com/vicanso/go-charts/v2 v2.6.1 h1:xWODVa4KtzkZrbUNd6WQunqGyFWXgaUeeXMQkFm9RuE= -github.com/vicanso/go-charts/v2 v2.6.1/go.mod h1:Ii2KDI3udTG1wPtiTnntzjlUBJVJTqNscMzh3oYHzUk= +github.com/vicanso/go-charts/v2 v2.6.3 h1:AP+zVZw27nt7kjxY5js70M3YfroDRCodrpdqW/Gdxh4= +github.com/vicanso/go-charts/v2 v2.6.3/go.mod h1:Ii2KDI3udTG1wPtiTnntzjlUBJVJTqNscMzh3oYHzUk= github.com/wcharczuk/go-chart/v2 v2.1.1 h1:2u7na789qiD5WzccZsFz4MJWOJP72G+2kUuJoSNqWnE= github.com/wcharczuk/go-chart/v2 v2.1.1/go.mod h1:CyCAUt2oqvfhCl6Q5ZvAZwItgpQKZOkCJGb+VGv6l14= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= diff --git a/pkg/chart.go b/pkg/chart.go index 0afc3fc..dc4be78 100644 --- a/pkg/chart.go +++ b/pkg/chart.go @@ -48,7 +48,7 @@ type ChartRequest struct { Width int `json:"width" query:"width" form:"width" default:"1024"` Height int `json:"height" query:"height" form:"height" default:"768"` Style string `json:"style" query:"style" form:"style" default:"vertical"` - Fill bool `json:"fill" query:"fill" form:"fill" default:"false"` + Line string `json:"line" query:"line" default:"nofill" validate:"oneof=nofill fill" message:"line must be fill"` Output string `json:"output" query:"output" form:"output" default:"png"` } diff --git a/pkg/line_chart.go b/pkg/line_chart.go index 268b75a..a190290 100644 --- a/pkg/line_chart.go +++ b/pkg/line_chart.go @@ -17,6 +17,10 @@ func NewLineChart() *LineChart { } func (c *LineChart) Get(xData []string, yData [][]float64, names []string, req *ChartRequest) ([]byte, error) { + fill := false + if req.Line == "fill" { + fill = true + } p, err := charts.LineRender( yData, charts.HeightOptionFunc(req.Height), @@ -44,7 +48,7 @@ func (c *LineChart) Get(xData []string, yData [][]float64, names []string, req * opt.ValueFormatter = func(f float64) string { return fmt.Sprintf("%s %s", NumberToK(&f), req.Metric) } - opt.FillArea = req.Fill + opt.FillArea = fill idx := len(opt.SeriesList) - 1 if len(opt.SeriesList) > 1 {