2012-07-31 39 views
7

我一直在研究在c#中繪製圖表的方式。我有一個具體的要求,用ay軸和x軸和第二y軸繪製圖表。我嘗試過使用excel interop,但還沒有找到解決方案。我已經開始使用MSChart組件,但還沒有達到任何數據有工作是繪製與主要和次要y軸c線圖#

index lines branches 
1  20  5 
2  30  8 
3  34  6 

我想繪製在x軸和規模indexies左側y軸的右邊Y軸分支的刻度線。

我使用的.NET版本2.0和3.5,是否可以幫助

回答

11

當創建一個系列,YAxisType屬性設置爲AxisType.PrimaryAxisType.Secondary

 var lines = new Series("lines"); 
     lines.ChartType = SeriesChartType.Line; 
     lines.Points.Add(new DataPoint(1, 20)); 
     lines.Points.Add(new DataPoint(2, 30)); 
     lines.Points.Add(new DataPoint(3, 34)); 
     lines.YAxisType = AxisType.Primary; 
     chart1.Series.Add(lines); 

     var branches = new Series("branches"); 
     branches.ChartType = SeriesChartType.Line; 
     branches.Points.Add(new DataPoint(1, 5)); 
     branches.Points.Add(new DataPoint(2, 6)); 
     branches.Points.Add(new DataPoint(3, 8)); 
     branches.YAxisType = AxisType.Secondary; 
     chart1.Series.Add(branches); 

這導致這樣的圖表,這聽起來就像你在做什麼。下面的例子有點難看,它包含主要和次要y值等,但您可以通過設置圖表控件的屬性來按照自己想要的方式進行清理。

enter image description here

+0

非常感謝hmqcnoesy – mayukh 2012-09-26 11:44:08

+0

究竟什麼是你設置來調節它們的屬性? – muzzlator 2013-05-24 05:15:28

相關問題