WPF에서 최근의 연구, 차트는 선 그래프, 가로축 사용자 정의 시간 정보를 그릴 유사한 컨트롤을 사용합니다. 너무 적은 사람들과 WPF로, DynamicDataDisplay.ChartPlotter, 툴킷을 공부했다,이 정보도 거의 찾아 볼 수있다. 가로축을 달성하기 DynamicDataDisplay.ChartPlotter이 시간을 표시,하지만 역사는 시간 정보가 아닌 현재 시간을 보여줍니다 생각하지만, 다음 폐기. 하나님을 알고있을 경우 내가 다음 큰 변경하려면 어떻게, 알림.
이러한 모든 그릴 차트 익숙한의 WinForm에서 사용하려는 나를 이끌었다.
1. 우선, 기준 추가
가 system.windows.forms.dll
WindowsFormsIntegration.dll
System.Windows.Forms.DataVisualization.dll
..이 XAML 네임 스페이스를 추가
의 xmlns : WFI = " CLR 네임 스페이스 : System.Windows.Forms.Integration; 조립체 = WindowsFormsIntegration " 의 xmlns : WF = " CLR 네임 스페이스 : System.Windows.Forms; 조립체 = System.Windows.Forms " 의 xmlns : 대하 = " CLR -namespace : System.Windows.Forms.DataVisualization.Charting; 조립체 = System.Windows.Forms.DataVisualization "
3.WPF 직접의 WinForm 차트를 인용되지 않지만에서 호스팅 할 수 있습니다 WindowsFormsHost
사용, 그래서 우리는 호스트 컨테이너를 추가해야합니다.
<WindowsFormsHost X : NAME = " WFHost_HistoryFlow " 마진 = " 1 " > <대하 : 표 X : NAME = " Chart_HistoryFlow " 로 getToolTipText = " Chart_HistoryFlow_GetToolTipText " 에 BackColor = " 화이트 스모크 " 을 MouseWheel = " Chart_HistoryFlow_MouseWheel " /> </ WindowsFormsHost>
4. .cs 뒤에 네임 스페이스 코드를 추가
사용 System.Windows.Forms 단계; 사용 System.Windows.Forms.DataVisualization.Charting 단계;
5. 배경 코드
5.1 개인 변수
DataTable의 데이터 테이블 = 새로운 DataTable의 ();
5.2 초기화
/// <요약> /// 設定차트 컨트롤 /// </ 요약> 전용 공간 SetChart () { ChartArea의 CA = 새로운 ChartArea ( " ChartArea1 " ); 이 .Chart_HistoryFlow.ChartAreas.Add (CA); ChartArea ca_Pres = 새로운 ChartArea ( " ChartArea1 " ); 이 .Chart_HistoryPres.ChartAreas.Add (ca_Pres); ChartArea ca_Ratio = 새로운 ChartArea ( " ChartArea1 "); 이 .Chart_HistoryRatio.ChartAreas.Add (ca_Ratio); // 프로세서 System.Windows.Forms.DataVisualization.Charting.Legend lgFlow = 새로운 System.Windows.Forms.DataVisualization.Charting.Legend ( " Legend1 " ); lgFlow.IsTextAutoFit = 진정한 ; lgFlow.Docking = Docking.Top; 이 .Chart_HistoryFlow.Legends.Add (lgFlow); System.Windows.Forms.DataVisualization.Charting.Legend lgPres = 새로운 System.Windows.Forms.DataVisualization.Charting.Legend ( " Legend1" ) lgPres.IsTextAutoFit = 참 ; lgPres.Docking = Docking.Top, 이 .Chart_HistoryPres.Legends.Add (lgPres) System.Windows.Forms.DataVisualization.Charting.Legend lgRatio = 새로운 System.Windows.Forms.DataVisualization. Charting.Legend ( " Legend1 " ) lgRatio.IsTextAutoFit = 참 ; lgRatio.Docking = Docking.Top, 이 .Chart_HistoryRatio.Legends.Add (lgRatio) SetChartAutoBar (Chart_HistoryFlow); SetChartAutoBar (Chart_HistoryPres); SetChartAutoBar (Chart_HistoryRatio) } /// <요약> ///가 커서 선 그래프 세트 /// </ 요약> 개인 공극 SetChartAutoBar 차트 (차트) { // 커서 설정 chart.ChartAreas [ 0 ] = .CursorX.IsUserEnabled 사실을 행 ; chart.ChartAreas [ 0 ] = .CursorX.AutoScroll true로 ; chart.ChartAreas [ 0 ] = .CursorX.IsUserSelectionEnabled true로 ; // X 축를 설정하는 것은 축소 될 수 있는지 chart.ChartAreas [ 0= .AxisX.ScaleView.Zoomable true로 ; // 축 좌표를 내장 압연 [chart.ChartAreas 0 ] = .AxisX.ScrollBar.IsPositionedInside true로는 ; // 스크롤 바의 크기를 설정 chart.ChartAreas [ 0 ]을 .AxisX .ScrollBar.Size = 10 ; // 스크롤바 버튼 스타일 설정, 다음 코드가 표시되어있는 스크롤 바의 모든 버튼이다 chart.ChartAreas [ 0 ] = .AxisX.ScrollBar.ButtonStyle ; ScrollBarButtonStyles.All // 집합 최소량의 자동 확대 및 축소된다 chart.ChartAreas [ 0 ] = .AxisX.ScaleView.SmallScrollSize .NaN;이중 chart.ChartAreas [ 0 ] .AxisX.ScaleView.SmallScrollMinSize = 1 ; }
5.3 이벤트
/// <요약> /// 최소 및 최대 데이터 슬라이드 정지 위치에 대응하는 과거 동선 차트 마우스 스크롤 바 /// </ 요약> /// <PARAM NAME = "SENDER"> </ PARAM> /// <매개 변수 이름 = "E"> </ PARAM> 개인 무효 Chart_HistoryFlow_MouseWheel ( 개체 보낸 사람, System.Windows.Forms.MouseEventArgs E) { // 스케일링 Ctrl 키를 누른 IF ((System.Windows.Forms.Control.ModifierKeys 및 키 .Control) == Keys.Control) { IF (e.Delta < 0 ) Chart_HistoryFlow.ChartAreas [ 0 ] + = .AxisX.ScaleView.Size 4. ; 사람의 Chart_HistoryFlow.ChartAreas는 [ 0 = -] .AxisX.ScaleView.Size 4. ; } // Ctrl 키를 누르지 스크롤 다른을 { IF (e.Delta가 < 0 ) { // 최대 데이터 +보다 더 현재 뷰 위치를 중지 IF ( Chart_HistoryFlow.ChartAreas [ 0 ] + .AxisX.ScaleView.Position Chart_HistoryFlow.ChartAreas [ 0 ] .AxisX.ScaleView.Size <Chart_HistoryFlow.ChartAreas [ 0 ] .AxisX.ScaleView.ViewMaximum) Chart_HistoryFlow.ChartAreas [ 0 ] .AxisX.ScaleView. [위치 + = 4. ; } 다른 { // 현재의 정지 위치가 최소 데이터보다 낮은 IF (Chart_HistoryFlow.ChartAreas [ 0 ] .AxisX.ScaleView.Position> Chart_HistoryFlow.ChartAreas [ 0 ] .AxisX.ScaleView.ViewMinimum) Chart_HistoryFlow.ChartAreas [ 0 ] .AxisX.ScaleView .POSITION - = 4. ; } } } /// <요약> /// 유동 펄스 선 그래프 커서 표시 상세한 데이터 /// </ 요약> /// <PARAM NAME = "SENDER"> </ PARAM> // / <매개 변수 이름 = "E"> </ PARAM> 개인 무효Chart_HistoryFlow_GetToolTipText ( 오브젝트 송신자 System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs E) { 경우 (e.HitTestResult.ChartElementType == ChartElementType.DataPoint) { 이 .Cursor = System.Windows.Input.Cursors.Cross; INT I = e.HitTestResult.PointIndex; 문자열 시간 = 이 .dataTable.Rows [I] " 时间" ]로 .toString (); 문자열 aFlow = 이 .dataTable.Rows [I] " 脉冲" ]로 .toString (); 문자열 bFlow = 이 .dataTable.Rows [I] ' B脉冲" ]로 .toString (); 문자열 aPressure = 이 .dataTable.Rows [I]를 [ " 压力" ]로 .toString (); 문자열 bPressure = 이 .dataTable.Rows [I] ' B의压力" ]로 .toString (); 문자열 abRatio = 이 .dataTable.Rows [I] " AB比率" ]로 .toString (); e.Text = $ "시간 : {시간} \ R 노나 펄스 \ {aFlow} \ R는 NB 펄스 \ {bFlow} \ R nA의 압력 \ {aPressure} \ R는 NB 압력 \ {bPressure} \ R NAB 비율 \ {abRatio} " ; } 다른 { 은이 .cursor = System.Windows.Input.Cursors.Arrow; } }
5.4 의 차트에 기록 데이터를
/// <요약> /// 차트 DataTable의 기록 데이터 /// </ 요약> /// <PARAM NAME = "는이 데이터 테이블"> DataTable에 포함 된 데이터 </ PARAM> /// <PARAM NAME = "차트 "> 차트 데이터가 기록 될 </ PARAM> 공개 공극 DataTableToChart (DataTable에 DataTable의 차트의 차트 문자열 타이틀 문자열 시리즈 1의 문자열 시리즈 2) { chart.Series.Clear (); // 차트 맑고 chart.Titles 하는 명확한 (); chart.Titles.Add (제목); // 제목 추가 차트.데이터 소스 = 데이터 테이블; ACodeSeries 시리즈 (시리즈 1의) = chart.Series.Add는; // 첫번째 테이블을 추가 aCodeSeries.ChartType = SeriesChartType.Line; // 설정 선 차트 시리즈 1의 aCodeSeries.YValueMembers =; // Y 축 데이터 aCodeSeries.XValueMember = " 시간 " , 시리즈 bCodeSeries = chart.Series.Add (시리즈 2) //는 두 번째 테이블을 추가 bCodeSeries.ChartType = SeriesChartType.Line; // 설정 선 차트 = bCodeSeries.YValueMembers 시리즈 2; }
DataTable의 "시간"라고 내 칼럼, "펄스", "B 펄스", "압력", "B 압력"에 데이터를 기록하려면 "AB 비율."
5.5 표시
OVER ~ 일러스트 sahua