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

How to setup up y-axis with min, max value and a fixed step between the grid lines? #227

Closed
SvenMuc opened this issue Jul 17, 2015 · 14 comments

Comments

@SvenMuc
Copy link
Contributor

SvenMuc commented Jul 17, 2015

Hi,
I'm just in the learning phase of using ios-charts. I like to change the x-axis grid to fixed values.
My plotted y-values are just int numbers like 1, 2, 3,..., 10. Nevertheless the left y-axis shows values like 6.3, 9.1, etc., depending on my zoom level.
The second question is, how to setup the x-axis in order to show the labels 1,5,10,15,....40?

Is there any way to influence the step size like e.g. in Excel?

// zoom y-axis to min/max value
lineChart.leftAxis.customAxisMin = max(0.0, lineChart.data!.yMin - 1.0)
lineChart.leftAxis.customAxisMax = min(10.0, lineChart.data!.yMax + 1.0)
lineChart.leftAxis.startAtZeroEnabled = false

Chart (min = 6.0 and max = 10.0):
linechartview

The arrangement strongly depends on the min and max value.

Chart (min = 3.0 and max = 10.0):
bildschirmfoto 2015-07-17 um 22 13 16

Thanks for your support.

@SvenMuc
Copy link
Contributor Author

SvenMuc commented Jul 19, 2015

I identified that something goes wrong in the function internal func computeAxisValues(#min: Double, max: Double) in the class ChartYAxisRenderer. But I do not understand the source code. The function is called 5 times.

What are the following lines exactly doing? Where is the labelCount defined?

var rawInterval = range / Double(labelCount)
var interval = ChartUtils.roundToNextSignificant(number: Double(rawInterval))
var intervalMagnitude = pow(10.0, round(log10(interval)))
var intervalSigDigit = (interval / intervalMagnitude)

@danielgindi
Copy link
Collaborator

You can specify customAxisMin/customAxisMax to whatever values you want

@SvenMuc
Copy link
Contributor Author

SvenMuc commented Jul 19, 2015

What do you mean with whatever values you want? Are these values ignored?
How can I achieve a well aligned grid?

@danielgindi
Copy link
Collaborator

It means that you specify the minimum/maximum for the Y axis like you want. I'm kind of short on time right now but I wanted to give you an answer anyway, so you should just look at the axis features, or look at the demos :-)

@danielgindi
Copy link
Collaborator

If I have the time later I'll try to give you a more detailed answer

@SvenMuc
Copy link
Contributor Author

SvenMuc commented Jul 19, 2015

Hi,
I solved the issue by analysing your source code. I forgot to set the labelCount.

            lineChart.leftAxis.customAxisMin = max(0.0, lineChart.data!.yMin - 1.0)
            lineChart.leftAxis.customAxisMax = min(10.0, lineChart.data!.yMax + 1.0)
            lineChart.leftAxis.labelCount = Int(lineChart.leftAxis.customAxisMax - lineChart.leftAxis.customAxisMin)
            lineChart.leftAxis.startAtZeroEnabled = false

@ramkrishna880
Copy link

My issue is that few cases y axis labels are not showing. (for bar and line graphs)

please help me to resolve this.

@sheetal-hemrom
Copy link

@ramkrishna880 setLabelsToSkip(0) in your Axis

@pranavBiz2Credit
Copy link

@danielgindi cant seem to access customAxisMin/customAxisMaxfor combined charts. Is there a way to fixate on the maximum and minimum values for Y-axis in Combined Chart?

@pranavBiz2Credit
Copy link

Hi again never mind figured this out..

axisMaximum/axisMinimum did the trick.

Such a marvellous plugin. You have no idea how easy you guys have made life for us developers.

A Massive Thank you!!

@haozhouxu
Copy link

you can set axis : MinValue="0" in xaml
image

@AwaisFayyaz
Copy link

AwaisFayyaz commented Sep 25, 2018

Hi, Can any body tell me how to specify fixed intervals for y axis. I am using positive negative bar chart.
charts 3.1.1

like 1.1, 1.3, 1.5 intervals for y axis in positive negative bar chart. see the attached image

Thanks
how to intervals

@auraamitios
Copy link

You can specify customAxisMin/customAxisMax to whatever values you want

Hi Daniel will these properties also work for Bar chart?

@jayrawat
Copy link

@pranavBiz2Credit can you provide code for how you set max, min & no of labels in combined chart by using axisMaximum/axisMinimum? I need to not use automatic calculation & set no of labels based on data set

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

No branches or pull requests

9 participants