go-chart/examples/stacked_bar/main.go

54 lines
1,018 B
Go
Raw Normal View History

2016-07-28 21:51:55 -04:00
package main
import (
2019-09-10 00:02:48 -04:00
"os"
2016-07-28 21:51:55 -04:00
2024-10-27 22:52:38 -04:00
"git.smarteching.com/zeni/go-chart/v2"
2016-07-28 21:51:55 -04:00
)
2019-09-10 00:02:48 -04:00
func main() {
2016-07-28 21:51:55 -04:00
sbc := chart.StackedBarChart{
2019-09-10 00:02:48 -04:00
Title: "Test Stacked Bar Chart",
Background: chart.Style{
Padding: chart.Box{
Top: 40,
},
},
2016-07-30 12:38:43 -04:00
Height: 512,
2016-07-28 21:51:55 -04:00
Bars: []chart.StackedBar{
{
Name: "This is a very long string to test word break wrapping.",
2016-07-28 21:51:55 -04:00
Values: []chart.Value{
{Value: 5, Label: "Blue"},
{Value: 5, Label: "Green"},
{Value: 4, Label: "Gray"},
{Value: 3, Label: "Orange"},
2016-07-28 21:51:55 -04:00
{Value: 3, Label: "Test"},
{Value: 2, Label: "??"},
2016-07-28 21:51:55 -04:00
{Value: 1, Label: "!!"},
},
},
{
2016-07-29 22:35:18 -04:00
Name: "Test",
2016-07-28 21:51:55 -04:00
Values: []chart.Value{
{Value: 10, Label: "Blue"},
{Value: 5, Label: "Green"},
{Value: 1, Label: "Gray"},
},
},
2016-07-30 02:13:33 -04:00
{
Name: "Test 2",
Values: []chart.Value{
{Value: 10, Label: "Blue"},
2016-07-30 02:39:58 -04:00
{Value: 6, Label: "Green"},
{Value: 4, Label: "Gray"},
2016-07-30 02:13:33 -04:00
},
},
2016-07-28 21:51:55 -04:00
},
}
2019-09-10 00:02:48 -04:00
f, _ := os.Create("output.png")
defer f.Close()
sbc.Render(chart.PNG, f)
2016-07-28 21:51:55 -04:00
}