go-chart/_examples/basic/main.go
Chris Redford b3dc3fef3c Separation of DotColorProvider and ColorProvider Interfaces (#34)
* fully functioning Viridis

* pure functions
2017-04-17 16:21:02 -07:00

44 lines
914 B
Go

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{
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
},
},
}
res.Header().Set("Content-Type", "image/png")
graph.Render(chart.PNG, res)
}
func drawChartWide(res http.ResponseWriter, req *http.Request) {
graph := chart.Chart{
Width: 1920, //this overrides the default.
Series: []chart.Series{
chart.ContinuousSeries{
XValues: []float64{1.0, 2.0, 3.0, 4.0},
YValues: []float64{1.0, 2.0, 3.0, 4.0},
},
},
}
res.Header().Set("Content-Type", "image/png")
graph.Render(chart.PNG, res)
}
func main() {
http.HandleFunc("/", drawChart)
http.HandleFunc("/wide", drawChartWide)
log.Fatal(http.ListenAndServe(":8080", nil))
}