Skip to content

bar chart with skipNull crashes if there are datasets of different lengths #10411

Description

@TheRealSyler

Expected behavior

You should be able to have the skipNull option enabled and use the datasets in the example below.

const datasets = [
    { data: [1, 2] },
    { data: [1, 2, 3] },
]

Current behavior

It Crashes here, because item.controller.getParsed(dataIndex) returns undefined, you cannot use item.controller._cachedMeta.vScale.axis to access undefined.

Reproducible sample

https://codepen.io/therealsyler/pen/poaxgBJ

Optional extra steps/info to reproduce

var ctx = document.getElementById("myChart");

var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
    labels: [ 1,2 ],
    datasets: [
      { data: [1, 2] },
      { data: [1, 2] }, // ,3
    ]
    },
    options: {
       responsive: true,
       skipNull: true,
    }
});

Possible solution

Change this

From:

const val = item.controller.getParsed(dataIndex)[item.controller._cachedMeta.vScale.axis];

To:

const parsed = item.controller.getParsed(dataIndex)
const val = parsed && parsed[item.controller._cachedMeta.vScale.axis];

Context

No response

chart.js version

3.8.0

Browser name and version

No response

Link to your project

No response

Activity

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