feat: support setting bar width for bar chart, #24
This commit is contained in:
parent
1f5b9d513e
commit
0a80e7056f
3 changed files with 14 additions and 5 deletions
10
bar_chart.go
10
bar_chart.go
|
|
@ -59,7 +59,8 @@ type BarChartOption struct {
|
|||
// The option of title
|
||||
Title TitleOption
|
||||
// The legend option
|
||||
Legend LegendOption
|
||||
Legend LegendOption
|
||||
BarWidth int
|
||||
}
|
||||
|
||||
func (b *barChart) render(result *defaultRenderResult, seriesList SeriesList) (Box, error) {
|
||||
|
|
@ -86,7 +87,12 @@ func (b *barChart) render(result *defaultRenderResult, seriesList SeriesList) (B
|
|||
}
|
||||
seriesCount := len(seriesList)
|
||||
// 总的宽度-两个margin-(总数-1)的barMargin
|
||||
barWidth := (width - 2*margin - barMargin*(seriesCount-1)) / len(seriesList)
|
||||
barWidth := (width - 2*margin - barMargin*(seriesCount-1)) / seriesCount
|
||||
if opt.BarWidth > 0 && opt.BarWidth < barWidth {
|
||||
barWidth = opt.BarWidth
|
||||
// 重新计算margin
|
||||
margin = (width - len(seriesList)*barWidth - barMargin*(seriesCount-1)) / 2
|
||||
}
|
||||
barMaxHeight := seriesPainter.Height()
|
||||
theme := opt.Theme
|
||||
seriesNames := seriesList.Names()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue