반응형

mschart -- Plot Area ( InnerPlotPosition ) 구하기



참고 : https://stackoverflow.com/questions/40315455/how-to-display-x-axis-and-y-axis-values-when-move-the-mouse/40316759

        https://docs.microsoft.com/en-us/previous-versions/dd456696(v=vs.140)



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

       --> 차트 확대시에는 안맞음...

 





** ChartArea.Position & ChartArea.InnerPlotPostion

--> ElementPosition object  임

The InnerPlotPosition property defines the rectangle within a chart area element that is used for plotting data; it excludes tick marks, axis labels, and so forth.

ChartArea.Position property defines the position of a ChartArea object within the Chart, and includes tick marks, axis labels, and so forth.

ElementPosition  ; 상대좌표 (0,0) ~ (100, 100) 사이값을 가짐.





  -- 해당 윈도우 기준의 '절대적 pixel 값'을 axis 값으로 변환한다. 

  -- axis 값을 '상대값 (0 ~ 100%)'으로 변환한다. 









--

// ChartArea.InnerPlotPosition 은 ChartArea 영역에 대한 100분율 상대좌표임.
// 따라서, 100분율을 역환산하여 ChartArea.InnerPlotPosition 좌표와 크기구함.
RectangleF GetPlotArea(Chart chart, ChartArea CA)
{
RectangleF CArp = GetChartArea(chart, CA); // ChartArea 영역
float pw = CArp.Width / 100f; // ChartArea 영역 백분율 단위
float ph = CArp.Height / 100f;
float x = CArp.X + pw * CA.InnerPlotPosition.X;
float y = CArp.Y + ph * CA.InnerPlotPosition.Y;
float w = pw * CA.InnerPlotPosition.Width;
float h = ph * CA.InnerPlotPosition.Height;
return new RectangleF(x, y, w, h);
}
// ChartArea.Position 은 전체 Chart 영역에 대한 100분율 상대좌표임.
// 따라서, 100분율을 역환산하여 ChartArea 좌표와 크기구함.
RectangleF GetChartArea(Chart chart, ChartArea CA)
{
float pw = chart.ClientSize.Width / 100f; // Chart 영역에 대한 백분율 단위
float ph = chart.ClientSize.Height / 100f; // Chart 영역에 대한 백분율 단위
float x = pw * CA.Position.X;
float y = ph * CA.Position.Y;
float w = pw * CA.Position.Width;
float h = ph * CA.Position.Height;
return new RectangleF(x, y, w, h);
}
// 같은 ChartArea 에서도 y축 axis 다를수 있으므로, 매개변수로 Chartarea 대신에 Axis 사용함.
// 차트 확대시에는 GetPlotArea( ) 와 틀리게, 화면상이 아닌 가상의 확대영역을 반환한다.
RectangleF GetInnerPlotPostionVirtual(Axis ax, Axis ay)
{
float x1 = (float)ax.ValueToPixelPosition(ax.Minimum);
float y1 = (float)ay.ValueToPixelPosition(ay.Maximum);
float w = (float)ax.ValueToPixelPosition(ax.Maximum) - x1;
float h = (float)ay.ValueToPixelPosition(ay.Minimum) - y1;
return new RectangleF(x1, y1, w, h);
}
view raw plotarea.cs hosted with ❤ by GitHub


반응형
Posted by 자유프로그램
,