Chart.js: scaleLabel nor defaultFontColor are applied (v2.9.4)

Created on 23 Nov 2020  ·  4Comments  ·  Source: chartjs/Chart.js

Expected Behavior

I expect defaultFontColor and scaleLabel.fontColor or at least scaleLabel.fontColor override this ridiculous '#666' default color

Current Behavior

Default set in:

    defaults._set('global', {
        defaultColor: 'rgba(0,0,0,0.1)',
        defaultFontColor: '#666',
        defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
        defaultFontSize: 12,
        defaultFontStyle: 'normal',
        defaultLineHeight: 1.2,
        showLines: true
    });

is not overriden

Possible Solution

I've noticed that in _drawLabels method tickFont.color is not properly set

Steps to Reproduce

https://codepen.io/sajTempler/pen/abZeBQa

try editing options object for a chart and change scaleLabel.fontColor or defaultFontColor

Context

I am styling the chart with some stats

Environment

  • Chart.js version: 2.9.4
  • Browser name and version: Brave 86 / Chrome 86
  • Link to your project: private look at attached Codepen
bug

Most helpful comment

From the docs about the styling of the ticks you can see that the option to adjust the color of the scalelabel should be in the ticks config.

Ticks label color documentation: https://www.chartjs.org/docs/latest/axes/styling.html#tick-configuration
Default color documentation: https://www.chartjs.org/docs/latest/general/fonts.html

Default color change: https://codepen.io/leelenaleee/pen/GRqVrBm
Color in ticks label: https://codepen.io/leelenaleee/pen/xxOvgVe

All 4 comments

From the docs about the styling of the ticks you can see that the option to adjust the color of the scalelabel should be in the ticks config.

Ticks label color documentation: https://www.chartjs.org/docs/latest/axes/styling.html#tick-configuration
Default color documentation: https://www.chartjs.org/docs/latest/general/fonts.html

Default color change: https://codepen.io/leelenaleee/pen/GRqVrBm
Color in ticks label: https://codepen.io/leelenaleee/pen/xxOvgVe

The scale label configuration is nested under the scale configuration in the scaleLabel key

Says docs: https://www.chartjs.org/docs/latest/axes/labelling.html

Thanks for working examples @LeeLenaleee

@sajTempler scaleLabel in this case is a bad name. It's for the axis title. See https://codepen.io/etimberg/pen/bGeXLPB

Thanks for the answers @LeeLenaleee @etimberg

I guess this issue can be closed 🔐

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joebirkin picture joebirkin  ·  3Comments

lbowers picture lbowers  ·  3Comments

SylarRuby picture SylarRuby  ·  3Comments

akashrajkn picture akashrajkn  ·  3Comments

gabrieldesouza picture gabrieldesouza  ·  3Comments