chartjs / Chart.js

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

Default 'borderColor' does not take effect in line charts #11644

Closed FarawayFowl closed 8 months ago

FarawayFowl commented 8 months ago

Expected behavior

Chart.defaults.borderColor and Chart.defaults.elements.line.borderColor should manipulate the default color of a dataset in a line chart.

Current behavior

The default color of a dataset in a line chart stays blue, regardless what was previously defined.

Reproducible sample

https://codepen.io/FarawayFowl/pen/JjzNeRz

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

4.4.1

Browser name and version

Microsoft Edge for Business | Version 120.0.2210.133 (Offizielles Build) (64-Bit)

Link to your project

No response

itsarijitray commented 8 months ago

Can I pick this?

LeeLenaleee commented 8 months ago

When you want to set default colors you will need to dissable the colors plugin. This is beacause if we are going to check if the defaults have a value too the plugin will always be deactivated since the defaults are already filled by chart.js itself with basic values.

You can dissable the plugin with the defaults using this line: Chart.defaults.plugins.colors = false;

Or you can disable it on a per chart bases using this config:

  options: {
    plugins: {
      colors: false
    }
  }
FarawayFowl commented 8 months ago

Thank you for this! As far as I can see, this behaviour is not documented yet. Perhaps it could be documented here:

https://www.chartjs.org/docs/latest/general/colors.html#default-color-palette