开发者

MS Charts: Getting the real InnerPlotPosition?

开发者 https://www.devze.com 2023-04-01 19:41 出处:网络
When creating charts using Microsoft Charts, I need to get the exact position of the grid on the chart开发者_开发知识库.

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:

MS Charts: Getting the real 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.)


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

精彩评论

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