简体   繁体   中英

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.

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

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
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM