wcharczuk / go-chart

go chart is a basic charting library in go.
MIT License
3.99k stars 326 forks source link

Grid lines not showing up | documentation? #107

Open robbbsen opened 5 years ago

robbbsen commented 5 years ago

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!

sebastian-stephan commented 5 years ago

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

yznts commented 3 years ago

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

karageee commented 1 year ago

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

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