2013-01-10 113 views
0

C#的MSChart VS2010 .NET4如何在mschart中添加均勻分佈在XAxis上的點?

chart1.Series[0].Points.AddXY(0, 1); 
    chart1.Series[0].Points.AddXY(7, 1; 
    chart1.Series[0].Points.AddXY(8,1); 

我希望這3點是這樣的

.  . . 

但事實證明,這樣的

. . . 

爲什麼? 謝謝圖表

chartArea1.AxisX.InterlacedColor = System.Drawing.SystemColors.ControlLight; 
chartArea1.AxisX.Interval = 1D; 
chartArea1.AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount; 
chartArea1.AxisX.IntervalOffset = 1D; 
chartArea1.AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number; 
chartArea1.AxisX.IsInterlaced = true; 
chartArea1.AxisX.IsLabelAutoFit = false; 
chartArea1.AxisX.LabelStyle.Font = new System.Drawing.Font("Calibri", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.LightGray; 
chartArea1.AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.DashDotDot; 
chartArea1.AxisX.MajorTickMark.LineColor = System.Drawing.Color.Maroon; 
chartArea1.AxisX.ScrollBar.LineColor = System.Drawing.Color.White; 
chartArea1.AxisY.ArrowStyle = System.Windows.Forms.DataVisualization.Charting.AxisArrowStyle.SharpTriangle; 
chartArea1.AxisY.InterlacedColor = System.Drawing.Color.WhiteSmoke; 
chartArea1.AxisY.Interval = 1D; 
chartArea1.AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number; 
chartArea1.AxisY.IsInterlaced = true; 
chartArea1.AxisY.IsLabelAutoFit = false; 
chartArea1.AxisY.LabelStyle.Font = new System.Drawing.Font("Lucida Grande", 8F); 
chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.LightGray; 
chartArea1.AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.DashDot; 
chartArea1.AxisY.ScaleView.MinSizeType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number; 
chartArea1.CursorX.IsUserEnabled = true; 
chartArea1.CursorX.IsUserSelectionEnabled = true; 
chartArea1.CursorY.IsUserEnabled = true; 
chartArea1.CursorY.IsUserSelectionEnabled = true; 
chartArea1.Name = "ChartArea1"; 
this.chart1.ChartAreas.Add(chartArea1); 
this.chart1.Location = new System.Drawing.Point(-4, 0); 
this.chart1.Margin = new System.Windows.Forms.Padding(0); 
this.chart1.Name = "chart1"; 
series1.BorderWidth = 3; 
series1.ChartArea = "ChartArea1"; 
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point; 
series1.Font = new System.Drawing.Font("Calibri", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
series1.IsXValueIndexed = true; 
series1.LabelBorderWidth = 2; 
series1.MarkerColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); 
series1.Name = "Series1"; 
series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.UInt32; 
series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.UInt32; 
this.chart1.Series.Add(series1); 
this.chart1.Size = new System.Drawing.Size(1031, 618); 
this.chart1.TabIndex = 5; 
+0

你能告訴我們更多的代碼和圖表的截圖嗎? – digEmAll

+0

我很想去,但我不能上傳圖片,因爲我不允許。我可能在屬性窗口中觸摸了一些設置,但我不記得它們 – aihenry2980

+0

ChartType是哪一個系列?點? – digEmAll

回答

0

我猜你應該使用空數據點的

代碼(見http://msdn.microsoft.com/en-us/library/dd456677.aspx

使用IsEmpty屬性,這會導致下面的代碼。 (DataManipulator.InsertEmptyPoints應該需要更少的代碼,但我沒有測試它尚未)

chart1.Series[0].Points.Add(new DataPoint(0,1)); 
chart1.Series[0].Points.Add(new DataPoint(1,0){IsEmpty=true}); 
chart1.Series[0].Points.Add(new DataPoint(2,0){IsEmpty=true}); 
chart1.Series[0].Points.Add(new DataPoint(3,0){IsEmpty=true}); 
chart1.Series[0].Points.Add(new DataPoint(4,0){IsEmpty=true}); 
chart1.Series[0].Points.Add(new DataPoint(5,0){IsEmpty=true}); 
chart1.Series[0].Points.Add(new DataPoint(6,0){IsEmpty=true}); 
chart1.Series[0].Points.Add(new DataPoint(7,1)); 
chart1.Series[0].Points.Add(new DataPoint(8,1)); 
+0

似乎DataManipulator僅用於vs2012。由於性能問題,我無法添加這麼多點。 – aihenry2980

+1

@ aihenry2980 DataManipulator出現在.Net 4中(http://msdn.microsoft.com/zh-cn/library/system.web.ui.datavisualization.charting.datamanipulator%28v=vs.100%29.aspx)我不知道看不出爲什麼你不能在VS2010 thx中使用它作爲答案,IsXValueIndexed似乎足夠用一個系列。當使用多個系列時,空DataPoints似乎更好用 – jbl

+0

我以前從未嘗試過多個系列,我會稍後再試。 Thanx @jbl – aihenry2980

1

發現問題。

series1.IsXValueIndexed = true; 

這是發生的原因。 它應該是錯誤的。感謝大家的關注。