2012-01-16 55 views
4

我有一個折線圖,其中包含一些如圖所示的值。我想X值是1 2 3等,但現在我有數據在系列和x我有0,77 1,77 2,77 3,77。我設置如何在圖表控件中設置X值的間隔

IsStartedFromZero = true; 
Interval = 1; 
Maximum = 4; 
Maximum = 4; 

在chartarea屬性

如何強制X值是1 2 3 4?

CODE:

Series s = new Series(); 
     s.Color = Color.Red; 
     s.ChartType = SeriesChartType.Line; 
     s.BorderWidth = 3; 

     s.Points.Add(new DataPoint(1.2, 0)); 
     s.Points.Add(new DataPoint(1.2,50)); 
     s.Points.Add(new DataPoint(2, 80)); 
     s.Points.Add(new DataPoint(3.2, 100)); 

     Series s1 = new Series(); 
     s1.Color = Color.Blue; 
     s1.ChartType = SeriesChartType.Line; 
     s1.BorderWidth = 2; 

     s1.Points.Add(new DataPoint(0.8,3.2)); 
     s1.Points.Add(new DataPoint(0.83,6.5)); 
     s1.Points.Add(new DataPoint(0.9,12.9)); 
     s1.Points.Add(new DataPoint(1,25.8)); 
     s1.Points.Add(new DataPoint(1.1,29)); 
     s1.Points.Add(new DataPoint(1.2,54.8)); 
     s1.Points.Add(new DataPoint(1.4,58.1)); 
     s1.Points.Add(new DataPoint(1.5,61.3)); 
     s1.Points.Add(new DataPoint(1.6,67.7)); 
     s1.Points.Add(new DataPoint(2,90.3)); 
     s1.Points.Add(new DataPoint(2.5,100)); 



     chart1.Series.Add(s); 
     chart1.Series.Add(s1); 

     chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.White; 
     chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.White; 
     chart1.ChartAreas[0].AxisX.Maximum = 4; 
     chart1.ChartAreas[0].AxisX.Interval = 1; 
     chart1.ChartAreas[0].AxisX.IsStartedFromZero = true; 
     chart1.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Number; 

chart

+1

我們需要更多的代碼,你的起始值是多少(在這種情況下看起來是0.77) 你的間隔和最大使用情況如何, – Moonlight 2012-01-16 15:38:53

回答

0

我倒覺得默認行爲是集合中的第X標籤包含您的數據系列中的最低值。在你的情況下,你的藍色系列的最低值似乎是〜0.8,低於1.

鑑於您指定的Interval爲1,而Maximum爲4有意義的是X標籤將大致爲0.77,1.77,2.77,3.77。

如果您在綁定圖表後強制顯示X標籤爲1,2,3,4,那麼您的標籤將不會正確對應您的數據,並且如果您將數據從1.0開始對齊,那麼您將從圖表中裁剪出一些系列數據。

取決於你想達到的目標,我只是堅持圖表吐出的默認值。

4

答案是設置:

  chart1.ChartAreas[0].AxisX.Minimum = 0; 

而這一切!

相關問題