From 3d6b47b0d5de5e341ec69f978864609f11d7ef63 Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Sun, 28 Feb 2016 17:51:06 -0500 Subject: [PATCH] Fix legend generation when no datasets --- src/controllers/controller.doughnut.js | 24 ++++++++++++++---------- src/controllers/controller.polarArea.js | 24 ++++++++++++++---------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index 92816a028..c3c70f968 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -35,16 +35,20 @@ module.exports = function(Chart) { legend: { labels: { generateLabels: function(data) { - return data.labels.map(function(label, i) { - return { - text: label, - fillStyle: data.datasets[0].backgroundColor[i], - hidden: isNaN(data.datasets[0].data[i]), - - // Extra data used for toggling the correct item - index: i - }; - }); + if (data.labels.length && data.datasets.length) { + return data.labels.map(function(label, i) { + return { + text: label, + fillStyle: data.datasets[0].backgroundColor[i], + hidden: isNaN(data.datasets[0].data[i]), + + // Extra data used for toggling the correct item + index: i + }; + }); + } else { + return []; + } } }, onClick: function(e, legendItem) { diff --git a/src/controllers/controller.polarArea.js b/src/controllers/controller.polarArea.js index 162d1620c..1506f9da7 100644 --- a/src/controllers/controller.polarArea.js +++ b/src/controllers/controller.polarArea.js @@ -36,16 +36,20 @@ module.exports = function(Chart) { legend: { labels: { generateLabels: function(data) { - return data.labels.map(function(label, i) { - return { - text: label, - fillStyle: data.datasets[0].backgroundColor[i], - hidden: isNaN(data.datasets[0].data[i]), - - // Extra data used for toggling the correct item - index: i - }; - }); + if (data.labels.length && data.datasets.length) { + return data.labels.map(function(label, i) { + return { + text: label, + fillStyle: data.datasets[0].backgroundColor[i], + hidden: isNaN(data.datasets[0].data[i]), + + // Extra data used for toggling the correct item + index: i + }; + }); + } else { + return []; + } } }, onClick: function(e, legendItem) { -- 2.47.2