Debian Codegraph @

examples/legend/main.go

raw symbols SCIP
1 package main
2
3 //go:generate go run main.go
4
5 import (
6 "os"
7
8 chart "github.com/wcharczuk/go-chart/v2"
9 )
10
11 func main() {
12
13 /*
14 In this example we add a `Renderable` or a custom component to the `Elements` array.
15 In this specific case it is a pre-built renderable (`CreateLegend`) that draws a legend for the chart's series.
16 If you like, you can use `CreateLegend` as a template for writing your own renderable, or even your own legend.
17 */
18
19 graph := chart.Chart{
20 Background: chart.Style{
21 Padding: chart.Box{
22 Top: 20,
23 Left: 20,
24 },
25 },
26 Series: []chart.Series{
27 chart.ContinuousSeries{
28 Name: "A test series",
29 XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
30 YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
31 },
32 },
33 }
34
35 //note we have to do this as a separate step because we need a reference to graph
36 graph.Elements = []chart.Renderable{
37 chart.Legend(&graph),
38 }
39
40 f, _ := os.Create("output.png")
41 defer f.Close()
42 graph.Render(chart.PNG, f)
43 }