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.
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.
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)!
//set is the object of BarChartDataSet.
set.valueFont = UIFont(name: "your Font name", size: 12) ?? UIFont.systemFont(ofSize: 12)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With