2016-07-17 14:24:54 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/wcharczuk/go-chart"
|
|
|
|
"github.com/wcharczuk/go-chart/drawing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
|
|
graph := chart.Chart{
|
|
|
|
Background: chart.Style{
|
|
|
|
Padding: chart.Box{
|
2016-07-17 15:52:26 -04:00
|
|
|
Top: 50,
|
2016-07-17 14:24:54 -04:00
|
|
|
Left: 25,
|
|
|
|
Right: 25,
|
|
|
|
Bottom: 10,
|
|
|
|
},
|
|
|
|
FillColor: drawing.ColorFromHex("efefef"),
|
|
|
|
},
|
|
|
|
XAxis: chart.XAxis{
|
|
|
|
Style: chart.Style{
|
|
|
|
Show: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
YAxis: chart.YAxis{
|
|
|
|
Style: chart.Style{
|
|
|
|
Show: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Series: []chart.Series{
|
|
|
|
chart.ContinuousSeries{
|
|
|
|
XValues: chart.Seq(1.0, 100.0),
|
|
|
|
YValues: chart.SeqRand(100.0, 256.0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
res.Header().Set("Content-Type", "image/png")
|
|
|
|
graph.Render(chart.PNG, res)
|
|
|
|
}
|
|
|
|
|
2016-07-17 15:52:26 -04:00
|
|
|
func drawChartDefault(res http.ResponseWriter, req *http.Request) {
|
|
|
|
graph := chart.Chart{
|
|
|
|
Background: chart.Style{
|
|
|
|
FillColor: drawing.ColorFromHex("efefef"),
|
|
|
|
},
|
|
|
|
XAxis: chart.XAxis{
|
|
|
|
Style: chart.Style{
|
|
|
|
Show: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
YAxis: chart.YAxis{
|
|
|
|
Style: chart.Style{
|
|
|
|
Show: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Series: []chart.Series{
|
|
|
|
chart.ContinuousSeries{
|
|
|
|
XValues: chart.Seq(1.0, 100.0),
|
|
|
|
YValues: chart.SeqRand(100.0, 256.0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
res.Header().Set("Content-Type", "image/png")
|
|
|
|
graph.Render(chart.PNG, res)
|
|
|
|
}
|
|
|
|
|
2016-07-17 14:24:54 -04:00
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/", drawChart)
|
2016-07-17 15:52:26 -04:00
|
|
|
http.HandleFunc("/default", drawChartDefault)
|
2016-07-17 14:24:54 -04:00
|
|
|
http.ListenAndServe(":8080", nil)
|
|
|
|
}
|