Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Charts Swift bar graph exceeds beyond view

I have a problem with the Charts library. The problem I am facing is that the bar graph is not "fit" within the borders of my view. The following image shows that, the both first and last bar are cut into half and label of the highest bar is also partially cut.

Bars and labels are cut along the graph borders

When I search online, I got the following thread https://github.com/danielgindi/Charts/issues/353 which seems to describe the exact same issue.

I use a simple dataset with some random numbers at 6 indices. The data is added to the chart as follows:

let values: [Int] = [5, 8, 1, 2, 1, 2]
var dataEntries: [BarChartDataEntry]

for i in 0..<values.count {
    let dataEntry = BarChartDataEntry(x: Double(i), y: Double(values[i]))
    dataEntries.append(dataEntry)
}

let chartDataSet = BarChartDataSet(values: dataEntries, label: "Count")
let chartData = BarChartData(dataSet: chartDataSet)
barChartView.data = chartData

Hopefully someone can help me out. Thanks in advance!

like image 765
Woodahack Avatar asked Aug 20 '16 19:08

Woodahack


1 Answers

you can add the offset to Top and bottom view as below :

 barChartView.extraTopOffset = 40.0f;
 barChartView.extraBottomOffset = 10.0f;
like image 78
ashmi123 Avatar answered Oct 03 '22 18:10

ashmi123