2016-07-17 05:53:46 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-02-23 02:15:13 +01:00
|
|
|
"log"
|
2016-07-17 05:53:46 +02:00
|
|
|
"net/http"
|
|
|
|
|
2018-12-06 16:46:27 +01:00
|
|
|
"git.gutmet.org/go-chart.git"
|
2016-07-17 05:53:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
|
|
graph := chart.Chart{
|
|
|
|
Series: []chart.Series{
|
|
|
|
chart.ContinuousSeries{
|
|
|
|
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
|
|
|
|
YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
res.Header().Set("Content-Type", "image/png")
|
|
|
|
graph.Render(chart.PNG, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func drawChartWide(res http.ResponseWriter, req *http.Request) {
|
|
|
|
graph := chart.Chart{
|
|
|
|
Width: 1920, //this overrides the default.
|
|
|
|
Series: []chart.Series{
|
|
|
|
chart.ContinuousSeries{
|
2017-04-18 01:21:02 +02:00
|
|
|
XValues: []float64{1.0, 2.0, 3.0, 4.0},
|
|
|
|
YValues: []float64{1.0, 2.0, 3.0, 4.0},
|
2016-07-17 05:53:46 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
res.Header().Set("Content-Type", "image/png")
|
|
|
|
graph.Render(chart.PNG, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/", drawChart)
|
|
|
|
http.HandleFunc("/wide", drawChartWide)
|
2017-02-23 02:15:13 +01:00
|
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
2016-07-17 05:53:46 +02:00
|
|
|
}
|