go-chart
go-chart copied to clipboard
Grid lines not showing up | documentation?
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:
Is this a missing feature, am I doing anything wrong or is it buggy? Thank you very much!
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,
}
Unfortunately, not working for BarChart. Any ideas on this?
Unfortunately, not working for BarChart. Any ideas on this?
based on issue #139 I don't think it's implemented