3

I'm using ios-charts to build a line chart and have been customizing it's design. However I'm having some issues with changing some settings/designs right now. This is what it currently looks like.

I can't seem to add vertical spacing between the legend and the graphs x axis labels. They are too close together.

let xAxis = chartView.xAxis
xAxis.labelPosition = .bottom // Emphasis
xAxis.labelFont = UIFont.systemFont(ofSize: 12, weight: .regular)
xAxis.axisLineWidth = 1
xAxis.axisMinimum = 239
xAxis.axisMaximum = 249
//xAxis.yOffset = 15 // ONLY ADDS TOP SPACE   
    
// Legend
chartView.rightAxis.enabled = false // remove from the right side
chartView.legend.font = UIFont.systemFont(ofSize: 12, weight: .regular)
chartView.legend.yEntrySpace = 10
chartView.legend.formSize = 10
chartView.legend.yOffset = 10 // ONLY ADDS BOTTOM SPACE
Tyler Rutt
  • 49
  • 4

2 Answers2

2

Setting the verticalAlignment to VerticalAlignment.top (it is VerticalAlignment.bottom by default) should use the yOffset as the top space.

-1

You can use this parameter:

chartView.legend.yOffset
Victor Morei
  • 180
  • 4
  • 2
    That just adds space between the bottom of legend and the bounds of the chart. Not adding space above the legend. – Tyler Rutt Feb 16 '22 at 20:27