Debian Codegraph @

examples/simple_moving_average/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 mainSeries := chart.ContinuousSeries{
13 Name: "A test series",
14 XValues: chart.Seq{Sequence: chart.NewLinearSequence().WithStart(1.0).WithEnd(100.0)}.Values(), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
15 YValues: chart.Seq{Sequence: chart.NewRandomSequence().WithLen(100).WithMin(0).WithMax(100)}.Values(), //generates a []float64 randomly from 0 to 100 with 100 elements.
16 }
17
18 // note we create a SimpleMovingAverage series by assignin the inner series.
19 // we need to use a reference because `.Render()` needs to modify state within the series.
20 smaSeries := &chart.SMASeries{
21 InnerSeries: mainSeries,
22 } // we can optionally set the `WindowSize` property which alters how the moving average is calculated.
23
24 graph := chart.Chart{
25 Series: []chart.Series{
26 mainSeries,
27 smaSeries,
28 },
29 }
30
31 f, _ := os.Create("output.png")
32 defer f.Close()
33 graph.Render(chart.PNG, f)
34 }