mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Merge pull request #2074 from nnnick/fix/2070
Fix legend generation when no datasets
This commit is contained in:
commit
a25c2c740c
@ -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]),
|
||||
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
|
||||
};
|
||||
});
|
||||
// Extra data used for toggling the correct item
|
||||
index: i
|
||||
};
|
||||
});
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
},
|
||||
onClick: function(e, legendItem) {
|
||||
|
||||
@ -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]),
|
||||
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
|
||||
};
|
||||
});
|
||||
// Extra data used for toggling the correct item
|
||||
index: i
|
||||
};
|
||||
});
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
},
|
||||
onClick: function(e, legendItem) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user