feat: support rotate series label
This commit is contained in:
parent
55eca7b0b9
commit
4fc250aefc
5 changed files with 66 additions and 12 deletions
19
bar_chart.go
19
bar_chart.go
|
|
@ -23,6 +23,8 @@
|
|||
package charts
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/wcharczuk/go-chart/v2"
|
||||
)
|
||||
|
|
@ -164,11 +166,26 @@ func (b *barChart) render(result *defaultRenderResult, seriesList SeriesList) (B
|
|||
if labelPainter == nil {
|
||||
continue
|
||||
}
|
||||
y := barMaxHeight - h
|
||||
radians := float64(0)
|
||||
var fontColor Color
|
||||
if series.Label.Position == PositionBottom {
|
||||
y = barMaxHeight
|
||||
radians = -math.Pi / 2
|
||||
if isLightColor(fillColor) {
|
||||
fontColor = defaultLightFontColor
|
||||
} else {
|
||||
fontColor = defaultDarkFontColor
|
||||
}
|
||||
}
|
||||
labelPainter.Add(LabelValue{
|
||||
Index: index,
|
||||
Value: item.Value,
|
||||
X: x + barWidth>>1,
|
||||
Y: barMaxHeight - h,
|
||||
Y: y,
|
||||
// 旋转
|
||||
Radians: radians,
|
||||
FontColor: fontColor,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue