Skip to content

Doughnut/Pie generateLabels assumes backgroundColor is always set on dataset #2143

Closed

Description

@tannerlinsley

In the doughnut chart defaults, the generateLabels function assumes that data.datasets[0].backgroundColor is always set, resulting in the classic Cannot read property '0' of undefined error

labels: {
    generateLabels: function(data) {
        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 [];
        }
    }
},

Activity

  1. etimberg commented on Mar 16, 2016

    @etimberg
    Member

    We could look at the objects and see what backgroundColor is set and use that.

    The legend isn't great here since it assumes the color is the same for all datasets 😞

  2. added this to the milestone on Mar 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions