2016-09-01 01:11:52 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2019-02-13 21:55:13 -05:00
|
|
|
chart "github.com/wcharczuk/go-chart"
|
2016-10-21 15:44:37 -04:00
|
|
|
"github.com/wcharczuk/go-chart/drawing"
|
2016-09-01 01:11:52 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
2016-10-21 15:44:37 -04:00
|
|
|
f, _ := chart.GetDefaultFont()
|
|
|
|
r, _ := chart.PNG(1024, 1024)
|
2016-09-01 01:11:52 -04:00
|
|
|
|
2016-10-21 15:44:37 -04:00
|
|
|
chart.Draw.Text(r, "Test", 64, 64, chart.Style{
|
|
|
|
FontColor: drawing.ColorBlack,
|
|
|
|
FontSize: 18,
|
|
|
|
Font: f,
|
|
|
|
})
|
|
|
|
|
|
|
|
chart.Draw.Text(r, "Test", 64, 64, chart.Style{
|
|
|
|
FontColor: drawing.ColorBlack,
|
|
|
|
FontSize: 18,
|
|
|
|
Font: f,
|
|
|
|
TextRotationDegrees: 45.0,
|
|
|
|
})
|
|
|
|
|
|
|
|
tb := chart.Draw.MeasureText(r, "Test", chart.Style{
|
|
|
|
FontColor: drawing.ColorBlack,
|
|
|
|
FontSize: 18,
|
|
|
|
Font: f,
|
|
|
|
}).Shift(64, 64)
|
|
|
|
|
|
|
|
tbc := tb.Corners().Rotate(45)
|
|
|
|
|
|
|
|
chart.Draw.BoxCorners(r, tbc, chart.Style{
|
|
|
|
StrokeColor: drawing.ColorRed,
|
|
|
|
StrokeWidth: 2,
|
|
|
|
})
|
|
|
|
|
|
|
|
tbcb := tbc.Box()
|
|
|
|
chart.Draw.Box(r, tbcb, chart.Style{
|
|
|
|
StrokeColor: drawing.ColorBlue,
|
|
|
|
StrokeWidth: 2,
|
|
|
|
})
|
2016-09-01 01:11:52 -04:00
|
|
|
|
|
|
|
res.Header().Set("Content-Type", "image/png")
|
2016-10-21 15:44:37 -04:00
|
|
|
r.Save(res)
|
2016-09-01 01:11:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/", drawChart)
|
|
|
|
http.ListenAndServe(":8080", nil)
|
|
|
|
}
|