go-chart
go-chart copied to clipboard
Can't show long label at XAxis in BarChart
When the label is too long to show the label at one line, the label is dispeared, and I puzzled! I finally find the problem, in BarChart's function drawXAxis, there is calling of function Draw.TextWithin, this function has a bug;
in draw.go line 23 lines := Text.WrapFit(r, text, box.Width(), style) lines array will contains empty string, like ["", "test"], empty string will cause lineBox := r.MeasureText(line), lineBox.Width() and lineBox.Height() get invalid value.
I fixed this by rewriting the code in text.go WrapFitWord function, line 101
// old
output = append(output, t.Trim(line))
// new
if len(line) != 0 {
output = append(output, t.Trim(line))
}
当BarChat的横坐标的标签过长时,会导致标签不显示。
原因是 在BarChart调用drawXAxis,Draw.TextWithin, 在一个框里画标签时,首先会将标签分成多行lines := Text.WrapFit(r, text, box.Width(), style)
,然而分成多行后,lines数组里总是有空字符串,空字符串会导致在计算box时无法获取box的高和宽,导致文字的坐标偏离十万八千里。
我通过改源码修复,在in text.go WrapFitWord function, 101行:
// old
output = append(output, t.Trim(line))
// new
if len(line) != 0 {
output = append(output, t.Trim(line))
}
Any update on this?