2016-07-28 21:51:55 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/wcharczuk/go-chart"
|
|
|
|
)
|
|
|
|
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
|
|
sbc := chart.StackedBarChart{
|
|
|
|
Background: chart.Style{
|
|
|
|
Padding: chart.Box{Top: 50, Left: 50, Right: 50, Bottom: 50},
|
|
|
|
},
|
2016-07-29 22:35:18 -04:00
|
|
|
XAxis: chart.Style{
|
|
|
|
Show: true,
|
|
|
|
},
|
|
|
|
YAxis: chart.Style{
|
|
|
|
Show: true,
|
|
|
|
},
|
2016-07-28 21:51:55 -04:00
|
|
|
Bars: []chart.StackedBar{
|
|
|
|
{
|
2016-07-30 02:31:49 -04:00
|
|
|
Name: "Katrina like animals that are very fat and furry.",
|
2016-07-28 21:51:55 -04:00
|
|
|
Values: []chart.Value{
|
|
|
|
{Value: 5, Label: "Blue"},
|
|
|
|
{Value: 5, Label: "Green"},
|
|
|
|
{Value: 4, Label: "Gray"},
|
2016-07-29 22:38:37 -04:00
|
|
|
{Value: 3, Label: "Orange"},
|
2016-07-28 21:51:55 -04:00
|
|
|
{Value: 3, Label: "Test"},
|
2016-07-29 22:38:37 -04:00
|
|
|
{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"},
|
|
|
|
{Value: 5, Label: "Green"},
|
|
|
|
{Value: 1, Label: "Gray"},
|
|
|
|
},
|
|
|
|
},
|
2016-07-28 21:51:55 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
res.Header().Set("Content-Type", "image/svg+xml")
|
|
|
|
err := sbc.Render(chart.SVG, res)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error rendering chart: %v\n", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/", drawChart)
|
|
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
|
|
}
|