简体   繁体   中英

How to draw y-axis by dynamic values by using YLow and YHigh

I am using core plot library for drawing the graph. I always get dynamic values for y-axis and I calculate Ymin and Ymax from the result set. The difference between (Ymax-Ymin) may be very low or very high. I want to create dynamic intervals between these values. If the difference is low major interval should be less and if it is high major interval should be high. I can't set the preferredNumberOfMajorTicks static value as values may vary. The code should work for every case. Please guide me with some code example.

@Eric Thanks for the response. I tried both of your solutions.First oneCPTAxisLabelingPolicyEqualDivisions but it always divides the range in one interval say if yMax and yMin are (128.5 and 123.2) then one interval seems nice but if values are (5550-100) then also it shows only one interval with such a big difference of values.Secondly I tried with CPTAxisLabelingPolicyFixedInterval and calculated the majorIntervalLength with by dividing the length by different number of intervals,it works fine but again I don't want to keep the value of interval static .As if I divide the length by 4 then it will always create 4 intervals even for the very low values say 4.5 and 3.5. Can you please guide me if there is any way to calculate the no of intervals by yMax and yMin?

Try the CPTAxisLabelingPolicyAutomatic axis labeling policy. That will pick "nice" intervals within the plot range for the ticks and labels. You can use the CPTAxisLabelingPolicyEqualDivisions labeling policy to always divide the plot range into equal parts, although there are no guarantees that the ticks will be on "nice" values. If you want the most control, stick with the default labeling policy ( CPTAxisLabelingPolicyFixedInterval ). Divide the length of the plot range ( Ymax-Ymin ) by the desired number of intervals to compute the majorIntervalLength .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM