2016-09-01 07:11:52 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/wcharczuk/go-chart"
|
2016-10-21 21:44:37 +02:00
|
|
|
"github.com/wcharczuk/go-chart/drawing"
|
2016-09-01 07:11:52 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
2016-10-21 21:44:37 +02:00
|
|
|
f, _ := chart.GetDefaultFont()
|
|
|
|
r, _ := chart.PNG(1024, 1024)
|
2016-09-01 07:11:52 +02:00
|
|
|
|
2016-10-21 21:44:37 +02: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)
|
|
|
|
|
2017-05-16 22:31:36 +02:00
|
|
|
chart.Draw.Box2d(r, tbc, chart.Style{
|
2016-10-21 21:44:37 +02:00
|
|
|
StrokeColor: drawing.ColorRed,
|
|
|
|
StrokeWidth: 2,
|
|
|
|
})
|
|
|
|
|
2017-05-16 22:31:36 +02:00
|
|
|
tbc2 := tbc.Shift(tbc.Height(), 0)
|
|
|
|
chart.Draw.Box2d(r, tbc2, chart.Style{
|
|
|
|
StrokeColor: drawing.ColorGreen,
|
|
|
|
StrokeWidth: 2,
|
|
|
|
})
|
|
|
|
|
2016-10-21 21:44:37 +02:00
|
|
|
tbcb := tbc.Box()
|
|
|
|
chart.Draw.Box(r, tbcb, chart.Style{
|
|
|
|
StrokeColor: drawing.ColorBlue,
|
|
|
|
StrokeWidth: 2,
|
|
|
|
})
|
2016-09-01 07:11:52 +02:00
|
|
|
|
|
|
|
res.Header().Set("Content-Type", "image/png")
|
2016-10-21 21:44:37 +02:00
|
|
|
r.Save(res)
|
2016-09-01 07:11:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
http.HandleFunc("/", drawChart)
|
|
|
|
http.ListenAndServe(":8080", nil)
|
|
|
|
}
|