feat: support axis render

This commit is contained in:
vicanso 2022-06-08 23:19:03 +08:00
parent 4cf494088e
commit b394e1b49f
5 changed files with 344 additions and 39 deletions

View file

@ -27,7 +27,7 @@ func writeFile(buf []byte) error {
func main() {
p, err := charts.NewPainter(charts.PainterOptions{
Width: 600,
Height: 1200,
Height: 2000,
Type: charts.ChartOutputPNG,
})
if err != nil {
@ -429,6 +429,7 @@ func main() {
Right: p.Width() - 1,
Bottom: top + 30,
})), charts.LegendPainterOption{
Left: "10",
Data: []string{
"Email",
"Union Ads",
@ -446,6 +447,7 @@ func main() {
Right: p.Width() - 1,
Bottom: top + 30,
})), charts.LegendPainterOption{
Left: charts.PositionRight,
Data: []string{
"Email",
"Union Ads",
@ -465,6 +467,7 @@ func main() {
Right: p.Width() - 1,
Bottom: top + 100,
})), charts.LegendPainterOption{
Top: "10",
Data: []string{
"Email",
"Union Ads",
@ -476,6 +479,72 @@ func main() {
FontColor: drawing.ColorBlack,
}).Render()
top += 100
charts.NewAxisPainter(p.Child(charts.PainterBoxOption(charts.Box{
Top: top,
Left: 1,
Right: p.Width() - 1,
Bottom: top + 50,
})), charts.AxisPainterOption{
Data: []string{
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun",
},
StrokeColor: drawing.ColorBlack,
FontSize: 12,
FontColor: drawing.ColorBlack,
}).Render()
top += 50
charts.NewAxisPainter(p.Child(charts.PainterBoxOption(charts.Box{
Top: top,
Left: 1,
Right: p.Width() - 1,
Bottom: top + 50,
})), charts.AxisPainterOption{
Position: charts.PositionTop,
BoundaryGap: charts.FalseFlag(),
Data: []string{
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun",
},
StrokeColor: drawing.ColorBlack,
FontSize: 12,
FontColor: drawing.ColorBlack,
}).Render()
top += 50
charts.NewAxisPainter(p.Child(charts.PainterBoxOption(charts.Box{
Top: top,
Left: 10,
Right: p.Width() - 1,
Bottom: top + 200,
})), charts.AxisPainterOption{
Position: charts.PositionLeft,
Data: []string{
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun",
},
StrokeColor: drawing.ColorBlack,
FontSize: 12,
FontColor: drawing.ColorBlack,
}).Render()
buf, err := p.Bytes()
if err != nil {
panic(err)