Reputation: 1532
I am trying to create a bar with a gradient in core plot. I have the following code:
UIImage *img = [UIImage imageNamed:@"orange_bar_graph"];
CPTImage *image = [CPTImage imageWithCGImage:img.CGImage];
image.tiled = NO;
CPTFill *areaFill = [CPTFill fillWithImage:image];
CPTBarPlot *plotOne = [[CPTBarPlot alloc] init];
plotOne.fill = areaFill;
plotOne.identifier = identifer[@"plotOne"];
However when I run the application it just shows the outline of the bars and the fill image is not being shown:
If I place it breaks points it shows that the image is created successfully and that the variable areaFill is not nil.
I did a post a while back where I had this similar code working. Here I use imageForPNGFile but that was just returning nil when trying it here: Core Plot Gradient bars
However I can't seem to get it to work here.
Edit:
I have just ran this on the iPad 2 simulator and it works as expected. However when running on the iPad Air simulator it doesn't work.
Upvotes: 0
Views: 188
Reputation: 27381
Set the scale
of the image.
CPTImage *image = [CPTImage imageWithCGImage:img.CGImage scale:img.scale];
If you're using the latest Core Plot code (after release 1.5.1), you can load the image directly:
CPTImage *image = [CPTImage imageNamed:@"orange_bar_graph"];
Upvotes: 1