vicanso / go-charts

A charts library for Golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

如何给 HorizontalBarRender 添加数值显示?

sicuni opened this issue · comments

values := [][]float64{
{100,200,300,100,200,300 },
}
p, err := charts.HorizontalBarRender(
values,
charts.TitleTextOptionFunc("test"),
charts.PaddingOptionFunc(charts.Box{
Top: 20,
Right: 40,
Bottom: 20,
Left: 20,
}),
func(opt *charts.ChartOption) {
opt.SeriesList[0].Label.Show = true
},
charts.YAxisDataOptionFunc([]string{
"1",
"2",
"3",
"4",
"5",
"6",
}),
)
if err != nil {
panic(err)
}

buf, err := p.Bytes()
if err != nil {
	panic(err)
}
f, _ := os.Create("test.png")
f.Write(buf)
f.Close()

暂未支持,后续版本增加

暂未支持,后续版本增加

好的

@sicuni 最新版本已支持,设置代码如下:

func(opt *charts.ChartOption) {
	opt.SeriesList[0].Label.Show = true
	// 设置展示位置在左侧(默认为右侧)
	opt.SeriesList[0].Label.Position = charts.PositionLeft
	// 设置左偏移量(也可以设置top)
	opt.SeriesList[0].Label.Offset.Left = -1
},

image

@sicuni 最新版本已支持,设置代码如下:

func(opt *charts.ChartOption) {
	opt.SeriesList[0].Label.Show = true
	// 设置展示位置在左侧(默认为右侧)
	opt.SeriesList[0].Label.Position = charts.PositionLeft
	// 设置左偏移量(也可以设置top)
	opt.SeriesList[0].Label.Offset.Left = -1
},
image

image
这个图为0的时候好像会有一些问题

values := [][]float64{
{0,0,0,0,0,0 },
}
p, err := charts.HorizontalBarRender(
values,
charts.TitleTextOptionFunc("test"),
charts.PaddingOptionFunc(charts.Box{
Top: 20,
Right: 40,
Bottom: 20,
Left: 20,
}),
func(opt *charts.ChartOption) {
opt.SeriesList[0].Label.Show = true
},
charts.YAxisDataOptionFunc([]string{
"1",
"2",
"3",
"4",
"5",
"6",
}),
)
if err != nil {
panic(err)
}
buf, err := p.Bytes()
if err != nil {
panic(err)
}
f, _ := os.Create("test.png")
f.Write(buf)
f.Close()
image

晚点修复

@sicuni 使用最新版本试试

@sicuni 使用最新版本试试

image
显示的字体颜色是否支持可配置一下?数值太小的时候和背景几乎完全看不清...

现在是根据柱状图的背景色判断使用黑色或白色字体,有期望的展示截图不,后续参考调整

现在是根据柱状图的背景色判断使用黑色或白色字体,有期望的展示截图不,后续参考调整

func(opt *charts.ChartOption) {
opt.SeriesList[0].Label.Show = true
// 设置展示位置在左侧(默认为右侧)
opt.SeriesList[0].Label.Position = charts.PositionLeft
opt.SeriesList[0].Label.Color = drawing.ColorBlack
},
opt.SeriesList[0].Label.Color = drawing.ColorBlack 这个目前好像不支持, 能否支持一下?
在生成图的过程中存在的问题如图:这里的10白色显示
image

晚点修复

@sicuni 使用最新版本试试

@sicuni 使用最新版本试试

好的、非常感谢!