2016-09-20 41 views
0

如何在圖表(C#,Visual Studio 2013)中刪除白色區域(1,2)並減小軸(3)的寬度。圖表的寬度約16000px。 PS:如果圖表的寬度較短(1000-2000像素),則沒有白色區域且軸寬度正常。 enter image description here如何去除圖表中的白色區域?

+0

您使用什麼代碼來設計圖表的樣式?你是否定位ChartArea?另外:請參閱[here!](http://stackoverflow.com/questions/32925981/remove-white-and-unnecessary-space-from-chart-control/32926520?s=1|2.1348#32926520) – TaW

+0

我使用ca 。位置=新ElementPosition(0,10,90,90)並減少(1)中的白色區域。但(2)和chartarea和傳奇之間的whitearea是大而且很大...你可以看到http://share.pho.to/AKnNt/fb/original(原始寬度10500像素) –

回答

0

大的空白處是按比例放大的距離。

當您放大Chart寬度時,可以將位置設置爲較小的值。

注意:您可以將元素的相關屬性爲ElementPosition類型和的..

  • ..its值不是以像素爲單位,但在各自的容器中的百分比。
  • ..初始值全部設置爲0,這意味着Automatic

因此,每次調整圖表大小時需要計算位置,並且由於其他位置仍在0,因此您無法初始設置單個屬性。

這些元素可以定位:

  • Chartarea(s)
  • (每個)的InnerPlotPositionChartarea
  • Legend(s)
  • 其他幾個人,像Annotations,我們並不需要在這裏

你也可以設置th e尺寸Major - 和MinorTickMarksAuto到適當的數值。下面是在這裏工作的16,000Chart.Width一個像素的示例:

ChartArea ca = chart1.ChartAreas[0]; 
Legend L = chart1.Legends[0]; 

ca.Position = new ElementPosition(0.2f, 5, 99, 90); 
ca.InnerPlotPosition = new ElementPosition(0.3f, 1, 99.5f, 90); 
L.Position = new ElementPosition(99.03f, 5, 0.75f, 22); 

ca.AxisY.MajorTickMark.Size = 0.15f; 

ChartArea ca = chart1.ChartAreas[0]; 
ca.Position.X = 0.1f; 
ca.InnerPlotPosition.X = 0.3f; 

Axis ay = ca.AxisY; 
ay.MajorTickMark.Size = 0.1f; 

enter image description here

另外請注意,我看不到任何方式定位YAxis標籤;所以它通常會在左邊。您可以在Paint事件DrawString吧,雖然:

private void chart1_Paint(object sender, PaintEventArgs e) 
{ 
    Axis ay = chart1.ChartAreas[0].AxisY; 
    Graphics g = e.Graphics; 
    g.TranslateTransform(-20, 180); 
    g.RotateTransform(270); 
    using (SolidBrush brush = new SolidBrush(ay.TitleForeColor)) 
     g.DrawString(ay.Title, ay.TitleFont, brush, 22, 22); 
} 

我用一些合適的值,在這裏很好,但你會想其他尺寸制定出新的!


但是:我不知道你是否應該放大圖這個樣子。相反,我相信你應該允許用戶zoom in和滾動放大圖表!

+0

隨着位置和InnerPlotPosition我失去了圖形。 MajorTickMark.Size幫助我(3)。 –

+0

明白了,看到我更新的答案! – TaW

相關問題