简体   繁体   中英

Coreplot: Autoscaling y-axis labels according to plot data

使用coreplot的两个图形图

I am using coreplot to render graphs on my mobile application as per the attached image. My problem is the graph sometimes doesn't scale well for the y-axis labels. From the graph it is quite evident that the max y-axis label is 3500.0 BUT the actual y-axis maximum value in both the graphs plot points is ONLY 2498. This results in wastage of space from the plots maximum point to the y-axis label's maximum point thereby shrinking my graph. This does not happen with all my graphs but only a few graphs. Ideally, I would expect the y-axis max label to have been set to 3000. OR even better, if there is way to have the maximum y-axis label shown as 2498 instead of 3500 that would be wonderful.

Here is how I set my y-axis range:

plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yMin) length:CPTDecimalFromFloat(yMax)];

ymin  = 1159.000000 and ymax = 2498.000000 //For this example

I've tried to use "scaletoFitPlots" but in vain. I only want the y-axis labels to be scalded properly and NOT the x-axis labels. I've also referred to a few threads on stack overflow such as this - CorePlot - Set y-Axis range to include all data points but in vain :(. I really appreciate some help here.

Follow up question:

主要网格线范围内的图形

图形不在主要网格线范围内

If you see the final two graphs, one of them is completely within the major grid line of the y-axis wheres the other is not within, ie, the max y-axis label is 200000.0 and the maximum value of a plot is above that. Is there a way I can make all my graphs to fall within the major grid line for the maximum value of a y-axis label?

Plot ranges are specified with a starting location and length. You've given a range from 1,159 to 3,657 (1,159 + 2,498). Given the min and max values, the length of the range should be (max - min).

plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yMin)
                                                length:CPTDecimalFromFloat(yMax - yMin)];

The tick mark and label positions are controlled by the axis labeling policy. If you don't care what the labels are, but want them to be at the extremes of the axis, use the CPTAxisLabelingPolicyEqualDivisions labeling policy. If you always want the labels to be "nice" numbers, extend the plot range beyond the min and max data values to the nearest "nice" values. For the example above (1,159 to 2,498), you could choose a starting location of 1,000 and a length of 1,500.

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