go-chart/examples/min_max/main.go

62 lines
1.3 KiB
Go
Raw Normal View History

2016-08-06 18:53:14 -04:00
package main
2019-09-10 00:02:48 -04:00
//go:generate go run main.go
2016-08-06 18:53:14 -04:00
import (
2019-09-10 00:02:48 -04:00
"os"
2016-08-06 18:53:14 -04:00
2024-10-27 22:52:38 -04:00
"git.smarteching.com/zeni/go-chart/v2"
2016-08-06 18:53:14 -04:00
)
2019-09-10 00:02:48 -04:00
func main() {
2016-08-06 18:53:14 -04:00
mainSeries := chart.ContinuousSeries{
Name: "A test series",
2019-09-10 00:02:48 -04:00
XValues: chart.Seq{Sequence: chart.NewLinearSequence().WithStart(1.0).WithEnd(100.0)}.Values(),
YValues: chart.Seq{Sequence: chart.NewRandomSequence().WithLen(100).WithMin(50).WithMax(150)}.Values(),
2016-08-06 18:53:14 -04:00
}
minSeries := &chart.MinSeries{
Style: chart.Style{
StrokeColor: chart.ColorAlternateGray,
StrokeDashArray: []float64{5.0, 5.0},
},
InnerSeries: mainSeries,
}
maxSeries := &chart.MaxSeries{
Style: chart.Style{
StrokeColor: chart.ColorAlternateGray,
StrokeDashArray: []float64{5.0, 5.0},
},
InnerSeries: mainSeries,
}
graph := chart.Chart{
2016-08-07 00:59:46 -04:00
Width: 1920,
Height: 1080,
2016-08-06 18:53:14 -04:00
YAxis: chart.YAxis{
2019-09-10 00:02:48 -04:00
Name: "Random Values",
2016-08-06 18:53:14 -04:00
Range: &chart.ContinuousRange{
Min: 25,
Max: 175,
},
},
XAxis: chart.XAxis{
2019-09-10 00:02:48 -04:00
Name: "Random Other Values",
2016-08-06 18:53:14 -04:00
},
Series: []chart.Series{
mainSeries,
minSeries,
maxSeries,
2019-09-10 00:02:48 -04:00
chart.LastValueAnnotationSeries(minSeries),
chart.LastValueAnnotationSeries(maxSeries),
2016-08-06 18:53:14 -04:00
},
}
2016-08-07 00:59:46 -04:00
graph.Elements = []chart.Renderable{chart.Legend(&graph)}
2019-09-10 00:02:48 -04:00
f, _ := os.Create("output.png")
defer f.Close()
graph.Render(chart.PNG, f)
2016-08-06 18:53:14 -04:00
}