go-chart/examples/annotations/main.go

45 lines
1.2 KiB
Go
Raw Permalink Normal View History

2016-07-16 23:53:46 -04:00
package main
2019-09-10 00:02:48 -04:00
//go:generate go run main.go
2016-07-16 23:53:46 -04:00
import (
2019-09-10 00:02:48 -04:00
"os"
2016-07-16 23:53:46 -04:00
"github.com/wcharczuk/go-chart/v2"
2016-07-16 23:53:46 -04:00
)
2019-09-10 00:02:48 -04:00
func main() {
2016-07-16 23:53:46 -04:00
/*
In this example we add an `Annotation` series, which is a special type of series that
draws annotation labels at given X and Y values (as translated by their respective ranges).
It is important to not that the chart automatically sizes the canvas box to fit the annotations,
As well as automatically assign a series color for the `Stroke` or border component of the series.
The annotation series is most often used by the original author to show the last value of another series, but
they can be used in other capacities as well.
*/
graph := chart.Chart{
Series: []chart.Series{
chart.ContinuousSeries{
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
},
chart.AnnotationSeries{
2016-07-28 17:35:17 -04:00
Annotations: []chart.Value2{
{XValue: 1.0, YValue: 1.0, Label: "One"},
{XValue: 2.0, YValue: 2.0, Label: "Two"},
{XValue: 3.0, YValue: 3.0, Label: "Three"},
{XValue: 4.0, YValue: 4.0, Label: "Four"},
{XValue: 5.0, YValue: 5.0, Label: "Five"},
2016-07-16 23:53:46 -04:00
},
},
},
}
2019-09-10 00:02:48 -04:00
f, _ := os.Create("output.png")
defer f.Close()
graph.Render(chart.PNG, f)
2016-07-16 23:53:46 -04:00
}