반응형
mschart -- Plot Area ( InnerPlotPosition ) 구하기
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
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%)'으로 변환한다.
--
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
반응형
'mschart' 카테고리의 다른 글
C# mschart -- creonplus 일봉, 분봉 차트 그리기 (0) | 2019.04.18 |
---|---|
c# mschart -- 코드만으로 chart 만들기 (0) | 2019.02.20 |
c# mschart -- 마우스 crosshair 그리기 (0) | 2019.02.20 |
c# mschart -- mschart 막대그래프 줌시에도, grid line 사이에 위치시키기 (0) | 2019.01.23 |
c# mschart -- 차트막대 grid 사이로 x축따라 이동하기 (0) | 2019.01.22 |