2016-08-06 18:53:14 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2019-02-13 19:09:26 -05:00
|
|
|
chart "github.com/wcharczuk/go-chart"
|
2017-05-12 20:12:23 -04:00
|
|
|
"github.com/wcharczuk/go-chart/seq"
|
2016-08-06 18:53:14 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
|
|
mainSeries := chart.ContinuousSeries{
|
|
|
|
Name: "A test series",
|
2017-05-12 20:12:23 -04:00
|
|
|
XValues: seq.Range(1.0, 100.0),
|
2018-09-07 18:25:58 -04:00
|
|
|
YValues: seq.New(seq.NewRandom().WithLen(100).WithMax(150).WithMin(50)).Array(),
|
2016-08-06 18:53:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
minSeries := &chart.MinSeries{
|
|
|
|
Style: chart.Style{
|
|
|
|
Show: true,
|
|
|
|
StrokeColor: chart.ColorAlternateGray,
|
|
|
|
StrokeDashArray: []float64{5.0, 5.0},
|
|
|
|
},
|
|
|
|
InnerSeries: mainSeries,
|
|
|
|
}
|
|
|
|
|
|
|
|
maxSeries := &chart.MaxSeries{
|
|
|
|
Style: chart.Style{
|
|
|
|
Show: true,
|
|
|
|
StrokeColor: chart.ColorAlternateGray,
|
|
|
|
StrokeDashArray: []float64{5.0, 5.0},
|
|
|
|
},
|
|
|
|
InnerSeries: mainSeries,
|
|
|
|
}
|
|
|
|
|
|
|
|
graph := chart.Chart{
|
2016-08-07 00:59:46 -04:00
|
|
|
Width: 1920,
|
|
|
|
Height: 1080,
|
2016-08-06 18:53:14 -04:00
|
|
|
YAxis: chart.YAxis{
|
2016-08-07 00:59:46 -04:00
|
|
|
Name: "Random Values",
|
|
|
|
NameStyle: chart.StyleShow(),
|
|
|
|
Style: chart.StyleShow(),
|
2016-08-06 18:53:14 -04:00
|
|
|
Range: &chart.ContinuousRange{
|
|
|
|
Min: 25,
|
|
|
|
Max: 175,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
XAxis: chart.XAxis{
|
2016-08-07 01:27:26 -04:00
|
|
|
Name: "Random Other Values",
|
|
|
|
NameStyle: chart.StyleShow(),
|
|
|
|
Style: chart.StyleShow(),
|
2016-08-06 18:53:14 -04:00
|
|
|
},
|
|
|
|
Series: []chart.Series{
|
|
|
|
mainSeries,
|
|
|
|
minSeries,
|
|
|
|
maxSeries,
|
|
|
|
chart.LastValueAnnotation(minSeries),
|
|
|
|
chart.LastValueAnnotation(maxSeries),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-08-07 00:59:46 -04:00
|
|
|
graph.Elements = []chart.Renderable{chart.Legend(&graph)}
|
|
|
|
|
2016-08-07 01:27:26 -04:00
|
|
|
res.Header().Set("Content-Type", "image/png")
|
|
|
|
graph.Render(chart.PNG, res)
|
2016-08-06 18:53:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/", drawChart)
|
|
|
|
http.ListenAndServe(":8080", nil)
|
|
|
|
}
|