From c14a5a68c02ff4bc3d86f476fed961d6651bea61 Mon Sep 17 00:00:00 2001 From: ffhelicopter Date: Fri, 7 Jun 2019 13:46:23 +0800 Subject: [PATCH 1/2] modify barchart:show the value of each bar on top of it --- plotter/barchart.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plotter/barchart.go b/plotter/barchart.go index c5ce931a..9c788759 100644 --- a/plotter/barchart.go +++ b/plotter/barchart.go @@ -6,6 +6,7 @@ package plotter import ( "errors" + "fmt" "image/color" "math" @@ -120,6 +121,10 @@ func (b *BarChart) Plot(c draw.Canvas, plt *plot.Plot) { valMin := trVal(bottom) valMax := trVal(bottom + ht) + // value point + topx := catMin + topy := valMax + var pts []vg.Point var poly []vg.Point if !b.Horizontal { @@ -138,6 +143,9 @@ func (b *BarChart) Plot(c draw.Canvas, plt *plot.Plot) { {valMax, catMin}, } poly = c.ClipPolygonX(pts) + + topx = valMax + topy = catMin } c.FillPolygon(b.Color, poly) @@ -150,6 +158,11 @@ func (b *BarChart) Plot(c draw.Canvas, plt *plot.Plot) { outline = c.ClipLinesX(pts) } c.StrokeLines(b.LineStyle, outline...) + // 增加在bar上显示具体数据 + strvalue := fmt.Sprintln(ht) + ft, _ := vg.MakeFont(plot.DefaultFont, 10) + c.FillText(draw.TextStyle{Color: color.Black, Font: ft}, vg.Point{X: topx, Y: topy}, strvalue) + } } From 6573d32811674ffc6f9f2034f893d8c8f39ec981 Mon Sep 17 00:00:00 2001 From: ffhelicopter Date: Fri, 7 Jun 2019 13:52:22 +0800 Subject: [PATCH 2/2] modify barchart:show the value of each bar on top of it --- plotter/barchart.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plotter/barchart.go b/plotter/barchart.go index 9c788759..3c409591 100644 --- a/plotter/barchart.go +++ b/plotter/barchart.go @@ -158,7 +158,7 @@ func (b *BarChart) Plot(c draw.Canvas, plt *plot.Plot) { outline = c.ClipLinesX(pts) } c.StrokeLines(b.LineStyle, outline...) - // 增加在bar上显示具体数据 + // show the value of each bar on top of it strvalue := fmt.Sprintln(ht) ft, _ := vg.MakeFont(plot.DefaultFont, 10) c.FillText(draw.TextStyle{Color: color.Black, Font: ft}, vg.Point{X: topx, Y: topy}, strvalue)