package main import ( "fmt" "log" "net/http" "os" "github.com/wcharczuk/go-chart" ) func drawChart(res http.ResponseWriter, req *http.Request) { sbc := chart.BarChart{ Height: 512, BarWidth: 60, XAxis: chart.Style{ Show: true, }, YAxis: chart.YAxis{ Style: chart.Style{ Show: true, }, }, Bars: []chart.Value{ {Value: 5, Label: "Blue"}, {Value: 5, Label: "Green"}, {Value: 4, Label: "Gray"}, {Value: 3, Label: "Orange"}, {Value: 3, Label: "Test"}, {Value: 2, Label: "??"}, {Value: 1, Label: "!!"}, }, } res.Header().Set("Content-Type", "image/png") err := sbc.Render(chart.PNG, res) if err != nil { fmt.Printf("Error rendering chart: %v\n", err) } } func port() string { if len(os.Getenv("PORT")) > 0 { return os.Getenv("PORT") } return "8080" } func main() { listenPort := fmt.Sprintf(":%s", port()) fmt.Printf("Listening on %s\n", listenPort) http.HandleFunc("/", drawChart) log.Fatal(http.ListenAndServe(listenPort, nil)) }