Debian Codegraph @

examples/bar_chart_base_value/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 "github.com/wcharczuk/go-chart/v2/drawing"
10 )
11
12 func main() {
13 profitStyle := chart.Style{
14 FillColor: drawing.ColorFromHex("13c158"),
15 StrokeColor: drawing.ColorFromHex("13c158"),
16 StrokeWidth: 0,
17 }
18
19 lossStyle := chart.Style{
20 FillColor: drawing.ColorFromHex("c11313"),
21 StrokeColor: drawing.ColorFromHex("c11313"),
22 StrokeWidth: 0,
23 }
24
25 sbc := chart.BarChart{
26 Title: "Bar Chart Using BaseValue",
27 Background: chart.Style{
28 Padding: chart.Box{
29 Top: 40,
30 },
31 },
32 Height: 512,
33 BarWidth: 60,
34 YAxis: chart.YAxis{
35 Ticks: []chart.Tick{
36 {Value: -4.0, Label: "-4"},
37 {Value: -2.0, Label: "-2"},
38 {Value: 0, Label: "0"},
39 {Value: 2.0, Label: "2"},
40 {Value: 4.0, Label: "4"},
41 {Value: 6.0, Label: "6"},
42 {Value: 8.0, Label: "8"},
43 {Value: 10.0, Label: "10"},
44 {Value: 12.0, Label: "12"},
45 },
46 },
47 UseBaseValue: true,
48 BaseValue: 0.0,
49 Bars: []chart.Value{
50 {Value: 10.0, Style: profitStyle, Label: "Profit"},
51 {Value: 12.0, Style: profitStyle, Label: "More Profit"},
52 {Value: 8.0, Style: profitStyle, Label: "Still Profit"},
53 {Value: -4.0, Style: lossStyle, Label: "Loss!"},
54 {Value: 3.0, Style: profitStyle, Label: "Phew Ok"},
55 {Value: -2.0, Style: lossStyle, Label: "Oh No!"},
56 },
57 }
58
59 f, _ := os.Create("output.png")
60 defer f.Close()
61 sbc.Render(chart.PNG, f)
62 }