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{
|
|
|
|
Canvas: chart.Style{
|
|
|
|
FillColor: chart.ColorLightGray,
|
|
|
|
},
|
|
|
|
Values: []chart.PieChartValue{
|
2016-07-28 22:22:18 +02:00
|
|
|
{Value: 0.2, Label: "Blue"},
|
2016-07-28 11:34:44 +02:00
|
|
|
{Value: 0.2, Label: "Green"},
|
|
|
|
{Value: 0.2, Label: "Gray"},
|
|
|
|
{Value: 0.1, Label: "Orange"},
|
2016-07-28 22:22:18 +02:00
|
|
|
{Value: 0.1, Label: "HEANG"},
|
2016-07-28 11:34:44 +02:00
|
|
|
{Value: 0.1, Label: "??"},
|
2016-07-28 11:43:28 +02:00
|
|
|
{Value: 0.1, Label: "!!"},
|
2016-07-28 11:34:44 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-07-28 22:22:18 +02:00
|
|
|
res.Header().Set("Content-Type", "image/svg+xml")
|
|
|
|
err := pie.Render(chart.SVG, 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))
|
|
|
|
}
|