2016-07-28 11:34:44 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/wcharczuk/go-chart"
|
|
|
|
)
|
|
|
|
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
|
|
pie := chart.PieChart{
|
2016-07-29 04:17:35 +02:00
|
|
|
Width: 512,
|
|
|
|
Height: 512,
|
2016-07-28 23:30:00 +02:00
|
|
|
Values: []chart.Value{
|
2016-07-29 03:51:55 +02:00
|
|
|
{Value: 5, Label: "Blue"},
|
|
|
|
{Value: 5, Label: "Green"},
|
|
|
|
{Value: 4, Label: "Gray"},
|
|
|
|
{Value: 4, Label: "Orange"},
|
2016-08-06 09:28:12 +02:00
|
|
|
{Value: 3, Label: "Deep Blue"},
|
2016-07-29 03:51:55 +02:00
|
|
|
{Value: 3, Label: "??"},
|
|
|
|
{Value: 1, Label: "!!"},
|
2016-07-28 11:34:44 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-07-29 04:00:48 +02:00
|
|
|
res.Header().Set("Content-Type", "image/png")
|
|
|
|
err := pie.Render(chart.PNG, res)
|
2016-07-28 11:34:44 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error rendering pie chart: %v\n", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/", drawChart)
|
|
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
|
|
}
|