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

Custmize colors for line in line chart #87

Open
abhijitpawar12 opened this issue Aug 13, 2024 · 1 comment
Open

Custmize colors for line in line chart #87

abhijitpawar12 opened this issue Aug 13, 2024 · 1 comment

Comments

@abhijitpawar12
Copy link

abhijitpawar12 commented Aug 13, 2024

Hi @vicanso
Can we do customisation for line colors in LineChart
func GenerateLineChart(values [][]float64, xaxisArray []string, chartName string, id string) {
minValue := 0.0
maxValue := 100.0
show := true
splitLineShow := true

yAxisOption1 := charts.YAxisOption{
	Min:           &minValue,
	Max:           &maxValue,
	Font:          nil, // Replace with actual *truetype.Font if available
	Data:          []string{"A", "B", "C"},
	FontSize:      6,
	Position:      "left",
	FontColor:     charts.Color{R: 0, G: 0, B: 0, A: 255}, // Black color
	Formatter:     "{value}",
	Color:         charts.Color{R: 255, G: 0, B: 0, A: 255}, // Red color
	Show:          &show,
	DivideCount:   5,
	Unit:          1,
	SplitLineShow: &splitLineShow,
}

fmt.Print(yAxisOption1)

p, err := charts.LineRender(
	values,

	charts.XAxisDataOptionFunc(xaxisArray),

	func(opt *charts.ChartOption) {
		opt.Legend.Padding = charts.Box{
			Top:    20,
			Bottom: 30,
		}

		opt.YAxisOptions = []charts.YAxisOption{
			{
				SplitLineShow: charts.TrueFlag(),
				FontSize:      10,
				FontColor:     charts.Color{R: 0, G: 0, B: 0, A: 255}, // Black color
				Formatter:     "{value} " + "MB",
			},
		}

		opt.XAxis = charts.XAxisOption{
			Data:      xaxisArray,
			FontSize:  10,
			FontColor: charts.Color{R: 0, G: 0, B: 0, A: 255}, // Black color
		}

		opt.SymbolShow = charts.TrueFlag()
		opt.LineStrokeWidth = 4
		opt.Width = 600
		opt.Height = 300

		// Customize line colors for each series using StrokeStyle
		colors := []charts.Color{
			{R: 255, G: 0, B: 0, A: 255}, // Red
			{R: 255, G: 0, B: 0, A: 255}, // Green
			{R: 255, G: 0, B: 0, A: 255}, // Blue
			{R: 255, G: 0, B: 0, A: 255}, // Orange
		}

		for i := range opt.SeriesList {
			opt.SeriesList[i].Style = charts.Style{
				StrokeColor: colors[i%len(colors)],
				FontColor:   colors[i%len(colors)],
				FillColor:   colors[i%len(colors)],
			}

		}
	},

	charts.TitleOptionFunc(charts.TitleOption{
		Text:      "MB",                                      // Set the title with the unit
		FontColor: charts.Color{R: 69, G: 69, B: 69, A: 255}, // Black color
	}),
)
@vicanso
Copy link
Owner

vicanso commented Aug 14, 2024

https://github.com/vicanso/go-charts/blob/main/theme.go#L124

You can add your customize theme.

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