2016-07-29 03:51:55 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/wcharczuk/go-chart"
|
|
|
|
)
|
|
|
|
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
|
|
sbc := chart.StackedBarChart{
|
2017-06-11 20:38:10 +02:00
|
|
|
Title: "Test Stacked Bar Chart",
|
|
|
|
TitleStyle: chart.StyleShow(),
|
|
|
|
Background: chart.Style{
|
|
|
|
Padding: chart.Box{
|
|
|
|
Top: 40,
|
|
|
|
},
|
|
|
|
},
|
2016-07-30 18:38:43 +02:00
|
|
|
Height: 512,
|
2016-07-30 04:35:18 +02:00
|
|
|
XAxis: chart.Style{
|
|
|
|
Show: true,
|
|
|
|
},
|
|
|
|
YAxis: chart.Style{
|
|
|
|
Show: true,
|
|
|
|
},
|
2016-07-29 03:51:55 +02:00
|
|
|
Bars: []chart.StackedBar{
|
|
|
|
{
|
2016-07-30 18:35:44 +02:00
|
|
|
Name: "This is a very long string to test word break wrapping.",
|
2016-07-29 03:51:55 +02:00
|
|
|
Values: []chart.Value{
|
|
|
|
{Value: 5, Label: "Blue"},
|
|
|
|
{Value: 5, Label: "Green"},
|
|
|
|
{Value: 4, Label: "Gray"},
|
2016-07-30 04:38:37 +02:00
|
|
|
{Value: 3, Label: "Orange"},
|
2016-07-29 03:51:55 +02:00
|
|
|
{Value: 3, Label: "Test"},
|
2016-07-30 04:38:37 +02:00
|
|
|
{Value: 2, Label: "??"},
|
2016-07-29 03:51:55 +02:00
|
|
|
{Value: 1, Label: "!!"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-07-30 04:35:18 +02:00
|
|
|
Name: "Test",
|
2016-07-29 03:51:55 +02:00
|
|
|
Values: []chart.Value{
|
|
|
|
{Value: 10, Label: "Blue"},
|
|
|
|
{Value: 5, Label: "Green"},
|
|
|
|
{Value: 1, Label: "Gray"},
|
|
|
|
},
|
|
|
|
},
|
2016-07-30 08:13:33 +02:00
|
|
|
{
|
|
|
|
Name: "Test 2",
|
|
|
|
Values: []chart.Value{
|
|
|
|
{Value: 10, Label: "Blue"},
|
2016-07-30 08:39:58 +02:00
|
|
|
{Value: 6, Label: "Green"},
|
|
|
|
{Value: 4, Label: "Gray"},
|
2016-07-30 08:13:33 +02:00
|
|
|
},
|
|
|
|
},
|
2016-07-29 03:51:55 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-07-30 18:38:43 +02:00
|
|
|
res.Header().Set("Content-Type", "image/png")
|
|
|
|
err := sbc.Render(chart.PNG, res)
|
2016-07-29 03:51:55 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error rendering chart: %v\n", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/", drawChart)
|
|
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
|
|
}
|