CodeChanger
CodeChanger

Reputation: 8351

Unable to remove extra margin in BarChart (Charts)

One of my app using Charts library for drawing graphs.

Everything works fine but in BarChartView it's adding some default margin around the chart and I have done the below changes in the Chart property but still, it's not removing the margin around the graph.

I have also checked the same issue on this Question thread but no luck at all.

Check below screenshot for margin issue:

enter image description here

I have done the below changes for removing the margin around BarChart.

_barChartView.minOffset = 0;
    
_barChartView.xAxis.enabled = NO;
            
ChartYAxis *leftAxis = _barChartView.leftAxis;
leftAxis.drawGridLinesEnabled = NO;
            
_barChartView.leftAxis.enabled = NO;
_barChartView.leftAxis.drawAxisLineEnabled = NO;
            
_barChartView.rightAxis.enabled = NO;
_barChartView.rightAxis.drawAxisLineEnabled = NO;
_barChartView.legend.enabled = NO;

But still, I am not able to remove the margin.

Also checked Charts Demo app has the same issue while changing data from the slider.

Check Below screenshot from Chart Demo App:

enter image description here

Any help or hint appreciated :)

Upvotes: 0

Views: 788

Answers (2)

Ando
Ando

Reputation: 1827

I know this is old but just for anyone who stumbles upon the question

This solved it for me

barChartView.leftAxis.axisMinimum = 0
barChartView.rightAxis.axisMinimum = 0

Upvotes: 1

Bhavesh Dhaduk
Bhavesh Dhaduk

Reputation: 1906

Hello I have checked in the demo of Charts library which you have provided.

Where i have added below code and it's work, check the screenshot below.

BarChartViewController.h Add this code on line number : 115

_chartView.minOffset = 0;

_chartView.xAxis.enabled = NO;

_chartView.leftAxis.enabled = NO;
_chartView.leftAxis.drawAxisLineEnabled = NO;

_chartView.rightAxis.enabled = NO;
_chartView.rightAxis.drawAxisLineEnabled = NO;
_chartView.legend.enabled = NO;

enter image description here

enter image description here

let me know for more.

Here is the output of my simulator with blue background.

enter image description here

Upvotes: 3

Related Questions