go-chart/examples/pie_chart/main.go
Will Charczuk a008ebe30e tweaks.
2016-07-29 18:40:43 -07:00

41 lines
768 B
Go

package main
import (
"fmt"
"log"
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
pie := chart.PieChart{
Title: "test\nchart",
TitleStyle: chart.Style{
Show: true,
},
Width: 512,
Height: 512,
Values: []chart.Value{
{Value: 5, Label: "Blue"},
{Value: 5, Label: "Green"},
{Value: 4, Label: "Gray"},
{Value: 4, Label: "Orange"},
{Value: 3, Label: "Test"},
{Value: 3, Label: "??"},
{Value: 1, Label: "!!"},
},
}
res.Header().Set("Content-Type", "image/png")
err := pie.Render(chart.PNG, res)
if err != nil {
fmt.Printf("Error rendering pie chart: %v\n", err)
}
}
func main() {
http.HandleFunc("/", drawChart)
log.Fatal(http.ListenAndServe(":8080", nil))
}