Skip to content

Commit

Permalink
fix: fix x axis label of horizontal bar chart, #42
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Jan 11, 2023
1 parent e101755 commit 8ba9e2e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
11 changes: 10 additions & 1 deletion charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,16 @@ func defaultRender(p *Painter, opt defaultRenderOption) (*defaultRenderResult, e
yAxisOption.Data = r.Values()
} else {
yAxisOption.isCategoryAxis = true
opt.XAxis.Data = r.Values()
// 由于x轴为value部分,因此计算其label单独处理
opt.XAxis.Data = NewRange(AxisRangeOption{
Painter: p,
Min: min,
Max: max,
// 高度需要减去x轴的高度
Size: rangeHeight,
// 分隔数量
DivideCount: defaultAxisDivideCount,
}).Values()
opt.XAxis.isValueAxis = true
}
reverseStringSlice(yAxisOption.Data)
Expand Down
28 changes: 14 additions & 14 deletions examples/horizontal_bar_chart/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ func writeFile(buf []byte) error {
func main() {
values := [][]float64{
{
8203,
18203,
23489,
29034,
104970,
131744,
630230,
10,
30,
50,
70,
90,
110,
130,
},
{
9325,
19325,
23438,
31000,
121594,
134141,
681807,
20,
40,
60,
80,
100,
120,
140,
},
}
p, err := charts.HorizontalBarRender(
Expand Down

0 comments on commit 8ba9e2e

Please sign in to comment.