fix: support chinese for axis, #4
This commit is contained in:
parent
a713c3023e
commit
cad8296e28
4 changed files with 7 additions and 0 deletions
|
|
@ -219,3 +219,5 @@ BenchmarkMultiChartSVGRender-8 367 3356325 ns/op
|
||||||
|
|
||||||
默认使用的字符为`roboto`为英文字体库,因此如果需要显示中文字符需要增加中文字体库,`InstallFont`函数可添加对应的字体库,成功添加之后则指定`title.textStyle.fontFamily`即可。
|
默认使用的字符为`roboto`为英文字体库,因此如果需要显示中文字符需要增加中文字体库,`InstallFont`函数可添加对应的字体库,成功添加之后则指定`title.textStyle.fontFamily`即可。
|
||||||
在浏览器中使用`svg`时,如果指定的`fontFamily`不支持中文字符,展示的中文并不会乱码,但是会导致在计算字符宽度等错误。
|
在浏览器中使用`svg`时,如果指定的`fontFamily`不支持中文字符,展示的中文并不会乱码,但是会导致在计算字符宽度等错误。
|
||||||
|
|
||||||
|
[中文字库noto-cjk](https://github.com/googlefonts/noto-cjk)
|
||||||
1
chart.go
1
chart.go
|
|
@ -190,6 +190,7 @@ func (o *ChartOption) FillDefault(theme string) {
|
||||||
if o.XAxis.Theme == "" {
|
if o.XAxis.Theme == "" {
|
||||||
o.XAxis.Theme = theme
|
o.XAxis.Theme = theme
|
||||||
}
|
}
|
||||||
|
o.XAxis.Font = o.Font
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ChartOption) getWidth() int {
|
func (o *ChartOption) getWidth() int {
|
||||||
|
|
|
||||||
3
xaxis.go
3
xaxis.go
|
|
@ -23,10 +23,12 @@
|
||||||
package charts
|
package charts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/golang/freetype/truetype"
|
||||||
"github.com/wcharczuk/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type XAxisOption struct {
|
type XAxisOption struct {
|
||||||
|
Font *truetype.Font
|
||||||
// The boundary gap on both sides of a coordinate axis.
|
// The boundary gap on both sides of a coordinate axis.
|
||||||
// Nil or *true means the center part of two axis ticks
|
// Nil or *true means the center part of two axis ticks
|
||||||
BoundaryGap *bool
|
BoundaryGap *bool
|
||||||
|
|
@ -66,6 +68,7 @@ func drawXAxis(p *Draw, opt *XAxisOption, yAxisCount int) (int, *Range, error) {
|
||||||
Right: right,
|
Right: right,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
dXAxis.Font = opt.Font
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
yaxis.go
1
yaxis.go
|
|
@ -96,6 +96,7 @@ func drawYAxis(p *Draw, opt *ChartOption, axisIndex, xAxisHeight int, padding ch
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
dYAxis.Font = opt.Font
|
||||||
NewAxis(dYAxis, data, style).Render()
|
NewAxis(dYAxis, data, style).Render()
|
||||||
yRange.Size = dYAxis.Box.Height()
|
yRange.Size = dYAxis.Box.Height()
|
||||||
return &yRange, nil
|
return &yRange, nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue