Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table not support FontColor #61

Open
lt123456 opened this issue Nov 9, 2023 · 5 comments
Open

table not support FontColor #61

lt123456 opened this issue Nov 9, 2023 · 5 comments

Comments

@lt123456
Copy link

lt123456 commented Nov 9, 2023

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
}

@lt123456 lt123456 changed the title table table not support FontColor Nov 9, 2023
@vicanso
Copy link
Owner

vicanso commented Nov 9, 2023

Please use CellTextStyle for setting font color.

@lt123456
Copy link
Author

lt123456 commented Nov 9, 2023 via email

@lt123456
Copy link
Author

lt123456 commented Nov 9, 2023

image 我想实现的, 比如分数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
	},

按你说的设置了还是没生效。我还没加数据判断

@vicanso
Copy link
Owner

vicanso commented Nov 9, 2023

可根据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)
}
image

@lt123456
Copy link
Author

lt123456 commented Feb 21, 2024

hello,新年好,(整行字指定文字颜色,指定背景颜色都搞定了,现在又遇到新的问题)
1708508331386

如图所示:
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)

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants