Calculate plotSpace X and Y

83 views
Skip to first unread message

Nic Hubbard

unread,
Dec 1, 2010, 5:02:04 PM12/1/10
to coreplot-discuss
Currently my graph is just looking flat, and I am wondering why, and
think it is because of my x and y range are wrong. How do I calculate
these? Here is what I am using:

CGFloat max = 0.0;
CGFloat min = FLT_MAX;

for (NSNumber *dataValue in sortedArray) {
min = MIN([dataValue floatValue], min);
max = MAX([dataValue floatValue], max);
}

plotSpace.xRange = [CPPlotRange
plotRangeWithLocation:CPDecimalFromFloat(0.0)
length:CPDecimalFromFloat(max - min)];
plotSpace.yRange = [CPPlotRange
plotRangeWithLocation:CPDecimalFromFloat(0.0)
length:CPDecimalFromFloat(num_points)];

Eric

unread,
Dec 1, 2010, 11:16:08 PM12/1/10
to coreplot-discuss
As I said in my reply to your question on stackoverflow.com (http://
stackoverflow.com/questions/4327712/), you're returning the same value
for X and Y which is what's causing the straight line.

Assuming you meant to use the data index as your X-value and the value
from your dataValue array as the Y-value, I would calculate the plot
space ranges like this:

plotSpace.xRange = [CPPlotRange
plotRangeWithLocation:CPDecimalFromFloat(0.0)
length:CPDecimalFromUnsignedInteger(dataValue.count)];
plotSpace.yRange = [CPPlotRange
plotRangeWithLocation:CPDecimalFromFloat(min)
length:CPDecimalFromFloat(max - min)];

Eric

Nic Hubbard

unread,
Dec 2, 2010, 2:19:23 PM12/2/10
to coreplot-discuss
Thank you, Thank you!

I am not sure why I was not able to figure this out from the examples,
but I now have it working.
Reply all
Reply to author
Forward
0 new messages