mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Update doughnut and polar area legend callbacks to handle when the background color is not set.
This commit is contained in:
parent
d5af01b2c7
commit
0e33b6b556
@ -36,16 +36,25 @@ module.exports = function(Chart) {
|
||||
labels: {
|
||||
generateLabels: function(data) {
|
||||
if (data.labels.length && data.datasets.length) {
|
||||
|
||||
return data.labels.map(function(label, i) {
|
||||
var ds = data.datasets[0];
|
||||
var arc = ds.metaData[i];
|
||||
var fill = arc.custom && arc.custom.backgroundColor ? arc.custom.backgroundColor : helpers.getValueAtIndexOrDefault(ds.backgroundColor, i, this.chart.options.elements.arc.backgroundColor);
|
||||
var stroke = arc.custom && arc.custom.borderColor ? arc.custom.borderColor : helpers.getValueAtIndexOrDefault(ds.borderColor, i, this.chart.options.elements.arc.borderColor);
|
||||
var bw = arc.custom && arc.custom.borderWidth ? arc.custom.borderWidth : helpers.getValueAtIndexOrDefault(ds.borderWidth, i, this.chart.options.elements.arc.borderWidth);
|
||||
|
||||
return {
|
||||
text: label,
|
||||
fillStyle: data.datasets[0].backgroundColor[i],
|
||||
fillStyle: fill,
|
||||
strokeStyle: stroke,
|
||||
lineWidth: bw,
|
||||
hidden: isNaN(data.datasets[0].data[i]),
|
||||
|
||||
// Extra data used for toggling the correct item
|
||||
index: i
|
||||
};
|
||||
});
|
||||
}, this);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -38,15 +38,23 @@ module.exports = function(Chart) {
|
||||
generateLabels: function(data) {
|
||||
if (data.labels.length && data.datasets.length) {
|
||||
return data.labels.map(function(label, i) {
|
||||
var ds = data.datasets[0];
|
||||
var arc = ds.metaData[i];
|
||||
var fill = arc.custom && arc.custom.backgroundColor ? arc.custom.backgroundColor : helpers.getValueAtIndexOrDefault(ds.backgroundColor, i, this.chart.options.elements.arc.backgroundColor);
|
||||
var stroke = arc.custom && arc.custom.borderColor ? arc.custom.borderColor : helpers.getValueAtIndexOrDefault(ds.borderColor, i, this.chart.options.elements.arc.borderColor);
|
||||
var bw = arc.custom && arc.custom.borderWidth ? arc.custom.borderWidth : helpers.getValueAtIndexOrDefault(ds.borderWidth, i, this.chart.options.elements.arc.borderWidth);
|
||||
|
||||
return {
|
||||
text: label,
|
||||
fillStyle: data.datasets[0].backgroundColor[i],
|
||||
fillStyle: fill,
|
||||
strokeStyle: stroke,
|
||||
lineWidth: bw,
|
||||
hidden: isNaN(data.datasets[0].data[i]),
|
||||
|
||||
// Extra data used for toggling the correct item
|
||||
index: i
|
||||
};
|
||||
});
|
||||
}, this);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user