small bugfix for edge case.
This commit is contained in:
parent
3432bd9443
commit
d455b775da
3 changed files with 45 additions and 0 deletions
|
|
@ -42,7 +42,46 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
graph.Render(chart.PNG, res)
|
||||
}
|
||||
|
||||
func drawCustomChart(res http.ResponseWriter, req *http.Request) {
|
||||
/*
|
||||
This is basically the other timeseries example, except we switch to hour intervals and specify a different formatter from default for the xaxis tick labels.
|
||||
*/
|
||||
graph := chart.Chart{
|
||||
XAxis: chart.XAxis{
|
||||
Style: chart.Style{
|
||||
Show: true,
|
||||
},
|
||||
ValueFormatter: chart.TimeHourValueFormatter,
|
||||
},
|
||||
Series: []chart.Series{
|
||||
chart.TimeSeries{
|
||||
XValues: []time.Time{
|
||||
time.Now().Add(-10 * time.Hour),
|
||||
time.Now().Add(-9 * time.Hour),
|
||||
time.Now().Add(-8 * time.Hour),
|
||||
time.Now().Add(-7 * time.Hour),
|
||||
time.Now().Add(-6 * time.Hour),
|
||||
time.Now().Add(-5 * time.Hour),
|
||||
time.Now().Add(-4 * time.Hour),
|
||||
time.Now().Add(-3 * time.Hour),
|
||||
time.Now().Add(-2 * time.Hour),
|
||||
time.Now().Add(-1 * time.Hour),
|
||||
time.Now(),
|
||||
},
|
||||
YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
res.Header().Set("Content-Type", "image/png")
|
||||
graph.Render(chart.PNG, res)
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", drawChart)
|
||||
http.HandleFunc("/favico.ico", func(res http.ResponseWriter, req *http.Request) {
|
||||
res.Write([]byte{})
|
||||
})
|
||||
http.HandleFunc("/custom", drawCustomChart)
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue