Grids Not Showing

158 views
Skip to first unread message

Yoshiki Vázquez Baeza

unread,
May 4, 2012, 2:22:13 AM5/4/12
to coreplot-discuss
Hello,

I'm working with a CPTXYGraph, so far so good, your framework is
powerful (cheers on that!) and functional. I'm currently facing a
problem where I provide labels for the X axis and labels for the Y
axis, I of course set the policy to CPTAxisLabelingPolicyNone, the
only problem is that when I do this, I would immediately the grids
that I have previously set.

Is this a known behavior? Am I'm missing something? Would showing you
guys the code help?

Thanks!

Yoshiki.

Eric

unread,
May 4, 2012, 6:59:32 PM5/4/12
to coreplot...@googlegroups.com
With CPTAxisLabelingPolicyNone, you also have to provide the tick locations (major and/or minor). The grid lines are drawn at the corresponding tick locations.

Eric

Yoshiki Vázquez Baeza

unread,
May 4, 2012, 7:45:20 PM5/4/12
to coreplot-discuss
Hello Eric, and Thanks! That solved my problem.

Now, I wonder about the following, when I added the tick locations, I
noticed that the grids would remain static in the background. I have
the interactions enabled and it seems that when you drag around the
scope of the plot or zoom, the grids are static in the background.

Thanks!

Yoshiki.

Eric

unread,
May 4, 2012, 9:03:09 PM5/4/12
to coreplot...@googlegroups.com
The grid lines should move with the tick marks on the axis. Do you have more than one plot space?

Eric

Yoshiki Vázquez Baeza

unread,
May 5, 2012, 1:30:56 PM5/5/12
to coreplot-discuss
Nope, I do no thave more than one plot space, what I have is various
CPTScatterPlot objects, I don't know if that might be a problem.

Eric

unread,
May 5, 2012, 6:10:23 PM5/5/12
to coreplot...@googlegroups.com
The grid lines are attached to the axes—it shouldn't matter how many plots you have. What value of separateLayers are you using? The default is NO. Are you on iOS? If so, what is the value of collapsesLayers on the hosting view? Can you post some of your setup code?

Eric

Yoshiki Vázquez Baeza

unread,
May 6, 2012, 8:19:17 PM5/6/12
to coreplot-discuss
Hello, of the two properties you are mentioning, I have nothing
special set-up.

This is what the main set-up look like:

//Set the hosting view, in this case it won't be resizable
CPTGraphHostingView *hostingView = [[CPTGraphHostingView
alloc] initWithFrame:CGRectMake(0, 0, frame.size.width,
frame.size.height)];
[hostingView setBackgroundColor:[UIColor clearColor]];

//Create and allocate the graph, it will be re-sized as needed
graph=[[CPTXYGraph alloc] initWithFrame:CGRectZero];

//The hosting view is the main holder for all the plot
[hostingView setHostedGraph:graph];
[hostingView setAutoresizingMask:UIViewAutoresizingNone];

//Now that everything is set, begin the customization
[self addSubview:hostingView];
[hostingView release];

//The theme will be default black
[graph applyTheme:[CPTTheme themeNamed:kCPTStocksTheme]];

//The plot uses all the hosting view space
[graph setPaddingLeft:PBPlotPaddingNone];
[graph setPaddingTop:PBPlotPaddingNone];
[graph setPaddingBottom:PBPlotPaddingNone];
[graph setPaddingRight:PBPlotPaddingNone];

//Add a little padding to the right to make the last tick
visible
[[graph plotAreaFrame] setPaddingRight:2];

[graph setLegendAnchor:CPTRectAnchorLeft];

//By default do not allow the user interaction
[[graph defaultPlotSpace] setAllowsUserInteraction:NO];

Eric

unread,
May 6, 2012, 8:28:56 PM5/6/12
to coreplot...@googlegroups.com
I don't see anything out of place in that code. What version of Core Plot are you using?

Eric

Yoshiki Vázquez Baeza

unread,
May 6, 2012, 9:24:20 PM5/6/12
to coreplot-discuss
Hello I'm using version 1.0, this is how I'm setting up my girds:

//Get the axes' axisSet property
CPTXYAxisSet *axisSet=(CPTXYAxisSet *)[graph axisSet];
CPTXYAxis *yAxis=[axisSet yAxis];
CPTXYAxis *xAxis=[axisSet xAxis];

//Avoid overhead, create this objects once
CPTColor *grayColor=[[CPTColor colorWithGenericGray:0.2]
colorWithAlphaComponent:0.75];
CPTLineStyle *gridLineStyle=[PBUtilities lineStyleWithWidth:0.75
andColor:grayColor];

//Y axis gird lines
[yAxis setMajorGridLineStyle:gridLineStyle];
[yAxis setMinorGridLineStyle:gridLineStyle];
[yAxis setTickDirection:CPTSignNone];

//X axis gird lines
[xAxis setMajorGridLineStyle:gridLineStyle];
[xAxis setMinorGridLineStyle:gridLineStyle];
[xAxis setTickDirection:CPTSignNone];

And when I set up my ticks:

int i=0;
NSMutableArray *newAxisLabels=[[NSMutableArray alloc] init];
NSMutableArray *tickLocations=[[NSMutableArray alloc] init];
CPTAxisLabel *newLabel=nil;

//Keep the current appearance by retrieving these properties
CPTXYPlotSpace *plotSpace=(CPTXYPlotSpace *)[graph
defaultPlotSpace];
CPTXYAxisSet *axisSet=(CPTXYAxisSet *)[graph axisSet];
CPTXYAxis *xAxis=[axisSet xAxis];
CPTTextStyle *currentStyle=[xAxis labelTextStyle];

//If you don't set the policy to none, you won't be able to see
your custom labels
[xAxis setLabelingPolicy:CPTAxisLabelingPolicyNone];

//Avoid the over-head of repeating this calculations for each
iteration
float majorTickInterval=CPTDecimalFloatValue([xAxis
majorIntervalLength]);
CGFloat tickLabelOffset=[xAxis labelOffset]+[xAxis
majorTickLength]/2.0;

//The use of the ranges help us calculate how many ticks are
visible in the scrreen
float rangeLocation=CPTDecimalFloatValue([[plotSpace xRange]
location]);
float rangeLength=CPTDecimalFloatValue([[plotSpace xRange]
length]);
int visibleTicks=(int)floor((rangeLength / majorTickInterval));

#ifdef DEBUG
NSLog(@"There are %d visible ticks for the X axis", visibleTicks);
#endif

//Just be careful and let the programmer know if he screwed
something
if ([labels count] < visibleTicks) {
[NSException raise:@"PBPLot" format:@"You provided %d X ticks
labels, the method needs %d", [labels count], visibleTicks];
}

//Go through every of the visible ticks and add the custom label
provided
for(i=0; i<=visibleTicks; i++){
//Add the locations of the ticks, otherwise you will loose all
the lines and grids
[tickLocations addObject:[NSDecimalNumber
numberWithFloat:rangeLocation + (i * majorTickInterval)]];

newLabel=[[CPTAxisLabel alloc] initWithText:[labels
objectAtIndex:i] textStyle:currentStyle];
[newLabel setTickLocation:CPTDecimalFromFloat(rangeLocation +
(i * majorTickInterval))];
[newLabel setOffset:tickLabelOffset];
[newLabel setRotation:rotation];
[newAxisLabels addObject:newLabel];
[newLabel release];
}

//Add the ticks locations, otherwise no girds will be shown
[xAxis setMajorTickLocations:[NSSet setWithArray:tickLocations]];
[tickLocations release];

//Add the labels and manage your memory
[xAxis setAxisLabels:[NSSet setWithArray:newAxisLabels]];
[newAxisLabels release];

Eric

unread,
May 7, 2012, 8:32:08 PM5/7/12
to coreplot...@googlegroups.com
That code looks ok, too, although I didn't try to run it. Have you looked at the example apps? Find one that demonstrates custom tick locations, turn on plot space interaction, and see if it behaves the way you expect.

Eric

Yoshiki Vázquez Baeza

unread,
May 8, 2012, 2:26:06 AM5/8/12
to coreplot-discuss
Hello,

I've been trying various things (including your suggestion), I just
don't get the girds to move along with the custom ticks :S If I only
set the CPTAxisLabelingPolicyNone for one of the two axis, the girds
move as they are supposed to, but there are only girds on the places
where I have set a tick location. When I set the same policy for the
two axis, the girds stay in the same place.

Is there something else to try? The ticks locations and custom labels
are working as expected it is only the grid lines that are not really
working.

Thanks for any help that could be provided!

Yoshiki.

Eric

unread,
May 8, 2012, 9:35:17 PM5/8/12
to coreplot...@googlegroups.com
I'll have to test with two custom axes and see if I can reproduce the problem (my previous testing only included one custom axis). You should report this on the issue tracker so the problem doesn't get lost here on the discussion board.

Thanks,
Eric

Yoshiki Vázquez Baeza

unread,
May 8, 2012, 10:44:54 PM5/8/12
to coreplot-discuss
Hello,

Ok, I agree, but prior to reporting it I would like to see if someone
else has the same problem or if I'm missing something.

Let me know what happens and if you are able to reproduce the problem,
else I could share the complete code I'm using.

Thanks!

Yoshiki.
> ...
>
> leer más »

Eric

unread,
May 9, 2012, 8:53:18 PM5/9/12
to coreplot...@googlegroups.com
I was able to reproduce this in a test app. Please report it on the issue tracker and I'll work on fixing it.

Thanks,
Eric

Yoshiki Vázquez Baeza

unread,
May 10, 2012, 11:21:33 AM5/10/12
to coreplot...@googlegroups.com
Hello, 

Thanks Eric, I have posted this on the issue tracker. http://code.google.com/p/core-plot/issues/detail?id=433

Let me know if I can help in any way, is there a specifically place where I could get info about the development version of the framework? 

Thanks!

Yoshiki.

Eric

unread,
May 10, 2012, 9:48:03 PM5/10/12
to coreplot...@googlegroups.com
You can get the latest code here: http://code.google.com/p/core-plot/source/checkout

We also have a couple of wiki pages with more information.

Eric
Message has been deleted
Message has been deleted

Yoshiki Vázquez Baeza

unread,
May 18, 2012, 1:37:46 AM5/18/12
to coreplot-discuss
Hello,

I've found another thing, this will probably either help or be
useless:

When dragging around the graph, the grids remain static, though if I
touch a point and show an annotation on screen, the grids move to the
place where they should be showing. I will try to check out the
specific code that both of these actions have in common to try to fix
this. I'm not sure if I'm being clear, if not let me know.

Thanks!

Yoshiki.
> ...
>
> leer más »

Eric

unread,
May 18, 2012, 7:44:17 PM5/18/12
to coreplot...@googlegroups.com
It appears that the grids always draw in the proper place, but that there are some situations where they aren't told to redraw (using -setNeedsDisplay) when they should be.

Eric

Eric

unread,
May 24, 2012, 8:54:23 PM5/24/12
to coreplot...@googlegroups.com

Yoshiki Vázquez Baeza

unread,
May 29, 2012, 1:31:07 AM5/29/12
to coreplot-discuss
Hello,

Thanks!!!

I noticed this was solved, I'm sorry I didn't post anything before.

Thanks so much for the awesome support.

On 24 mayo, 18:54, Eric <eskr...@mac.com> wrote:
> This issue has been fixed.
>
> http://code.google.com/p/core-plot/source/detail?r=f3d72fdf84ff1470a8...
> ...
>
> leer más »
Reply all
Reply to author
Forward
0 new messages