开发者

How do I determine the position of a tick in x-axis of a graph?

开发者 https://www.devze.com 2023-02-26 05:16 出处:网络
I want to get position(x,y) of a tick in x-axis of 开发者_高级运维a graph to manual draw a line according it, please help me!

I want to get position(x,y) of a tick in x-axis of 开发者_高级运维a graph to manual draw a line according it, please help me! Please view below image to get my clearly question:

How do I determine the position of a tick in x-axis of a graph?


You can get the Y coordinate of all x-axis ticks like this: y = ActiveChart.Axes(xlValue).CrossesAt. In your example image, this will be 0.

The ticks on the x-axis will have X coordinates between ActiveChart.Axes(xlCategory).MinimumScale and ActiveChart.Axes(xlCategory).MaximumScale, both inclusive, at intervals of ActiveChart.Axes(xlCategory).MajorUnit.

Of course, if you know ahead of time which X value you want to highlight, then that X will be the X coordinate of the tick.

The above is assuming your chart is selected/activated. Instead of ActiveChart, you can use ActiveSheet.ChartObjects("Chart 1").Chart or whatever the correct reference to your chart is.

EDIT: Just realized that the example you show is a Line chart. It won't be possible to do what you're asking on a Line chart. You have to change the chart type to an XY (Scatter) chart first.

0

精彩评论

暂无评论...
验证码 换一张
取 消