go-chart/examples/axes_labels/main.go

41 lines
957 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
chart "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
/*
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{
XAxis: chart.XAxis{
2019-09-10 00:02:48 -04:00
Name: "The XAxis",
2016-07-16 23:53:46 -04:00
},
YAxis: chart.YAxis{
2019-09-10 00:02:48 -04:00
Name: "The YAxis",
2016-07-16 23:53:46 -04:00
},
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
}