Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

`base` dataset property for `bar` charts is not indexable when it should be

Open Truiteseche opened this issue 1 year ago • 2 comments

Expected behavior

The base dataset property bar charts for should be indexable, which means that each bar should have its own base Reminder: according to the docs, base is:

Base value for the bar in data units along the value axis. If not set, defaults to the value axis base value.

Current behavior

All bars have the same base (the first value of the array if we use an array) And it doesn't work either using the scriptable way since the function is also called once

Reproducible sample

https://codepen.io/Truite-Seche/pen/MWxayZm

Optional extra steps/info to reproduce

Put an array as base on a bar chart

Possible solution

Make base scriptable and indexable, but this is theoretically already the case according to the docs.

Context

No response

chart.js version

v4.4.1

Browser name and version

Microsoft Edge (Chromium) v120.0.2210.91

Link to your project

No response

Truiteseche avatar Dec 31 '23 16:12 Truiteseche

As a workaround for now you can pass your data array as a 2d array to set the base as you want:

data: [
          [2, 12],
          [5, 19],
          [3, 7],
          [10, 5],
          [15, 8],
          [7, 3]
        ]

https://codepen.io/leelenaleee/pen/oNVjqyK

LeeLenaleee avatar Jan 02 '24 08:01 LeeLenaleee

Indeed it works! In fact, it is a better solution to my problem, thanks! I let the issue open because there is still the problem with base

Truiteseche avatar Jan 02 '24 18:01 Truiteseche