diff --git a/bar_chart.go b/bar_chart.go index 931e808..7a690ac 100644 --- a/bar_chart.go +++ b/bar_chart.go @@ -1,6 +1,7 @@ package charts import ( + "errors" "math" "github.com/golang/freetype/truetype" @@ -64,6 +65,9 @@ func (b *barChart) render(result *defaultRenderResult, seriesList SeriesList) (B barMargin = 3 } seriesCount := len(seriesList) + if seriesCount == 0 { + return BoxZero, errors.New("empty series list") + } barWidth := (width - 2*margin - barMargin*(seriesCount-1)) / seriesCount if opt.BarWidth > 0 && opt.BarWidth < barWidth { barWidth = opt.BarWidth diff --git a/funnel_chart.go b/funnel_chart.go index 79dec22..a4505db 100644 --- a/funnel_chart.go +++ b/funnel_chart.go @@ -1,6 +1,8 @@ package charts import ( + "errors" + "github.com/golang/freetype/truetype" "github.com/go-analyze/charts/chartdraw" @@ -63,6 +65,9 @@ func (f *funnelChart) render(result *defaultRenderResult, seriesList SeriesList) height := seriesPainter.Height() width := seriesPainter.Width() count := len(seriesList) + if count == 0 { + return BoxZero, errors.New("empty series list") + } h := (height - gap*(count-1)) / count diff --git a/horizontal_bar_chart.go b/horizontal_bar_chart.go index e2dc0a4..fc3e186 100644 --- a/horizontal_bar_chart.go +++ b/horizontal_bar_chart.go @@ -1,6 +1,8 @@ package charts import ( + "errors" + "github.com/golang/freetype/truetype" "github.com/go-analyze/charts/chartdraw" @@ -59,6 +61,9 @@ func (h *horizontalBarChart) render(result *defaultRenderResult, seriesList Seri barMargin = 3 } seriesCount := len(seriesList) + if seriesCount == 0 { + return BoxZero, errors.New("empty series list") + } barHeight := (height - 2*margin - barMargin*(seriesCount-1)) / seriesCount if opt.BarHeight > 0 && opt.BarHeight < barHeight { barHeight = opt.BarHeight