仅允许在核心图条形图中水平滚动?
我正在使用 core-plot lib 在我的应用程序中绘制条形图,如下所示
我的问题是我希望仅在水平方向启用 grapgh 移动,以便我可以看到以下记录很长一段时间,但问题是我只是不想将 y 轴固定在其位置,
我该怎么做?
等待帮助....
I am using core-plot lib to draw bar charts in my app like this
My problem is that i want the enabling of grapgh movement only in horizontal direction so that I can see the records for a long period of time, But the problem is that i just wnt to keep the y axis fixed to its place,
How can i do this?
Waiting for help....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
如果您使用的是 Core-Plot 0.2.2 或更高版本(可能更早),那么您可以在绘图空间的委托上添加一个方法来处理以下操作:
这会将绘图移动限制为仅水平移动。这假设您已通过设置 allowedUserInteraction = YES 允许与绘图空间进行交互。
If you are using Core-Plot 0.2.2 or greater (possibly earlier) then you can add a method on your plot space's delegate to handle the following:
This will restrict the plot movement to horizontal only. This assumes you have allowed interacting with the plot space by setting allowsUserInteraction = YES.
通过在绘图空间上设置委托(即 CPPlotSpaceDelegate)来限制滚动并实现 willChangePlotRangeTo 方法。您可以同时做其他很酷的事情。以下是我如何将显示限制为第一象限:
请参阅:CPPlotSpace.h
Limit scrolling by setting a delegate (i.e., CPPlotSpaceDelegate) on the plot space and implement the willChangePlotRangeTo method. You can do other cool things at the same time. Here's how I limit the display to quadrant one:
See: CPPlotSpace.h
我使用了一种简单的方法来“禁用”垂直滚动
For, minY 和 maxY 我输入了我显示的值,就像垂直限制就是你所看到的,所以你不能垂直滚动
它对我有用,在我看到你的主题,所以我想用我的来完成你的答案
I used a simple way to "disable" the vertical scroll
For, minY and maxY I put the values I displayed, like that the vertical limits are what you see, so you can't vertical scroll
It worked for me, after I saw your topic, so I wanted to complete your answers with mine
直到最近,Core Plot 图表中才启用了基本的用户交互。要启用任意方向的滚动,您可以将绘图空间的
allowsUserInteraction
属性设置为 YES。我们目前无法将这一运动锁定在一个方向。滚动操作发生在 CPXYPlotSpace 上的
-pointingDeviceDraggedAtPoint:
方法中,因此您可以对 CPXYPlotSpace 进行子类化,复制该方法的实现,并将其更改为仅允许在 X 方向上移动。更好的是,我们将感谢任何扩展 CPXYPlotSpace 功能以添加对单向移动的支持的贡献。Only recently has rudimentary user interaction been enabled in Core Plot graphs. To enable scrolling in any direction, you can set the
allowsUserInteraction
property of the plot space to YES.We currently have no means of locking that movement to one direction. The scrolling action takes place in the
-pointingDeviceDraggedAtPoint:
method on CPXYPlotSpace, so you could subclass CPXYPlotSpace, copy over its implementation of that method, and alter it to only allow movement in the X direction. Even better, we'd appreciate any contributions to extend the functionality of the CPXYPlotSpace to add support for unidirectional movement.使用 CorePlot 1.0——为了将滚动限制为水平和缩放,我实现了两个 CPTPlotSpaceDelegate 方法:Steve Tranby 的方法和supperAly/edo42 建议的修改方法。
Using CorePlot 1.0 -- To restrict scrolling to just horizontal and scaling as well, I implemented the two CPTPlotSpaceDelegate methods: method by Steve Tranby with a modified method suggested by supperAly/edo42.
我正在使用 CorePlot 0.2.2
你需要将 CPPlotSpaceDelegate、CPLineStyleDelegate 协议添加到你的控制器
并添加(对于 CPLineStyleDelegate)
系统将保留 y 轴的原始范围
i am using CorePlot 0.2.2
u will need to add CPPlotSpaceDelegate,CPLineStyleDelegate protocols to your controller
and add (for CPLineStyleDelegate)
the system will keep the original range of y axis
在答案 4 后,您需要做的就是修复 y 轴,并附上注释。 (
newRange.doublePrecisionLocation
现在是newRange.locationDouble
)是设置plotSpace.globalYRange =plotSpace.yRange;
All you have to do to fix the y axis after Answer 4 with the comment incl. (
newRange.doublePrecisionLocation
is nownewRange.locationDouble
) is to setplotSpace.globalYRange = plotSpace.yRange;
感谢超级艾莉
当我的界面实现“CPPlotSpaceDelegate”协议时
并且该项目无法正常编译,并显示:
你的接口xxx没有实现'CPLineStyleDelegate'协议
,这让我很困惑。所以我添加方法:
-(void)lineStyleDidChange:(CPLineStyle *)lineStyle { //empty }
对于 CPLineStyleDelegate 并将
添加到我的界面,问题就消失了。thanks to supperAly
when my interface implements "CPPlotSpaceDelegate" protocol
and the project can not be complied normally , and shows that:
your interface xxx doesn't implement 'CPLineStyleDelegate' protocol
, which make me confuse.so i add the method :
-(void)lineStyleDidChange:(CPLineStyle *)lineStyle { //empty }
for CPLineStyleDelegate and add
<CPLineStyleDelegate>
to my interface and the problems have gone.以下代码基于 Tom Donaldson 的回答,并已使用 CorePlot 1.5.1 进行了测试:
The following code is based on Tom Donaldson's answer and has been tested with CorePlot 1.5.1:
您可以重写
CPTXYPlotSpace 中的函数并取出与 y 轴移动相关的所有代码。
You can override the
function in CPTXYPlotSpace and take out all the code related to the movement for y axis.
@Andrew S:“我收到‘分配给只读属性’
newRange.location = CPTDecimalFromFloat(0.0);"
我也有这个,并且按照 Core-Plot 库应用程序中的“CurvedScatterPlot”示例,在plotSpace:willChangePlotRangeTo:forCooperative: ...
CPTMutablePlotRange * 中使用了 newRange 的可变副本changedRange = [newRange mutableCopy];
changedRange.location = CPTDecimalFromCGFloat(0.0F); 然后通过了测试,我在 if...else 块中使用了changedRange。
@Andrew S: "I'm getting 'assignment to read-only property' on
newRange.location = CPTDecimalFromFloat(0.0);"
I had that, too, and, following the "CurvedScatterPlot" example in the Core-Plot gallery app, used a mutable copy of newRange in plotSpace:willChangePlotRangeTo:forCoordinate: ...
CPTMutablePlotRange *changedRange = [newRange mutableCopy];
changedRange.location = CPTDecimalFromCGFloat(0.0F); then passes muster and I used changedRange in the if...else block.