Skip to content

Commit

Permalink
refactor: support label show for radar chart, #62
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Dec 27, 2023
1 parent c302d0f commit 98af986
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions echarts.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ func (esList EChartsSeriesList) ToSeriesList() SeriesList {
Data: NewSeriesDataFromValues(dataItem.Value.values),
Max: item.Max,
Min: item.Min,
Label: SeriesLabel{
Color: parseColor(item.Label.Color),
Show: item.Label.Show,
Distance: item.Label.Distance,
},
})
}
continue
Expand Down
9 changes: 8 additions & 1 deletion radar_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package charts
import (
"errors"

"github.com/dustin/go-humanize"
"github.com/golang/freetype/truetype"
"github.com/wcharczuk/go-chart/v2"
"github.com/wcharczuk/go-chart/v2/drawing"
Expand Down Expand Up @@ -230,9 +231,15 @@ func (r *radarChart) render(result *defaultRenderResult, seriesList SeriesList)
StrokeColor: color,
FillColor: dotFillColor,
})
for _, point := range linePoints {
for index, point := range linePoints {
seriesPainter.Circle(dotWith, point.X, point.Y)
seriesPainter.FillStroke()
if series.Label.Show && index < len(series.Data) {
value := humanize.FtoaWithDigits(series.Data[index].Value, 2)
b := seriesPainter.MeasureText(value)
seriesPainter.Text(value, point.X-b.Width()/2, point.Y)
}

}
}

Expand Down

0 comments on commit 98af986

Please sign in to comment.