Debian Codegraph @

examples/custom_formatters/main.go

raw symbols SCIP
1 package main
2
3 //go:generate go run main.go
4
5 import (
6 "fmt"
7 "os"
8
9 "github.com/wcharczuk/go-chart/v2"
10 )
11
12 func main() {
13 /*
14 In this example we use a custom `ValueFormatter` for the y axis, letting us specify how to format text of the y-axis ticks.
15 You can also do this for the x-axis, or the secondary y-axis.
16 This example also shows what the chart looks like with the x-axis left off or not shown.
17 */
18
19 graph := chart.Chart{
20 YAxis: chart.YAxis{
21 ValueFormatter: func(v interface{}) string {
22 if vf, isFloat := v.(float64); isFloat {
23 return fmt.Sprintf("%0.6f", vf)
24 }
25 return ""
26 },
27 },
28 Series: []chart.Series{
29 chart.ContinuousSeries{
30 XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
31 YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
32 },
33 },
34 }
35 f, _ := os.Create("output.png")
36 defer f.Close()
37 graph.Render(chart.PNG, f)
38 }