go-chart/examples/axes/main.go

35 lines
863 B
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
2024-10-27 22:52:38 -04:00
chart "git.smarteching.com/zeni/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
/*
The below will draw the same chart as the `basic` example, except with both the x and y axes turned on.
In this case, both the x and y axis ticks are generated automatically, the x and y ranges are established automatically, the canvas "box" is adjusted to fit the space the axes occupy so as not to clip.
*/
graph := chart.Chart{
Series: []chart.Series{
chart.ContinuousSeries{
Style: chart.Style{
2016-07-28 21:58:45 -04:00
StrokeColor: chart.GetDefaultColor(0).WithAlpha(64),
FillColor: chart.GetDefaultColor(0).WithAlpha(64),
},
2016-07-16 23:53:46 -04:00
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
},
},
}
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
}