c# Winform MSChart를 사용하다가

 

파일에서 데이터를 불러와 표현 할 때 기존의 데이터 스케일이 너무 커서

새로 불러들인 데이터의 스케일이 작게 나타나 보이는 현상이 발생하였다.

첫 파일 불러오기
두 번째 파일 불러오기 - 기존 Scale을 유지하여 데이터를 파악 할 수 없다.

이를 자동으로 영역을 재 설정 하기 위해서는 다음과 같은 코드가 필요하다

chart.ChartAreas[0].AxisY.Maximum = Double.NaN;
chart.ChartAreas[0].AxisY.Minimum = Double.NaN;
chart.ChartAreas[0].RecalculateAxesScale();

 

위 코드를 삽입 후 데이터를 확인하면 아래와 같이 영역이 재 설정 되는 것을 확인 할 수 있다.

두 번째 파일 불러오기 - 영역이 재 설정 되었다.

 

 

 

출처

.net - How do I force a chart to auto adjust Y Axis Maximum? - Stack Overflow

반응형

MSChart 확장 라이브러리에 MSChart Extension 이 있다.

이 라이브러리를 사용하면 Zoom과 Pan, Cursor 기능을 쉽게 사용할 수 있다.

 

GitHub - Code-Artist/MSChartExtension: Windows Forms MSChart Extensions Method

 

GitHub - Code-Artist/MSChartExtension: Windows Forms MSChart Extensions Method

Windows Forms MSChart Extensions Method. Contribute to Code-Artist/MSChartExtension development by creating an account on GitHub.

github.com

 

이 라이브러리를 사용중에 Cursor를 프로그램적으로 지우고 싶었는데 아무리 해도 지울 수 있는 방법이 없었다.

 

Cursor

 

라이브러리를 분석해보니까 ClearCursor1() 메소드가 있었다.

그런데 접근한정자가 private인 것이다..

 

MSChartExtension Library의 일부

 

메소드 안을 보니 RemoveAnnotation을 하는 것이다.

 

그래서 chart의 Annotations 속성을 보니 Count가 4개가 있었다.

{chartAreaName}Cursor_1X

{chartAreaName}Cursor_1Y

{chartAreaName}cursor1_Label_BG

{chartAreaName}cursor1_Label

 

 

 

이 네개의 Annotation을 RemoveAnnotation을 호출하여 제거하도록 하였다.

chartMain.RemoveAnnotation(chartMain.ChartAreas[0].Name + "Cursor_1X");
chartMain.RemoveAnnotation(chartMain.ChartAreas[0].Name + "Cursor_1Y");
chartMain.RemoveAnnotation(chartMain.ChartAreas[0].Name + "cursor1_Label");
chartMain.RemoveAnnotation(chartMain.ChartAreas[0].Name + "cursor1_Label_BG");

 

 

그랬더니 잘 지워진다.

 

반응형

+ Recent posts