Open lt123456 opened 11 months ago
Please use CellTextStyle
for setting font color.
好的。谢谢
我想实现的, 比如分数100 标记绿色,不及格标记红色
bgColor := charts.Color{
R: 16,
G: 22,
B: 30,
A: 255,
}
p, err = charts.TableOptionRender(charts.TableChartOption{
Header: []string{
"Name",
"Price",
"Change",
},
BackgroundColor: bgColor,
HeaderBackgroundColor: bgColor,
RowBackgroundColors: []charts.Color{
bgColor,
},
HeaderFontColor: drawing.ColorWhite,
FontColor: drawing.ColorWhite,
Padding: charts.Box{
Top: 15,
Right: 10,
Bottom: 15,
Left: 10,
},
Data: [][]string{
{
"Datadog Inc",
"97.32",
"-7.49%",
},
{
"Hashicorp Inc",
"28.66",
"-9.25%",
},
{
"Gitlab Inc",
"51.63",
"+4.32%",
},
},
TextAligns: []string{
"",
charts.AlignRight,
charts.AlignRight,
},
CellTextStyle: func(tc charts.TableCell) *charts.Style {
style := charts.Style{
}
style.FillColor = drawing.ColorBlue
style.FontColor = drawing.ColorRed
return &style
},
按你说的设置了还是没生效。我还没加数据判断
可根据Column与Row来指定颜色,或者根据Text转换回数值再判断也可以。若还有问题,提供完整的可执行的代码示例。
package main
import (
"fmt"
"os"
"github.com/vicanso/go-charts/v2"
"github.com/wcharczuk/go-chart/v2/drawing"
)
func main() {
header := []string{
"Name",
"Age",
"Address",
"Tag",
"Action",
}
data := [][]string{
{
"John Brown",
"32",
"New York No. 1 Lake Park",
"nice, developer",
"Send Mail",
},
{
"Jim Green ",
"42",
"London No. 1 Lake Park",
"wow",
"Send Mail",
},
{
"Joe Black ",
"32",
"Sidney No. 1 Lake Park",
"cool, teacher",
"Send Mail",
},
}
p, err := charts.TableOptionRender(charts.TableChartOption{
Header: header,
Data: data,
CellTextStyle: func(tc charts.TableCell) *charts.Style {
if tc.Row == 0 && tc.Column == 0 {
return &charts.Style{
FontColor: drawing.ColorBlue,
}
}
fmt.Println(tc.Row)
fmt.Println(tc.Column)
return nil
},
})
if err != nil {
panic(err)
}
buf, err := p.Bytes()
if err != nil {
panic(err)
}
os.WriteFile("./test.png", buf, 0600)
}
hello,新年好,(整行字指定文字颜色,指定背景颜色都搞定了,现在又遇到新的问题)
如图所示: 1.想在特定列加一行 用来区分 内容项目| 内容 比如红色
2.想给某个单元格 增加 border 如同蓝色部分,这2个如何实现呀,求教
`package main
import ( "fmt" "os"
"github.com/vicanso/go-charts/v2"
"github.com/wcharczuk/go-chart/v2/drawing"
)
func main() { header := []string{ "Name", "Age", "Address", "Tag", "Action", } data := [][]string{ { "John Brown", "32", "New York No. 1 Lake Park", "nice, developer", "Send Mail", }, { "Jim Green ", "42", "London No. 1 Lake Park", "wow", "Send Mail", }, { "Joe Black ", "32", "Sidney No. 1 Lake Park", "cool, teacher", "Send Mail", }, }
p, err := charts.TableOptionRender(charts.TableChartOption{
Header: header,
Data: data,
CellTextStyle: func(tc charts.TableCell) *charts.Style {
if tc.Row == 0 && tc.Column == 0 {
return &charts.Style{
FontColor: drawing.ColorBlue,
}
}
fmt.Println(tc.Row)
fmt.Println(tc.Column)
return nil
},
})
if err != nil {
panic(err)
}
buf, err := p.Bytes()
if err != nil {
panic(err)
}
os.WriteFile("./test.png", buf, 0600)
}`
table not support FontColor, I. test data, it not support , I need you help CellStyle: func(tc charts.TableCell) *charts.Style { style := charts.Style{ Padding: charts.Box{ Bottom: 5, }, } style.FontColor = drawing.ColorRed return &style }