feat: support bar height for horizontal bar chart
This commit is contained in:
parent
0a80e7056f
commit
6652ece0fe
4 changed files with 11 additions and 3 deletions
|
|
@ -91,7 +91,7 @@ func (b *barChart) render(result *defaultRenderResult, seriesList SeriesList) (B
|
|||
if opt.BarWidth > 0 && opt.BarWidth < barWidth {
|
||||
barWidth = opt.BarWidth
|
||||
// 重新计算margin
|
||||
margin = (width - len(seriesList)*barWidth - barMargin*(seriesCount-1)) / 2
|
||||
margin = (width - seriesCount*barWidth - barMargin*(seriesCount-1)) / 2
|
||||
}
|
||||
barMaxHeight := seriesPainter.Height()
|
||||
theme := opt.Theme
|
||||
|
|
|
|||
|
|
@ -68,6 +68,8 @@ type ChartOption struct {
|
|||
LineStrokeWidth float64
|
||||
// The bar with of bar chart
|
||||
BarWidth int
|
||||
// The bar height of horizontal bar chart
|
||||
BarHeight int
|
||||
// Fill the area of line chart
|
||||
FillArea bool
|
||||
// The child charts
|
||||
|
|
|
|||
|
|
@ -369,6 +369,7 @@ func Render(opt ChartOption, opts ...OptionFunc) (*Painter, error) {
|
|||
_, err := NewHorizontalBarChart(p, HorizontalBarChartOption{
|
||||
Theme: opt.theme,
|
||||
Font: opt.font,
|
||||
BarHeight: opt.BarHeight,
|
||||
YAxisOptions: opt.YAxisOptions,
|
||||
}).render(renderResult, horizontalBarSeriesList)
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ type HorizontalBarChartOption struct {
|
|||
Title TitleOption
|
||||
// The legend option
|
||||
Legend LegendOption
|
||||
BarHeight int
|
||||
}
|
||||
|
||||
// NewHorizontalBarChart returns a horizontal bar chart renderer
|
||||
|
|
@ -82,7 +83,11 @@ func (h *horizontalBarChart) render(result *defaultRenderResult, seriesList Seri
|
|||
}
|
||||
seriesCount := len(seriesList)
|
||||
// 总的高度-两个margin-(总数-1)的barMargin
|
||||
barHeight := (height - 2*margin - barMargin*(seriesCount-1)) / len(seriesList)
|
||||
barHeight := (height - 2*margin - barMargin*(seriesCount-1)) / seriesCount
|
||||
if opt.BarHeight > 0 && opt.BarHeight < barHeight {
|
||||
barHeight = opt.BarHeight
|
||||
margin = (height - seriesCount*barHeight - barMargin*(seriesCount-1)) / 2
|
||||
}
|
||||
|
||||
theme := opt.Theme
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue