forked from gotasty/go-chart
/
main.go
69 lines (64 loc) · 1.34 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"log"
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
sbc := chart.StackedBarChart{
Title: "Test Stacked Bar Chart",
TitleStyle: chart.StyleShow(),
Background: chart.Style{
Padding: chart.Box{
Top: 40,
},
},
Height: 512,
XAxis: chart.Style{
Show: true,
},
YAxis: chart.Style{
Show: true,
},
Bars: []chart.StackedBar{
{
Name: "This is a very long string to test word break wrapping.",
Values: []chart.Value{
{Value: 5, Label: "Blue"},
{Value: 5, Label: "Green"},
{Value: 4, Label: "Gray"},
{Value: 3, Label: "Orange"},
{Value: 3, Label: "Test"},
{Value: 2, Label: "??"},
{Value: 1, Label: "!!"},
},
},
{
Name: "Test",
Values: []chart.Value{
{Value: 10, Label: "Blue"},
{Value: 5, Label: "Green"},
{Value: 1, Label: "Gray"},
},
},
{
Name: "Test 2",
Values: []chart.Value{
{Value: 10, Label: "Blue"},
{Value: 6, Label: "Green"},
{Value: 4, Label: "Gray"},
},
},
},
}
res.Header().Set("Content-Type", "image/png")
err := sbc.Render(chart.PNG, res)
if err != nil {
fmt.Printf("Error rendering chart: %v\n", err)
}
}
func main() {
http.HandleFunc("/", drawChart)
log.Fatal(http.ListenAndServe(":8080", nil))
}