core-plot iOS 反转 Y 轴
我想使用 core-plot 来显示水深图(实时更新),但我不知道如何反转 Y 轴,以便 X 轴(代表时域)位于顶部我的 UIView 和 Y 轴以正值向底部增长。
编辑
如果我能像这样画轴那就更好了:
- X轴是时间
- Y 轴从 0 到 X(X > 0),顶部为 0,底部为 X
- X 轴位于底部
ASCII 版本:
0 |
1 |
.
.
.
x |
--------------------------
0 1 2 3 4 5 6 7 ...
I would like to use core-plot to display a water depth graph (updated in real time) but I can't figure out how to reverse the Y axis, so that the X axis (representing the time domain) is on the top of my UIView and the Y axis grows towards the bottom with positive values.
EDIT
It would be even better if I could draw axes like this:
- X axis is time
- Y axis is from 0 to X (X > 0) and on the top there is 0, on the bottom there is X
- X axis is on the bottom
ASCII version:
0 |
1 |
.
.
.
x |
--------------------------
0 1 2 3 4 5 6 7 ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以对绘图范围使用负长度来反转轴的方向。例如(来自 CPTTestApp 中的轴演示):
You can use a negative length for the plot range to reverse the direction of an axis. For example (from the axis demo in CPTTestApp):
从接受的答案来看,这最终有点难以理解。要为任何不了解如何翻转 coreplot 中 y 轴值的人添加另一个示例,您确实需要将 plotRangeWithLocation 声明为您想要实现的正数,然后将长度设置为 <强>相同的负数,如下所示:
从 iOS 14 和 coreplot 2020 年中版本开始,这会产生这样的 y 轴:
This ended up being a bit tricky to understand from the accepted answer. To add another example for anyone having issues understanding how to flip the y axis values in coreplot, you really need to declare the plotRangeWithLocation to be the positive number you want to achieve, then set the length to the same negative number like this:
This produces a y-axis like this as of iOS 14 and coreplot mid 2020 versions: