Debian Codegraph @

examples/benchmark_line_charts/main.go

raw symbols SCIP
1 package main
2
3 //go:generate go run main.go
4
5 import (
6 "fmt"
7 "math/rand"
8 "os"
9 "time"
10
11 "github.com/wcharczuk/go-chart/v2"
12 )
13
14 func random(min, max float64) float64 {
15 return rand.Float64()*(max-min) + min
16 }
17
18 func main() {
19 numValues := 1024
20 numSeries := 100
21 series := make([]chart.Series, numSeries)
22
23 for i := 0; i < numSeries; i++ {
24 xValues := make([]time.Time, numValues)
25 yValues := make([]float64, numValues)
26
27 for j := 0; j < numValues; j++ {
28 xValues[j] = time.Now().AddDate(0, 0, (numValues-j)*-1)
29 yValues[j] = random(float64(-500), float64(500))
30 }
31
32 series[i] = chart.TimeSeries{
33 Name: fmt.Sprintf("aaa.bbb.hostname-%v.ccc.ddd.eee.fff.ggg.hhh.iii.jjj.kkk.lll.mmm.nnn.value", i),
34 XValues: xValues,
35 YValues: yValues,
36 }
37 }
38
39 graph := chart.Chart{
40 XAxis: chart.XAxis{
41 Name: "Time",
42 },
43 YAxis: chart.YAxis{
44 Name: "Value",
45 },
46 Series: series,
47 }
48
49 f, _ := os.Create("output.png")
50 defer f.Close()
51 graph.Render(chart.PNG, f)
52 }