Search code examples
iosfontsios-charts

How to set font for y-axis iOS Charts


I know that I am able to set the font of the x-axis in iOS Charts using the following code:

myChart.xAxis.labelFont = UIFont.init(name: "AvenirNext-Regular", size: 10)!

So, I thought that I would be able to change the font of the y-axis using similar code such as:

myChart.getAxis(.Right).labelFont = UIFont.init(name: "AvenirNext-Heavy", size: 10)!

However, the following code doesn't do anything. Is it possible to change the font of the y-axis? I tried to run the app and there was no change in the font.


Solution

  • It should work on y axis too, I checked the func, and it is reading labelFont already (If you think it's a bug, report it on github):

    /// draws the y-labels on the specified x-position
    internal func drawYLabels(context context: CGContext, fixedPosition: CGFloat, offset: CGFloat, textAlign: NSTextAlignment)
    {
        guard let yAxis = yAxis else { return }
    
        let labelFont = yAxis.labelFont
        let labelTextColor = yAxis.labelTextColor
        ...
    }