8

I am trying to change the size of the labels below the graph, these labels have the texts "Explanation for set1" and "Explanation for set2". Changing the valueFont of the sets only changes the font/size of datapoints on the graph it self, but not the Eplanation labels below.

    var yVals1 = Array<BarChartDataEntry>()
    var yVals2 = Array<BarChartDataEntry>()

    yVals1.append(BarChartDataEntry(value: Double(number1), xIndex: 0))
    yVals2.append(BarChartDataEntry(value: Double(number2), xIndex: 0))

    var set1: BarChartDataSet?
    var set2: BarChartDataSet?

    set1 = BarChartDataSet(yVals: yVals1, label: "Explanation for set1")
    set1?.valueFont = UIFont(name: "Verdana", size: 14.0)!
    set1?.setColor(UIColor.redColor())
    set2 = BarChartDataSet(yVals: yVals2, label: "Explanation for set2")
    set2?.valueFont = UIFont(name: "Verdana", size: 14.0)!
    set2!.setColor(UIColor.blueColor())

    var data = BarChartData()
    data.addDataSet(set1)
    data.addDataSet(set2)

Btw I am using version 2.2.5 of the library.

When I increase the size of the xAxis label from

      mChart.xAxis.labelFont = UIFont(name: "HelveticaNeue-Light", size: 12.0)!

to:

      mChart.xAxis.labelFont = UIFont(name: "HelveticaNeue-Light", size: 25.0)!

The label size seeems to increase (since there is more space between the explanation texts and the graph) but the actual text size doesn´t increase. enter image description here

DevB2F
  • 4,674
  • 4
  • 36
  • 60

3 Answers3

8

I solved my problem by updating the Charts library to version 3.0.2 and then adding the following code:

 let legend = mChart.legend
 legend.font = UIFont(name: "Verdana", size: 16.0)!

this legend option is something that was not available in the previous version of Charts I was using.

DevB2F
  • 4,674
  • 4
  • 36
  • 60
5

You need to update/set the labelFont property of the XAxis class of the BarChartView in order to change fontSize of the xAxis labels. You can refer the below code.

//chartView is the object of BarChartView class.
let  xAxis : XAxis = self.chartView.xAxis
xAxis.labelFont = UIFont(name: "HelveticaNeue-Light", size: 10.0)!
Prakash Donga
  • 558
  • 5
  • 10
  • Thanks for that input, please check my edited answer to see what happened when I added your code. – DevB2F Apr 22 '17 at 17:57
5
//set is the object of BarChartDataSet.
set.valueFont = UIFont(name: "your Font name", size: 12) ?? UIFont.systemFont(ofSize: 12)
Ruchin Somal
  • 1,073
  • 12
  • 14
  • This only changes the font of the value on the graph, not the font for the text below the graph. – DevB2F May 09 '17 at 16:51