diff --git a/addons/web/static/src/js/views/graph/graph_renderer.js b/addons/web/static/src/js/views/graph/graph_renderer.js
index 45683b61bad..4d8d3a74d9e 100644
--- a/addons/web/static/src/js/views/graph/graph_renderer.js
+++ b/addons/web/static/src/js/views/graph/graph_renderer.js
@@ -227,7 +227,10 @@ return AbstractRenderer.extend({
* Helper function to set up data properly for the pieChart model in
* nvd3.
*
- * @returns {nvd3 chart}
+ * returns undefined in the case of an non-embedded pie chart with no data.
+ * (all zero data included)
+ *.
+ * @returns {nvd3 chart|undefined}
*/
_renderPieChart: function (stateData) {
var self = this;
@@ -471,14 +474,16 @@ return AbstractRenderer.extend({
}
var chart = this['_render' + _.str.capitalize(this.state.mode) + 'Chart'](this.state.data);
- // FIXME: When 'orient' is right for Y axis, horizontal lines aren't displayed correctly
- chart.dispatch.on('renderEnd', function () {
- $('.nv-y .tick > line').attr('x2', function (i, value) {
- return Math.abs(value);
- });
- })
+ if (chart) {
+ // FIXME: When 'orient' is right for Y axis, horizontal lines aren't displayed correctly
+ chart.dispatch.on('renderEnd', function () {
+ $('.nv-y .tick > line').attr('x2', function (i, value) {
+ return Math.abs(value);
+ });
+ })
- chartResize(chart);
+ chartResize(chart);
+ }
if (this.state.mode === 'pie' && this.isComparison) {
// Render graph title
@@ -496,8 +501,9 @@ return AbstractRenderer.extend({
text: comparisonChartTitle,
}));
chartResize(comparisonChart);
-
- chart.update();
+ if (chart) {
+ chart.update();
+ }
} else if (this.title) {
this.$('.o_graph_svg_container').last().prepend($('', {
text: this.title,
diff --git a/addons/web/static/tests/views/graph_tests.js b/addons/web/static/tests/views/graph_tests.js
index 5c9e5b67d6f..595ed3f31dd 100644
--- a/addons/web/static/tests/views/graph_tests.js
+++ b/addons/web/static/tests/views/graph_tests.js
@@ -225,7 +225,7 @@ QUnit.module('Views', {
});
});
- QUnit.test('no content helper', function (assert) {
+ QUnit.test('no content helper (bar chart)', function (assert) {
assert.expect(2);
this.data.foo.records = [];
@@ -244,6 +244,25 @@ QUnit.module('Views', {
graph.destroy();
});
+ QUnit.test('no content helper (pie chart)', function (assert) {
+ assert.expect(2);
+ this.data.foo.records = []
+
+ var graph = createView({
+ View: GraphView,
+ model: "foo",
+ data: this.data,
+ arch: '' +
+ '' +
+ '',
+ });
+ assert.strictEqual(graph.$('div.o_graph_svg_container svg.nvd3-svg').length, 0,
+ "should not contain a div with a svg element");
+ assert.strictEqual(graph.$('div.o_view_nocontent').length, 1,
+ "should display the no content helper");
+ graph.destroy();
+ });
+
QUnit.test('no content helper after update', function (assert) {
var done = assert.async();
assert.expect(4);