Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LineChart Axis Inset? #46

Closed
msanders opened this issue Apr 23, 2015 · 25 comments
Closed

LineChart Axis Inset? #46

msanders opened this issue Apr 23, 2015 · 25 comments
Labels

Comments

@msanders
Copy link
Contributor

Hi, thanks for the great library! Is it possible to add an inner padding to x axes as shown in the picture below?

graph padding

I.e., both the first and last points and xAxis labels are inset by ~15px. Would be super useful. Thanks!

@msanders msanders changed the title Line chart axis inset? LineChart Axis Inset? Apr 23, 2015
@danielgindi
Copy link
Collaborator

@PhilJay what do you think? do we have an easy way of "skipping" x-indexes?

@PhilJay
Copy link
Collaborator

PhilJay commented May 3, 2015

Well an easy workaround could be to use "" as the first x value and then insert the first entry at x index 1

@danielgindi
Copy link
Collaborator

@msanders did that solve your problem?

@msanders
Copy link
Contributor Author

msanders commented May 4, 2015

@danielgindi No, that insets it much more than I wanted. Is it not possible to add an inset property just for layout?

@danielgindi
Copy link
Collaborator

Not right now - we'll have to look into it

@BurhanMughal
Copy link

Any News about above mentioned issue ?

@danielgindi
Copy link
Collaborator

@BurhanMughal Please, you are creating too much noise in the system. If there were new, you would have known. You are welcome to try to implement whatever feature is missing, or wait until someone else or I make it.

@BurhanMughal
Copy link

Sorry Daniel if you feel bad. But i was just looking to get informed that the issue is still in process because you closed this issue.

@danielgindi danielgindi reopened this May 13, 2015
@msanders
Copy link
Contributor Author

@danielgindi Any thoughts as to how we could go about implementing this? Would it just be an update to ChartXAxisRenderer?

@danielgindi
Copy link
Collaborator

danielgindi commented May 13, 2015 via email

@danielgindi
Copy link
Collaborator

Well it wouldn't be just about the XAxisRenderer as the other renders (the
chart renderers) would need the spacing also.
So I guess it would be in the ViewPort, but I did not have the time to look
into it yet, as we have other things on our plate :)

‏בתאריך יום רביעי, 13 במאי 2015, Daniel Cohen Gindi danielgindi@gmail.com
כתב:

I closed it earlier when there was no response to the suggestions

@SvenMuc
Copy link
Contributor

SvenMuc commented Aug 24, 2015

Tried to analyze the ChartViewPortHandler.swift file in order to set the inset. So far without any success. It's hard to understand the code.

I tried to modify the _contentRect, but this changes the size of the whole diagram. As a next step I will try to test different effects by changing the affine transformation.

Does someone can give me a short hint?

@liuxuan30
Copy link
Member

speaking of view port handler, you need to think about the transformers. ios-charts need the transformer to calculate the postions. will adding slight offset in transformer help?

@odedharth
Copy link

tried @PhilJay suggestion but it's problematic when you have few entries...
photo 19-04-2016 3 38 25 pm

@liuxuan30
Copy link
Member

liuxuan30 commented Apr 20, 2016

did anyone try to change chartXMin so it will have slight offset at the beggining? I remember I tried once, and deltaX potentially impacts the offset on right side

@danielgindi
Copy link
Collaborator

Implemented in Charts 3.0 (v3 branch) (Use axisMinValue/axisMaxValue)

@liuxuan30
Copy link
Member

does it hold a property for that?

@DevangiDesai
Copy link

Found solution for spacing on xAxis
chartView.xAxis.spaceMin = 0.5
chartView.xAxis.spaceMax = 0.5

@jetboh
Copy link

jetboh commented Jun 17, 2017

spaceMin / spaceMax didn't work for me but adjusting axisMinValue / axisMaxValue slightly did.

@29satnam
Copy link

29satnam commented May 9, 2018

@DevangiDesai solution does work if you want to add padding on xAxis at right and left.

self.chartView.xAxis.spaceMin = 10; self.chartView.xAxis.spaceMax = 2;

Here's a preview for future viewers:

screen shot 2018-05-09 at 1 50 45 pm

@juancarlosdmz
Copy link

Hi, this is an old issue, but I have a problem when I try to do this:
lineChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: model.months) lineChartView.xAxis.setLabelCount(model.months.count, force: true) lineChartView.xAxis.spaceMin = 0.2; lineChartView.xAxis.spaceMax = 0.2

the space is working, but I'm not being able to draw the twelve months, any idea?

@iraklivasha
Copy link

Hi Guys,

Can someone point the exact configuration for LineChartView so it displays paddings from left and right ? @DevangiDesai I tried code below too, but with no luck. Is there any chance that some other configuration is overlapping this settings ?

chartView.xAxis.spaceMin = 0.5
chartView.xAxis.spaceMax = 0.5

Screen Shot 2019-08-16 at 11 31 28 AM

@elliotcz97
Copy link

elliotcz97 commented Aug 5, 2020

Today i faced the same problem as you guys. The methods to use are:

    chartView.xAxis.spaceMin = 0.5
    chartView.xAxis.spaceMax = 0.5

If you want it to work you have to set these properties before you set the data of the chart (at least i got it this way to work)

So for my project i did it this way:

    let data = LineChartData(dataSet: dataSet)
    chartView.xAxis.spaceMin = 0.2
    chartView.xAxis.spaceMax = 0.2
    chartView.data = data

I hope this helps someone in the future. Great library btw, i love it!

@seriyvolk83
Copy link

seriyvolk83 commented Aug 20, 2020

Not the solution, but will help anyone who searches for how to remove the paddings:

chartView.xAxis.avoidFirstLastClippingEnabled = true
chartView.minOffset = 0

@cameronehrlich
Copy link

Not the solution, but will help anyone who searches for how to remove the paddings:

chartView.xAxis.avoidFirstLastClippingEnabled = true
chartView.minOffset = 0

Thank you @seriyvolk83, this solved the problem I was having!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests