go-chart/_examples/text_rotation/main.go

54 lines
1.0 KiB
Go
Raw Normal View History

2016-09-01 07:11:52 +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/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)
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 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)
}