简体   繁体   English

Coreplot中的轴标签修改

[英]Axis label modification in Coreplot

I'm drawing a graph in core plot with an automatic naming policy. 我正在使用自动命名策略在核心图中绘制图表。

My problem is that the numbers in my graph are very high. 我的问题是我的图表中的数字非常高。

For example the axis has 1000000.0 2000000.0 3000000.0 例如,轴具有1000000.0 2000000.0 3000000.0

I'd like some way to over write these and make them 1.00m 2.00m and 3.00m 我想要一些方法来重写这些并使它们成为1.00m 2.00m和3.00m

I've looked into the axis delegate but it only returns a bool and not a specific label. 我查看了轴委托,但它只返回一个bool而不是一个特定的标签。 I've also explored setting the axis label formatter but that cannot add the 'm' on the end, nor I don't think it can turn the number into a decimal similar to scientific notation without the exponential on the end. 我还探讨了设置轴标签格式化程序但是不能在末尾添加“m”,也不认为它可以将数字转换为类似于科学记数法的十进制数而不是最终的指数。

The answer is to set the label formatter on the axis. 答案是在轴上设置标签格式化程序。 From a quick look at the documentation for NSNumberFormatter, it seems you should be able to do what you're looking for with a combination of setPositiveFormat , setMultiplier , and setPositiveSuffix . 通过快速查看NSNumberFormatter的文档,您似乎应该能够通过setPositiveFormatsetMultipliersetPositiveSuffix的组合来完成您正在寻找的内容。

Something like: 就像是:

NSNumberFormatter *labelFormatter = [[NSNumberFormatter alloc] init];
[labelFormatter setPositiveFormat:@"#.##"];
[labelFormatter setPositiveSuffix:@"m"];
[labelFormatter setMultiplier:[NSNumber numberWithDouble:0.000001]];
axisSet.yAxis.labelFormatter = labelFormatter;
[labelFormatter release];

FWIW, the call to setPositiveSuffix isn't strictly necessary here - you can just include the "m" in the format string ( [labelFormatter setPositiveFormat:@"#.##m"] ), and leave that call out if you want. FWIW,这里对setPositiveSuffix的调用并不是绝对必要的 - 您可以在格式字符串中包含“m”( [labelFormatter setPositiveFormat:@"#.##m"] ),并在需要时保留该调用。 I included it here for the sake of completeness, in case you need to do more complex formatting than this. 为了完整起见,我把它包含在这里,以防你需要做比这更复杂的格式化。

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

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