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

Spark lines

Open carbocation opened this issue 4 years ago • 1 comments

Spark lines are the first item featured in the Readme, but there isn't a shortcut for building them. Just wanted to point this out since they do seem handy enough that they might merit a quick example. Thanks for creating this library! image

carbocation avatar Feb 23 '21 20:02 carbocation

Hey @carbocation, you probably found the answer already. But I had the same question and came across this issue.

In case if somebody else is having the same question — the answer is pretty simple because the only code example in readme IS the sparkline. Sparkline is the line chart.

import (
    ...
    "bytes"
    ...
    "github.com/wcharczuk/go-chart" //exposes "chart"
)

graph := chart.Chart{
    Series: []chart.Series{
        chart.ContinuousSeries{
            XValues: []float64{1.0, 2.0, 3.0, 4.0},
            YValues: []float64{1.0, 2.0, 3.0, 4.0},
        },
    },
}

buffer := bytes.NewBuffer([]byte{})
err := graph.Render(chart.PNG, buffer)

Will generate this:

image

That obviously doesn't look like sparkline you expect, but here's what exactly the same code will do with real data:

image

toydestroyer avatar Jun 04 '21 11:06 toydestroyer