From: Evert Timberg Date: Sun, 28 Feb 2016 22:51:06 +0000 (-0500) Subject: Fix legend generation when no datasets X-Git-Tag: v2.0.0~26^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2074%2Fhead;p=thirdparty%2FChart.js.git Fix legend generation when no datasets --- 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) {