diff --git a/pie_chart.go b/pie_chart.go
index 4833c34..099a91c 100644
--- a/pie_chart.go
+++ b/pie_chart.go
@@ -23,6 +23,7 @@
package charts
import (
+ "errors"
"math"
"github.com/golang/freetype/truetype"
@@ -68,6 +69,9 @@ func pieChartRender(opt pieChartOption, result *basicRenderResult) error {
values[index] = value
total += value
}
+ if total <= 0 {
+ return errors.New("The sum value of pie chart should gt 0")
+ }
r := d.Render
theme := NewTheme(opt.Theme)
diff --git a/pie_chart_test.go b/pie_chart_test.go
index 7cb9fde..84072be 100644
--- a/pie_chart_test.go
+++ b/pie_chart_test.go
@@ -46,10 +46,12 @@ func TestPieChartRender(t *testing.T) {
SeriesList: NewPieSeriesList([]float64{
5,
10,
+ 0,
}, PieSeriesOption{
Names: []string{
"a",
"b",
+ "c",
},
Label: SeriesLabel{
Show: true,
@@ -63,5 +65,5 @@ func TestPieChartRender(t *testing.T) {
assert.Nil(err)
data, err := d.Bytes()
assert.Nil(err)
- assert.Equal("", string(data))
+ assert.Equal("", string(data))
}