feat: support label for series, #1

This commit is contained in:
vicanso 2022-01-15 10:43:38 +08:00
parent a577d30eb8
commit eb421892fe
8 changed files with 148 additions and 7 deletions

View file

@ -28,6 +28,7 @@ import (
"io"
"sync"
"github.com/dustin/go-humanize"
"github.com/golang/freetype/truetype"
"github.com/wcharczuk/go-chart/v2"
"github.com/wcharczuk/go-chart/v2/drawing"
@ -174,9 +175,13 @@ func newTitleRenderable(title Title, font *truetype.Font, textColor drawing.Colo
func newPieChart(opt Options) *chart.PieChart {
values := make(chart.Values, len(opt.Series))
for index, item := range opt.Series {
label := item.Name
if item.Label.Show {
label += ":" + humanize.CommafWithDigits(item.Data[0].Value, 2)
}
values[index] = chart.Value{
Value: item.Data[0].Value,
Label: item.Name,
Label: label,
}
}
p := &chart.PieChart{