| 1 |
package main |
| 2 |
|
| 3 |
|
| 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(), |
| 15 |
YValues: chart.Seq{Sequence: chart.NewRandomSequence().WithLen(100).WithMin(50).WithMax(150)}.Values(), |
| 16 |
} |
| 17 |
|
| 18 |
minSeries := &chart.MinSeries{ |
| 19 |
Style: chart.Style{ |
| 20 |
StrokeColor: chart.ColorAlternateGray, |
| 21 |
StrokeDashArray: []float64{5.0, 5.0}, |
| 22 |
}, |
| 23 |
InnerSeries: mainSeries, |
| 24 |
} |
| 25 |
|
| 26 |
maxSeries := &chart.MaxSeries{ |
| 27 |
Style: chart.Style{ |
| 28 |
StrokeColor: chart.ColorAlternateGray, |
| 29 |
StrokeDashArray: []float64{5.0, 5.0}, |
| 30 |
}, |
| 31 |
InnerSeries: mainSeries, |
| 32 |
} |
| 33 |
|
| 34 |
graph := chart.Chart{ |
| 35 |
Width: 1920, |
| 36 |
Height: 1080, |
| 37 |
YAxis: chart.YAxis{ |
| 38 |
Name: "Random Values", |
| 39 |
Range: &chart.ContinuousRange{ |
| 40 |
Min: 25, |
| 41 |
Max: 175, |
| 42 |
}, |
| 43 |
}, |
| 44 |
XAxis: chart.XAxis{ |
| 45 |
Name: "Random Other Values", |
| 46 |
}, |
| 47 |
Series: []chart.Series{ |
| 48 |
mainSeries, |
| 49 |
minSeries, |
| 50 |
maxSeries, |
| 51 |
chart.LastValueAnnotationSeries(minSeries), |
| 52 |
chart.LastValueAnnotationSeries(maxSeries), |
| 53 |
}, |
| 54 |
} |
| 55 |
|
| 56 |
graph.Elements = []chart.Renderable{chart.Legend(&graph)} |
| 57 |
|
| 58 |
f, _ := os.Create("output.png") |
| 59 |
defer f.Close() |
| 60 |
graph.Render(chart.PNG, f) |
| 61 |
} |