go-chart
go-chart copied to clipboard
How to have a TimeSeries with Annotations
Hi can you please show how to have a TimeSeries with Annotations.
Pretty much like in the example: https://github.com/wcharczuk/go-chart/blob/master/examples/annotations/main.go But use output of time.UnixNano()
as XValue
in chart.Value2
.
Pretty much like in the example: https://github.com/wcharczuk/go-chart/blob/master/examples/annotations/main.go But use output of
time.UnixNano()
asXValue
inchart.Value2
.
need to cast to float64 though, as time.UnixNano() returns int64
like that.
graph := chart.Chart{
Series: []chart.Series{
chart.TimeSeries{
XValues: []time.Time{x1, x2, x3},
YValues: []float64{1.0, 2.0, 3.0},
},
chart.AnnotationSeries{
Annotations: []chart.Value2{
{XValue: chart.TimeToFloat64(x1), YValue: 1.0, Label: "first"},
{XValue: chart.TimeToFloat64(x2), YValue: 2.0, Label: "second"},
{XValue: chart.TimeToFloat64(x3), YValue: 3.0, Label: "last"},
},
},
},
}