问题
I am using core plot to create my graphs.
I want to have a gradient in my bars so that the colour starts at yellow and changes to red. However this depends on how high the bar is. The graphs for example should look as follows:
I am using the image on the far right (tallest one) within the application. However there are 2 issues.
1) The bar's are upside down. So they start with red and go up to yellow.
2) The bar's are totally red if I use an image that's too large. If I use an image that is too small it starts repeating. If I use the correct size image then it seems to works. However I will be using these images across multiple graphs which won't all be the same size. So it seems inefficient to have the images the right size. Plus I will have multiple bars per plot and so if a graph changes size then it will mean all the images will have to be changed.
Here is the code I am using to create the bars:
CPTImage *image = [CPTImage imageForPNGFile:@"gradient-bar"];
image.tiled = YES;
CPTFill *areaFill = [CPTFill fillWithImage:image];
CPTBarPlot *plot = [[CPTBarPlot alloc] init];
plot.fill = areaFill;
plot.identifier = @"BIP";
Here is an image of when the bar image is the right size:
The main thing I am looking for is being able to have one image that I can use on any sized graph.
Many thanks.
=====
Edit
If I set the image.tiled = NO I get the following graph:
I would like the graphs to be as the images from my original post. So around the 250 mark it should just be the yellow colour. Whereas if it's 1000 it should go though the whole range of colours from yellow to red.
回答1:
You're using a tiled image which is why it repeats when the bar is bigger than the original image. Set tiled
to NO
to stretch the image to fill the bar instead. I don't know why it is flipped.
来源:https://stackoverflow.com/questions/26013433/core-plot-gradient-bars