MS图表:获取真正的InnerPlotPosition? [英] MS Charts: Getting the real InnerPlotPosition?

查看:59
本文介绍了MS图表:获取真正的InnerPlotPosition?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Microsoft图表创建图表时,我需要获取图表上网格的确切位置.

When creating charts using Microsoft Charts, I need to get the exact position of the grid on the chart.

此页面表示-据我了解-这可以通过InnerPlotPosition来实现.但是,使用此属性时,得到以下矩形:

This page says -- as I understand it -- that this can be achieved with InnerPlotPosition. However, when using this property, I get the following rectangle:

此矩形似乎与图表大小成比例;调整图表大小时,矩形会缩小,但仍在网格的所有边缘上保持不变.我尝试过用一个常数添加和乘以两个大小,但是没有一个常数适用于所有大小.

This rectangle seems to scale with the chart size; when resizing the chart, the rectangle shrinks, but still keeps on the outside of the grid on all edges. I have tried both adding and multiplying the sizes with a constant, but no single constant works for all sizes.

因此,为了澄清一下,我想要的是网格上的外部黑色矩形.有什么办法可以得到这个吗?

So, just to clarify, what I want is the outer black rectangle on the grid. Is there any way to get this?

(我一直在考虑从边缘扫描像素,并检测每个方向上的第一个黑色像素,但这听起来像是一堆肮脏的东西.)

(I have been thinking of scanning pixels from the edges, and detecting the first black pixel in each direction, but that sounds like a grotty hack.)

推荐答案

我终于找到了可行的解决方案:

I finally found a solution that works:

     ChartArea a = chart.ChartAreas[0];
     double x1 = a.AxisX.ValueToPixelPosition(a.AxisX.Minimum);
     double x2 = a.AxisX.ValueToPixelPosition(a.AxisX.Maximum);
     double y1 = a.AxisY.ValueToPixelPosition(a.AxisY.Maximum);
     double y2 = a.AxisY.ValueToPixelPosition(a.AxisY.Minimum); 

这篇关于MS图表:获取真正的InnerPlotPosition?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆