chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
63.94k stars 11.89k forks source link

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

Open Truiteseche opened 6 months ago

Truiteseche commented 6 months ago

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

LeeLenaleee commented 6 months ago

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

Truiteseche commented 6 months ago

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