2017-04-19 05:20:29 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-12-06 16:46:27 +01:00
|
|
|
"git.gutmet.org/go-chart.git"
|
|
|
|
"git.gutmet.org/go-chart.git/seq"
|
2017-04-19 05:20:29 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
In this example we add a new type of series, a `PolynomialRegressionSeries` that takes another series as a required argument.
|
2017-05-13 02:12:23 +02:00
|
|
|
InnerSeries only needs to implement `ValuesProvider`, so really you could chain `PolynomialRegressionSeries` together if you wanted.
|
2017-04-19 05:20:29 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
mainSeries := chart.ContinuousSeries{
|
|
|
|
Name: "A test series",
|
2018-09-05 17:45:45 +02:00
|
|
|
XValues: seq.Range(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
|
|
|
YValues: seq.RandomValuesWithMax(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
|
2017-04-19 05:20:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
polyRegSeries := &chart.PolynomialRegressionSeries{
|
|
|
|
Degree: 3,
|
|
|
|
InnerSeries: mainSeries,
|
|
|
|
}
|
|
|
|
|
|
|
|
graph := chart.Chart{
|
|
|
|
Series: []chart.Series{
|
|
|
|
mainSeries,
|
|
|
|
polyRegSeries,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
res.Header().Set("Content-Type", "image/png")
|
|
|
|
graph.Render(chart.PNG, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/", drawChart)
|
|
|
|
http.ListenAndServe(":8080", nil)
|
|
|
|
}
|