updates.
This commit is contained in:
parent
e09aa43a1e
commit
cbc4672f1e
13 changed files with 359 additions and 303 deletions
58
testserver/main.go
Normal file
58
testserver/main.go
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
"github.com/wcharczuk/go-web"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := web.New()
|
||||
app.SetName("Chart Test Server")
|
||||
app.SetLogger(web.NewStandardOutputLogger())
|
||||
app.GET("/", func(rc *web.RequestContext) web.ControllerResult {
|
||||
rc.Response.Header().Set("Content-Type", "image/png")
|
||||
now := time.Now()
|
||||
c := chart.Chart{
|
||||
Title: "Hello!",
|
||||
TitleStyle: chart.Style{
|
||||
Show: true,
|
||||
},
|
||||
Width: 1024,
|
||||
Height: 400,
|
||||
Padding: chart.Box{
|
||||
Right: 40,
|
||||
Bottom: 40,
|
||||
},
|
||||
Axes: chart.Style{
|
||||
Show: true,
|
||||
StrokeWidth: 1.0,
|
||||
},
|
||||
YRange: chart.Range{
|
||||
Min: 0.0,
|
||||
Max: 7.0,
|
||||
},
|
||||
Series: []chart.Series{
|
||||
chart.TimeSeries{
|
||||
Name: "goog",
|
||||
Style: chart.Style{
|
||||
StrokeWidth: 1.0,
|
||||
},
|
||||
XValues: []time.Time{now.AddDate(0, 0, -4), now.AddDate(0, 0, -3), now.AddDate(0, 0, -2), now.AddDate(0, 0, -1)},
|
||||
YValues: []float64{2.5, 5.0, 2.0, 3.0},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
buffer := bytes.NewBuffer([]byte{})
|
||||
err := c.Render(chart.PNG, buffer)
|
||||
if err != nil {
|
||||
return rc.API().InternalError(err)
|
||||
}
|
||||
return rc.Raw(buffer.Bytes())
|
||||
})
|
||||
log.Fatal(app.Start())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue