gridColor applied to wrong axis #179
Description
- I have searched for existing issues
- I have provided detailed instructions that can reproduce the issue (including code and data necessary)
The newly added gridColor option (see #121) has the axis swapped. Specifying a gridColor on the x-axis options will cause it to draw vertical lines in that color, and for the y-axis options it draws horizontal lines.
Example:
axisX: {
gridColor: 'red',
tickColor: 'red',
...
}
axisY: {
gridColor: 'green',
tickColor: 'green',
...
}
I'm new to the whole library, but as far I think it works is that the lines are drawn from the tick positions and then up (for x-axis) or right (for y-axis) to create the gridlines. With that assumption I found the quickest solution to be just swapping the values around to the correct axis. Each chart seems to start with
let options = new Options(this.props)
So I have a quick fix in the constructor of the Options class that I can PR for, if
- we agree this is actually an issue and not intended behaviour
- the below suggestion is the right place to solve the problem (that depends if my above understanding about how the grid lines are drawn was correct)
In the Options class:
this.options = props.options || {}
if (this.options.axisX && this.options.axisY) {
// get axis color if any
let yGridColor = this.options.axisX.gridColor || null
let xGridColor = this.options.axisY.gridColor || null
// swap to correct axis
this.options.axisX.gridColor = xGridColor
this.options.axisY.gridColor = yGridColor
}
This simply swaps the gridColor for the axises before the charts start using them. If the gridColor
key is not specified it will use the default.