go-chart icon indicating copy to clipboard operation
go-chart copied to clipboard

Grid lines not showing up | documentation?

Open robbbsen opened this issue 6 years ago • 3 comments

Hi. Unfortunately the topic "grid lines" isn't documented at all. The only thing I could find was a test file inside the project. Out of that I've created a small test:

ticks := []chart.Tick{
	{Value: 1.0, Label: "1.0"},
	{Value: 2.0, Label: "2.0"},
	{Value: 3.0, Label: "3.0"},
	{Value: 4.0, Label: "4.0"},
}

lines := chart.GenerateGridLines(ticks, chart.Style{}, chart.Style{})

graph := chart.Chart{
	XAxis: chart.XAxis{
		Ticks: ticks,
		Style: chart.StyleShow(),
		GridLines: lines,
	},
	YAxis: chart.YAxis{
		Ticks: ticks,
		Style: chart.StyleShow(),
		GridLines: lines,
	},
	Series: []chart.Series{
		chart.ContinuousSeries{
			XValues: []float64{1, 2, 3, 4},
			YValues: []float64{1, 2, 3, 1},
			Style: chart.Style{StrokeWidth: 3, Show: true},
		},
	},
	Width: 570,
	Height: 300,
}

Unfortunately this isn't displaying any grind lines. Output:

temp

Is this a missing feature, am I doing anything wrong or is it buggy? Thank you very much!

robbbsen avatar Oct 29 '18 17:10 robbbsen

You have to set GridMajorStyle and GridMinorStyle ond the axis and set Show, StrokeColor and StrokeWidth. As far as I know otherwise they default to false, ColorTransparent and 0.0, which each of them makes them invisible.

	graph = chart.Chart{
		XAxis: chart.XAxis{
			Style: chart.StyleShow(),
		},
		YAxis: chart.YAxis{
			Style: chart.StyleShow(),
			GridMajorStyle: chart.Style{
				Show:        true,
				StrokeColor: drawing.ColorBlack,
				StrokeWidth: 1.5,
			},
			GridMinorStyle: chart.Style{
				Show:        true,
				StrokeColor: drawing.Color{R: 0, G: 0, B: 0, A: 100},
				StrokeWidth: 1.0,
			},
		},
		Series: []chart.Series{
			chart.ContinuousSeries{
				XValues: []float64{1, 2, 3, 4},
				YValues: []float64{1, 2, 3, 1},
				Style:   chart.Style{StrokeWidth: 3, Show: true},
			},
		},
		Width:  570,
		Height: 300,
	}

image

sebastian-stephan avatar Mar 01 '19 09:03 sebastian-stephan

Unfortunately, not working for BarChart. Any ideas on this?

yznts avatar Oct 18 '21 18:10 yznts

Unfortunately, not working for BarChart. Any ideas on this?

based on issue #139 I don't think it's implemented

karageee avatar Jan 19 '23 03:01 karageee