go-chart/_examples/text_rotation/main.go

54 lines
1.0 KiB
Go
Raw Permalink Normal View History

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)
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)
}