3

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.

Harish
  • 1,374
  • 17
  • 39

2 Answers2

3

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
    ...
}
Wingzero
  • 9,644
  • 10
  • 39
  • 80
3

Try this code to set font for Left Axis (Y - left), the same with Right Axis:

   myChartView.leftAxis.labelFont = UIFont.systemFont(ofSize: 17.0, weight: UIFontWeightRegular)
    myChartView.leftAxis.labelTextColor = .orange
Lê Trinh
  • 327
  • 3
  • 11