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