2017-03-04 20:42:10 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/wcharczuk/go-chart"
|
|
|
|
)
|
|
|
|
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
|
|
graph := chart.Chart{
|
|
|
|
Series: []chart.Series{
|
|
|
|
chart.ContinuousSeries{
|
|
|
|
Style: chart.Style{
|
|
|
|
Show: true,
|
|
|
|
StrokeWidth: chart.Disabled,
|
|
|
|
DotWidth: 3,
|
|
|
|
},
|
|
|
|
XValues: chart.Sequence.Random(32, 1024),
|
|
|
|
YValues: chart.Sequence.Random(32, 1024),
|
|
|
|
},
|
2017-03-05 17:24:35 -05:00
|
|
|
chart.ContinuousSeries{
|
|
|
|
Style: chart.Style{
|
|
|
|
Show: true,
|
|
|
|
StrokeWidth: chart.Disabled,
|
|
|
|
DotWidth: 5,
|
|
|
|
},
|
|
|
|
XValues: chart.Sequence.Random(16, 1024),
|
|
|
|
YValues: chart.Sequence.Random(16, 1024),
|
|
|
|
},
|
|
|
|
chart.ContinuousSeries{
|
|
|
|
Style: chart.Style{
|
|
|
|
Show: true,
|
|
|
|
StrokeWidth: chart.Disabled,
|
|
|
|
DotWidth: 7,
|
|
|
|
},
|
|
|
|
XValues: chart.Sequence.Random(8, 1024),
|
|
|
|
YValues: chart.Sequence.Random(8, 1024),
|
|
|
|
},
|
2017-03-04 20:42:10 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
res.Header().Set("Content-Type", "image/png")
|
|
|
|
err := graph.Render(chart.PNG, res)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-03-05 19:52:34 -05:00
|
|
|
func unit(res http.ResponseWriter, req *http.Request) {
|
|
|
|
graph := chart.Chart{
|
|
|
|
Height: 50,
|
|
|
|
Width: 50,
|
|
|
|
Canvas: chart.Style{
|
|
|
|
Padding: chart.Box{IsSet: true},
|
|
|
|
},
|
|
|
|
Background: chart.Style{
|
|
|
|
Padding: chart.Box{IsSet: true},
|
|
|
|
},
|
|
|
|
Series: []chart.Series{
|
|
|
|
chart.ContinuousSeries{
|
|
|
|
XValues: chart.Sequence.Float64(0, 4, 1),
|
|
|
|
YValues: chart.Sequence.Float64(0, 4, 1),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
res.Header().Set("Content-Type", "image/png")
|
|
|
|
err := graph.Render(chart.PNG, res)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 20:42:10 -05:00
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/", drawChart)
|
2017-03-05 19:52:34 -05:00
|
|
|
http.HandleFunc("/unit", unit)
|
2017-03-04 20:42:10 -05:00
|
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
|
|
}
|