Debian Codegraph @

examples/custom_ticks/main.go

raw symbols SCIP
1 package main
2
3 //go:generate go run main.go
4
5 import (
6 "os"
7
8 "github.com/wcharczuk/go-chart/v2"
9 )
10
11 func main() {
12 /*
13 In this example we set a custom set of ticks to use for the y-axis. It can be (almost) whatever you want, including some custom labels for ticks.
14 Custom ticks will supercede a custom range, which will supercede automatic generation based on series values.
15 */
16
17 graph := chart.Chart{
18 YAxis: chart.YAxis{
19 Range: &chart.ContinuousRange{
20 Min: 0.0,
21 Max: 4.0,
22 },
23 Ticks: []chart.Tick{
24 {Value: 0.0, Label: "0.00"},
25 {Value: 2.0, Label: "2.00"},
26 {Value: 4.0, Label: "4.00"},
27 {Value: 6.0, Label: "6.00"},
28 {Value: 8.0, Label: "Eight"},
29 {Value: 10.0, Label: "Ten"},
30 },
31 },
32 Series: []chart.Series{
33 chart.ContinuousSeries{
34 XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
35 YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
36 },
37 },
38 }
39 f, _ := os.Create("output.png")
40 defer f.Close()
41 graph.Render(chart.PNG, f)
42 }