2016-11-23 44 views
0

我可以輕鬆創建兩個單獨的圖表,但我想將它們添加到一個圖表中。一個在上面,另一個在下面。那我該怎麼做?使用窗口圖表形式在彼此下面添加兩個圖表

這是我迄今爲止嘗試過的代碼,但它只在頂部繪製一個圖表。

// Chart chart1 = new Chart(); 
      Chart chart1 = new Chart() 
      { 
       Width = 500, 
       Height = 1000 
      }; 


      chart1.Legends[0].Docking = Docking.Bottom; 
      ChartArea chartArea = new ChartArea() { Name = "ChartArea0" }; 
      //Remove X-axis grid lines 
      chartArea.AxisX.MajorGrid.LineWidth = 0; 
      //Remove Y-axis grid lines 
      chartArea.AxisY.MajorGrid.LineWidth = 0; 
      //Chart Area Back Color 

      chart1.ChartAreas.Add(chartArea); 

      chart1.Palette = ChartColorPalette.SeaGreen; 

      // Set title. 
      chart1.Titles.Add(" GIS"); 

      // Add series. 
      for (int i = 0; i < seriesEXpArray.Length; i++) 
      { 
       // Add series. 
       Series series = chart1.Series.Add(seriesEXpArray[i]); 
       series.ChartArea= "ChartArea0"; 
       // Add point. 
       series.Points.Add(ExppointsArray[i]); 
      } 

      chartArea = new ChartArea() { Name = "ChartArea1" }; 
      //Remove X-axis grid lines 
      chartArea.AxisX.MajorGrid.LineWidth = 0; 
      //Remove Y-axis grid lines 
      chartArea.AxisY.MajorGrid.LineWidth = 0; 
      //Chart Area Back Color 

      chart1.ChartAreas.Add(chartArea); 

      // Add series. 
      for (int i = 0; i < seriesUserCommenArray.Length; i++) 
      { 
       // Add series. 
       Series series = chart1.Series.Add(seriesUserCommenArray[i]); 
       series.ChartArea = "ChartArea1"; 
       // Add point. 
       series.Points.Add(UserCommentpointsArray[i]); 
      } 

回答

1

最有可能你的表格是不是大到足以容納你把它設置Height來..

更改爲5001000像素,並遵守其ChartAreas兩個Series ..

第二個(和第三個)ChartArea默認爲放置在第一個之下。並且都自動調整大小以顯示所有系列中的所有點。

添加第四個ChartArea時,版面會自動更改爲2x2網格。

如果要覆蓋ChartAreas的默認排列方式,可以通過設置Positions來完成。請參閱here for an example

順便說一句:要擺脫MajorGrid線是清潔國際海事組織寫:

chartArea.AxisX.MajorGrid.Enabled = false; 

等。

您也可以簡化ChartAreas創作,也Series這樣的:

ChartArea chartArea1 = chart1.ChartAreas.Add("ChartArea1"); 
.. 
Series series1 = chart1.Series.Add("S1"); 
.. 

最後:您確實意識到您正在添加多個Series每個只有一個DataPoint?這是相當不尋常的..

+0

謝謝你的幫助。它的工作 –