仅允许在核心图条形图中水平滚动?

发布于 2024-08-15 00:21:22 字数 278 浏览 8 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

孤单情人 2024-08-22 00:21:22

如果您使用的是 Core-Plot 0.2.2 或更高版本(可能更早),那么您可以在绘图空间的委托上添加一个方法来处理以下操作:

-(CGPoint)plotSpace:(CPTPlotSpace *)space willDisplaceBy:(CGPoint)displacement {
    return CGPointMake(displacement.x, 0);
}

这会将绘图移动限制为仅水平移动。这假设您已通过设置 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:

-(CGPoint)plotSpace:(CPTPlotSpace *)space willDisplaceBy:(CGPoint)displacement {
    return CGPointMake(displacement.x, 0);
}

This will restrict the plot movement to horizontal only. This assumes you have allowed interacting with the plot space by setting allowsUserInteraction = YES.

咽泪装欢 2024-08-22 00:21:22

通过在绘图空间上设置委托(即 CPPlotSpaceDelegate)来限制滚动并实现 willChangePlotRangeTo 方法。您可以同时做其他很酷的事情。以下是我如何将显示限制为第一象限:

- (CPPlotRange *)plotSpace:(CPPlotSpace *)space
    willChangePlotRangeTo:(CPPlotRange *)newRange
            forCoordinate:(CPCoordinate)coordinate {

    // Display only Quadrant I: never let the location go negative.
    //
    if (newRange.locationDouble < 0.0F) {
        newRange.location = CPDecimalFromFloat(0.0);
    }

    // Adjust axis to keep them in view at the left and bottom;
    // adjust scale-labels to match the scroll.
    //
    CPXYAxisSet *axisSet = (CPXYAxisSet *)self.graph.axisSet;
        if (coordinate == CPCoordinateX) {
            axisSet.yAxis.orthogonalCoordinateDecimal = newRange.location;
            axisSet.xAxis.titleLocation = CPDecimalFromFloat(newRange. newRange.locationDouble +
                                                             (newRange.lengthDouble / 2.0F));
        } else {
            axisSet.xAxis.orthogonalCoordinateDecimal = newRange.location;
            axisSet.yAxis.titleLocation = CPDecimalFromFloat(newRange.locationDouble +
                                                             (newRange.lengthDouble / 2.0F));
        }

    return newRange;
}

请参阅: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:

- (CPPlotRange *)plotSpace:(CPPlotSpace *)space
    willChangePlotRangeTo:(CPPlotRange *)newRange
            forCoordinate:(CPCoordinate)coordinate {

    // Display only Quadrant I: never let the location go negative.
    //
    if (newRange.locationDouble < 0.0F) {
        newRange.location = CPDecimalFromFloat(0.0);
    }

    // Adjust axis to keep them in view at the left and bottom;
    // adjust scale-labels to match the scroll.
    //
    CPXYAxisSet *axisSet = (CPXYAxisSet *)self.graph.axisSet;
        if (coordinate == CPCoordinateX) {
            axisSet.yAxis.orthogonalCoordinateDecimal = newRange.location;
            axisSet.xAxis.titleLocation = CPDecimalFromFloat(newRange. newRange.locationDouble +
                                                             (newRange.lengthDouble / 2.0F));
        } else {
            axisSet.xAxis.orthogonalCoordinateDecimal = newRange.location;
            axisSet.yAxis.titleLocation = CPDecimalFromFloat(newRange.locationDouble +
                                                             (newRange.lengthDouble / 2.0F));
        }

    return newRange;
}

See: CPPlotSpace.h

疯了 2024-08-22 00:21:22

我使用了一种简单的方法来“禁用”垂直滚动

    CPPlotRange *globalYRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(minY) length:CPDecimalFromDouble(maxY)];
    plotSpace.globalYRange = globalYRange;

For, minY 和 maxY 我输入了我显示的值,就像垂直限制就是你所看到的,所以你不能垂直滚动

它对我有用,在我看到你的主题,所以我想用我的来完成你的答案

I used a simple way to "disable" the vertical scroll

    CPPlotRange *globalYRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(minY) length:CPDecimalFromDouble(maxY)];
    plotSpace.globalYRange = globalYRange;

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

终难愈 2024-08-22 00:21:22

直到最近,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.

素食主义者 2024-08-22 00:21:22

使用 CorePlot 1.0——为了将滚动限制为水平和缩放,我实现了两个 CPTPlotSpaceDelegate 方法:Steve Tranby 的方法和supperAly/edo42 建议的修改方法。

-(CGPoint)plotSpace:(CPTPlotSpace *)space willDisplaceBy:(CGPoint)displacement
{
    return CGPointMake(displacement.x, 0);
}

-(CPTPlotRange *)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate
{
    if (coordinate == CPTCoordinateY) {
    newRange = ((CPTXYPlotSpace*)space).yRange;
    }
    return newRange;
}

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.

-(CGPoint)plotSpace:(CPTPlotSpace *)space willDisplaceBy:(CGPoint)displacement
{
    return CGPointMake(displacement.x, 0);
}

-(CPTPlotRange *)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate
{
    if (coordinate == CPTCoordinateY) {
    newRange = ((CPTXYPlotSpace*)space).yRange;
    }
    return newRange;
}
累赘 2024-08-22 00:21:22

我正在使用 CorePlot 0.2.2

-(CPPlotRange *)plotSpace:(CPPlotSpace *)space willChangePlotRangeTo:(CPPlotRange *)newRange forCoordinate:(CPCoordinate)coordinate;
{
    CPXYPlotSpace * plot_space = (CPXYPlotSpace*)space;
    plot_space.globalYRange = plot_space.yRange;
    return newRange;
}

你需要将 CPPlotSpaceDelegate、CPLineStyleDelegate 协议添加到你的控制器

并添加(对于 CPLineStyleDelegate)

-(void)lineStyleDidChange:(CPLineStyle *)lineStyle
{
//empty
}

系统将保留 y 轴的原始范围

i am using CorePlot 0.2.2

-(CPPlotRange *)plotSpace:(CPPlotSpace *)space willChangePlotRangeTo:(CPPlotRange *)newRange forCoordinate:(CPCoordinate)coordinate;
{
    CPXYPlotSpace * plot_space = (CPXYPlotSpace*)space;
    plot_space.globalYRange = plot_space.yRange;
    return newRange;
}

u will need to add CPPlotSpaceDelegate,CPLineStyleDelegate protocols to your controller

and add (for CPLineStyleDelegate)

-(void)lineStyleDidChange:(CPLineStyle *)lineStyle
{
//empty
}

the system will keep the original range of y axis

沦落红尘 2024-08-22 00:21:22

在答案 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 now newRange.locationDouble ) is to set plotSpace.globalYRange = plotSpace.yRange;

初见终念 2024-08-22 00:21:22

感谢超级艾莉
当我的界面实现“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.

厌味 2024-08-22 00:21:22

以下代码基于 Tom Donaldson 的回答,并已使用 CorePlot 1.5.1 进行了测试:

- (CPTPlotRange *)plotSpace:(CPTPlotSpace *)space
      willChangePlotRangeTo:(CPTPlotRange *)newRange
              forCoordinate:(CPTCoordinate)coordinate
{
    CPTMutablePlotRange *range = [CPTMutablePlotRange plotRangeWithLocation:newRange.location length:newRange.length];

    // Display only Quadrant I: never let the location go negative.
    //
    if (range.locationDouble < 0.0F)
    {
        range.location = CPTDecimalFromFloat(0.0);
    }

    // Adjust axis to keep them in view at the left and bottom;
    // adjust scale-labels to match the scroll.
    //
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *) space.graph.axisSet;
    if (coordinate == CPTCoordinateX)
    {
        axisSet.yAxis.orthogonalCoordinateDecimal = range.location;
        axisSet.xAxis.titleLocation               = CPTDecimalFromDouble(range.locationDouble + (range.lengthDouble / 2.0F));
    }
    else
    {
        axisSet.xAxis.orthogonalCoordinateDecimal = range.location;
        axisSet.yAxis.titleLocation               = CPTDecimalFromDouble(range.locationDouble + (range.lengthDouble / 2.0F));
    }

    return range;
}

The following code is based on Tom Donaldson's answer and has been tested with CorePlot 1.5.1:

- (CPTPlotRange *)plotSpace:(CPTPlotSpace *)space
      willChangePlotRangeTo:(CPTPlotRange *)newRange
              forCoordinate:(CPTCoordinate)coordinate
{
    CPTMutablePlotRange *range = [CPTMutablePlotRange plotRangeWithLocation:newRange.location length:newRange.length];

    // Display only Quadrant I: never let the location go negative.
    //
    if (range.locationDouble < 0.0F)
    {
        range.location = CPTDecimalFromFloat(0.0);
    }

    // Adjust axis to keep them in view at the left and bottom;
    // adjust scale-labels to match the scroll.
    //
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *) space.graph.axisSet;
    if (coordinate == CPTCoordinateX)
    {
        axisSet.yAxis.orthogonalCoordinateDecimal = range.location;
        axisSet.xAxis.titleLocation               = CPTDecimalFromDouble(range.locationDouble + (range.lengthDouble / 2.0F));
    }
    else
    {
        axisSet.xAxis.orthogonalCoordinateDecimal = range.location;
        axisSet.yAxis.titleLocation               = CPTDecimalFromDouble(range.locationDouble + (range.lengthDouble / 2.0F));
    }

    return range;
}
ゞ记忆︶ㄣ 2024-08-22 00:21:22

您可以重写

-(void)scaleBy:(CGFloat)interactionScale aboutPoint:(CGPoint)plotAreaPoint`

CPTXYPlotSpace 中的函数并取出与 y 轴移动相关的所有代码。

You can override the

-(void)scaleBy:(CGFloat)interactionScale aboutPoint:(CGPoint)plotAreaPoint`

function in CPTXYPlotSpace and take out all the code related to the movement for y axis.

七色彩虹 2024-08-22 00:21:22

@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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文