MS Charts: Getting the real InnerPlotPosition?

▼魔方 西西 提交于 2021-02-07 20:24:19

问题


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

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

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.)


回答1:


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); 


来源:https://stackoverflow.com/questions/7283394/ms-charts-getting-the-real-innerplotposition

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!