简体   繁体   English

如何使用巨大的y轴绘制核心图条形图?

[英]How to draw a coreplot barchart with a huge y-Axis?

I am creating a small iPhone application using CorePlot. 我正在使用CorePlot创建一个小型iPhone应用程序。 The graph consists of 10 bars. 该图由10个条组成。 Unfortunately, the y-values might differ between 0 and 1 million, therefore I create my plotspace with a rather huge yRange 不幸的是,y值可能在0到100万之间不同,因此我使用相当大的yRange创建了我的plotspace

plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(yAxisStart)
                                                length:CPTDecimalFromDouble(yAxisLength)];

What I am experiencing is that my application is really slow when loading the graph, and I can pinpoint this issue to the rather large value of yAxisLength. 我所经历的是,在加载图形时我的应用程序非常慢,我可以将此问题精确定位到yAxisLength的相当大的值。 I already removed the creation of tickmarks on the y axis, but still the performance is very bad. 我已经在y轴上删除了刻度标记的创建,但性能仍然非常糟糕。 Can anyone give me a hint how to improve performance? 任何人都可以给我一个提示如何提高性能?

Make sure you update the labeling parameters, even if you don't need any labels or ticks. 即使您不需要任何标签或刻度,也要确保更新标签参数。 The default labeling policy creates tick marks and labels one unit apart. 默认标签策略创建刻度线并将一个单元标记为一个单位。 That's why a large axis range slows your app down so much. 这就是为什么大轴范围会使您的应用程序减速太多的原因。 It also creates a separate Core Animation layer for each label. 它还为每个标签创建单独的Core Animation层。 Creating 1 million labels will take a long time and use a lot of memory. 创建100万个标签需要很长时间并占用大量内存。

If you don't need any ticks or labels, set the labeling policy to CPTAxisLabelingPolicyNone . 如果您不需要任何刻度或标签,请将标签策略设置为CPTAxisLabelingPolicyNone Otherwise, make the necessary adjustments to the various labeling properties (which ones to use depends on which policy you choose) so that there are reasonable number of ticks within the axis range. 否则,对各种标签属性进行必要的调整(使用哪些属性取决于您选择的策略),以便在轴范围内有合理数量的标记。

I haven't used CorePlot, but maybe you can scale your data before trying to plot it. 我没有使用过CorePlot,但也许你可以在尝试绘制之前扩展数据。

If the y-scale ranges up to a million, then divide y-max and all your y-values by 100,000. 如果y比例范围高达一百万,则将y-max和所有y值除以100,000。 Then just add something like "(x100,000)" to the y-axis label. 然后在y轴标签上添加类似“(x100,000)”的内容。

 y.labelingPolicy        = CPTAxisLabelingPolicyAutomatic;
    y.majorGridLineStyle    = nil;
    y.minorGridLineStyle    = nil;
    y.axisConstraints       = [CPTConstraints constraintWithLowerOffset:0.0];
    y.majorIntervalLength = CPTDecimalFromDouble(maxRange/2.0);

worked for me. 为我工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM