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
|
|
@ -60,6 +60,7 @@ type BarChartOption struct {
|
|||
Title TitleOption
|
||||
// The legend option
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ type ChartOption struct {
|
|||
SymbolShow *bool
|
||||
// The stroke width of line chart
|
||||
LineStrokeWidth float64
|
||||
// The bar with of bar chart
|
||||
BarWidth int
|
||||
// Fill the area of line chart
|
||||
FillArea bool
|
||||
// The child charts
|
||||
|
|
|
|||
|
|
@ -357,6 +357,7 @@ func Render(opt ChartOption, opts ...OptionFunc) (*Painter, error) {
|
|||
Theme: opt.theme,
|
||||
Font: opt.font,
|
||||
XAxis: opt.XAxis,
|
||||
BarWidth: opt.BarWidth,
|
||||
}).render(renderResult, barSeriesList)
|
||||
return err
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue