核心图渐变条 [英] Core Plot Gradient bars

查看:80
本文介绍了核心图渐变条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用核心图来创建图形。

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:

我正在使用应用程序最右边(最高的)图像。但是有2个问题。

I am using the image on the far right (tallest one) within the application. However there are 2 issues.

1)酒吧的酒吧倒挂了。因此,它们从红色开始到黄色。

1) The bar's are upside down. So they start with red and go up to yellow.

2)如果我使用的图像太大,则条形图完全是红色的。如果我使用的图像太小,它将开始重复。如果我使用正确的尺寸图像,那么它似乎可以工作。但是,我将在多个图表中使用这些图像,但它们的大小将不尽相同。因此,使图像具有合适的大小似乎效率不高。另外,每幅图我将有多个条形,因此,如果图形更改大小,则意味着所有图像都必须更改。

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.

非常感谢。

=====

编辑

如果我设置image.tiled = NO,则会得到以下图形:

If I set the image.tiled = NO I get the following graph:

我希望这些图形与原始帖子中的图片一样。因此,大约在250标记附近应该是黄色。而如果是1000,则应该经历从黄色到红色的整个颜色范围。

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.

推荐答案

您正在使用平铺图像,这就是为什么当条形图大于原始图像时会重复显示的原因。将 tiled 设置为 NO 可以拉伸图像以填充条形。我不知道为什么它会被翻转。

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.

这篇关于核心图渐变条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆