计算折线图上两点的角度

发布于 2024-12-01 04:54:53 字数 284 浏览 1 评论 0原文

我想获得折线图上两点的角度。 我知道如何计算角度,问题是我需要 seriescollection.point 的 x 和 y,但我不知道如何获取它。

有人可以帮我吗?

编辑:

Jean-François Corbett 向我展示了如何获取点,我的意思是从顶部和左侧,而不是图表上的点(在 X 比例和 Y 比例上),尽管它可以工作。 我算错了。如何计算下图中的角度?

在此处输入图像描述

I want to get the angle of two points on a Line chart.
I know how to calculate an angle, the problem is that I need the x and y of the seriescollection.point and I have no idea how to get it.

Can someone help me with it?

EDIT:

Jean-François Corbett showed me how to get the points, I meant from top and left, and not point on the graph (on X scale and Y scale) though it can work.
I calculate it wrong. how can I calculate the angles in the picture below?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

居里长安 2024-12-08 04:54:53

您询问如何获取图表系列中点的 (x,y) 坐标。方法如下:

Dim c As Chart
Dim s As Series
Dim x As Variant
Dim y As Variant

Set c = ActiveChart
Set s = c.SeriesCollection.Item(1)

x = s.XValues
y = s.Values

编辑 据我从编辑的问题中可以看出,OP现在想要每个点的像素坐标,原点位于绘图的左上角。为此,您只需按轴宽度和跨度进行缩放即可。对于线图(我讨厌),x 轴有点棘手,因为没有最小或最大比例属性;必须使用“类别”的数量来代替。以下代码执行此缩放:

Dim c As Chart
Dim s As Series
Dim xa As Axis
Dim ya As Axis
Dim x As Variant
Dim y As Variant
Dim i As Long

Set c = ActiveChart
Set s = c.SeriesCollection.Item(1)
Set xa = c.Axes(xlCategory)
Set ya = c.Axes(xlValue)

x = s.XValues
y = s.Values
For i = LBound(x) To UBound(x)
    ' Scale x by number of categories, equal to UBound(x) - LBound(x) + 1
    x(i) = (i - LBound(x) + 0.5) / (UBound(x) - LBound(x) + 1) * xa.Width
    ' Scale y by axis span
    y(i) = ya.Height - y(i) / (ya.MaximumScale - ya.MinimumScale) * ya.Height
Next i

请注意,y 沿绘图上的负 y 方向增加,因为您希望原点位于左上角。

使用此 xy,您可以计算屏幕上看到的角度。

You ask how to get the (x,y) coordinates of points in a chart series. Here is how:

Dim c As Chart
Dim s As Series
Dim x As Variant
Dim y As Variant

Set c = ActiveChart
Set s = c.SeriesCollection.Item(1)

x = s.XValues
y = s.Values

EDIT As far as I can tell from the edited question, OP now wants the pixel coordinates of each point, with origin at the top left of the plot. To do so, you just need to scale by the axis width and span. The x axis is a bit tricky in the case of line plots (which I hate), because there is no min or max scale property; have to use the number of "categories" instead. The following code does this scaling:

Dim c As Chart
Dim s As Series
Dim xa As Axis
Dim ya As Axis
Dim x As Variant
Dim y As Variant
Dim i As Long

Set c = ActiveChart
Set s = c.SeriesCollection.Item(1)
Set xa = c.Axes(xlCategory)
Set ya = c.Axes(xlValue)

x = s.XValues
y = s.Values
For i = LBound(x) To UBound(x)
    ' Scale x by number of categories, equal to UBound(x) - LBound(x) + 1
    x(i) = (i - LBound(x) + 0.5) / (UBound(x) - LBound(x) + 1) * xa.Width
    ' Scale y by axis span
    y(i) = ya.Height - y(i) / (ya.MaximumScale - ya.MinimumScale) * ya.Height
Next i

Note that y increases along the negative y direction on the plot, since you want the origin to be at the top left.

Using this x and y, you can calculate your angle as seen on the screen.

热风软妹 2024-12-08 04:54:53

X 和 Y 值不能直接从 Point 对象访问(据我所知),但它们代表传递的实际值到图表。尝试从存储它们的工作表中访问它们。

如果该方法不可用,请尝试使用 Series.values(它返回 Y 值数组)和 Series.XValues(它返回 X 值数组)。 (请参阅 MSDN 参考

The X and Y values are not directly accessible from the Point object, (as best as I can tell), but they represent actual values passed to the graph. Try accessing them from the worksheet where they are stored.

If that is unavailable, try Series.values, which returns an array of Y-values, and Series.XValues, which returns an array of X-values. (See MSDN Reference)

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