Search code examples
javascriptchartschart.js

ChartJS Change Axis color


I have MultipleLine Chart and I want to color axis, because it's impossible to see them on my background.

How can I change this option?

I tried zeroLineColor, but it looks like it doesn't exist anymore.

https://www.chartjs.org/docs/latest/migration/v3-migration.html - says that now I should use scriptable scale options.


Solution

  • The following code can be used to change color of x-axis in chartjs chart.

    options: {
    scales: {
        y: {
        grid: {
                    color: (line) => (line.index === 0 ? 'red' : 'rgba(0, 0, 0, 0.1)')
          }
        }
      }
    }
    

    Thanks.