0

c# mschart vs2010 .net4

    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;
4

2 回答 2

1

Found the problem.

 series1.IsXValueIndexed = true;

this is the reason that happened. it should be false. thanx for everyone's attention.

于 2013-01-10T09:25:55.720 回答
0

我猜你应该使用空的 DataPoints,(见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));
于 2013-01-10T08:55:20.587 回答