Debian Codegraph @

examples/legend_left/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
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: 260,
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 chart.ContinuousSeries{
34 Name: "Another test series",
35 XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
36 YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
37 },
38
39 chart.ContinuousSeries{
40 Name: "Yet Another test series",
41 XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
42 YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
43 },
44
45 chart.ContinuousSeries{
46 Name: "Even More series",
47 XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
48 YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
49 },
50
51 chart.ContinuousSeries{
52 Name: "Foo Bar",
53 XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
54 YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
55 },
56
57 chart.ContinuousSeries{
58 Name: "Bar Baz",
59 XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
60 YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
61 },
62
63 chart.ContinuousSeries{
64 Name: "Moo Bar",
65 XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
66 YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
67 },
68
69 chart.ContinuousSeries{
70 Name: "Zoo Bar Baz",
71 XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
72 YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
73 },
74
75 chart.ContinuousSeries{
76 Name: "Fast and the Furious",
77 XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
78 YValues: []float64{5.0, 4.0, 3.0, 2.0, 1.0},
79 },
80
81 chart.ContinuousSeries{
82 Name: "2 Fast 2 Furious",
83 XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
84 YValues: []float64{5.0, 4.0, 3.0, 2.0, 1.0},
85 },
86
87 chart.ContinuousSeries{
88 Name: "They only get more fast and more furious",
89 XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
90 YValues: []float64{5.0, 4.0, 3.0, 2.0, 1.0},
91 },
92 },
93 }
94
95 //note we have to do this as a separate step because we need a reference to graph
96 graph.Elements = []chart.Renderable{
97 chart.LegendLeft(&graph),
98 }
99
100 f, _ := os.Create("output.png")
101 defer f.Close()
102 graph.Render(chart.PNG, f)
103 }