Skip to content

Change label color when disabled (instead of standard styles) #10383

Answered by LeeLenaleee
aneuwald asked this question in Q&A
Discussion options

You must be logged in to vote

You can use a custom generateLabels function for this:

generateLabels: function(chart) {
  const datasets = chart.data.datasets;
  const {
    labels: {
      usePointStyle,
      pointStyle,
      textAlign,
      color
    }
  } = chart.legend.options;

  return chart._getSortedDatasetMetas().map((meta) => {
    const style = meta.controller.getStyle(usePointStyle ? 0 : undefined);
    const borderWidth = Chart.helpers.toPadding(style.borderWidth);
    const hidden = !meta.visible;

    return {
      text: datasets[meta.index].label,
      fillStyle: style.backgroundColor,
      fontColor: hidden ? 'red' : color,
      hidden: hidden,
      lineCap: style.borderCapStyle,
      lineDash: 

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@aneuwald
Comment options

Answer selected by aneuwald
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants