更新:从我所看到的,这与日期本身没什么关系。这只是一个在图表上有一个长条形图的情况,当它聚焦在它的一小段(日期/时间,短值范围等)时,它会停止对条形图进行着色。除了对它视而不见之外,仍然不知道为什么或如何解决它。
我一直试图解决涉及堆积图表和日期限制的奇怪小错误。假设您将Y轴设置为日期,X轴是项目,您使用条形图作为项目完成,项目截止日期和项目逾期。
现在,如果您将Y轴上显示的最小和最大日期设置为相隔几天,在预计将持续数月的项目中,您将看到问题。酒吧失去了它的颜色,但如果你增加最小值和最大值之间的差距,那么问题就会消失。
以下是所涉及代码的信息:
private void _Gantt_Load(object sender, EventArgs e)
{
chart1.MouseUp += new MouseEventHandler(MouseHandler);
_dtpGraphStart.ValueChanged += new EventHandler(DateTimeHandler);
_dtpGraphEnd.ValueChanged += new EventHandler(DateTimeHandler);
string pOneName = "Project 1";
string pTwoName = "Project 2";
DateTime pOneStart = new DateTime(2011, 01, 01, 0, 0, 0);
DateTime pTwoStart = new DateTime(2011, 02, 01, 12, 0, 0);
DateTime pOneEnd = new DateTime(2011, 01, 01, 15, 0, 0);
DateTime pTwoEnd = new DateTime(2011, 07, 01, 7, 0, 0);
double pOneTotal = (pOneEnd - pOneStart).TotalDays;
double pTwoTotal = (pTwoEnd - pTwoStart).TotalDays;
double pOnePercent = 75;
double pTwoPercent = 50;
double pOneComplete = (pOnePercent / 100.0f) * pOneTotal;
double pTwoComplete = (pTwoPercent / 100.0f) * pTwoTotal;
chart1.Series["StartSeries"].Points.AddXY(pOneName, pOneStart);
chart1.Series["StartSeries"].Points.AddXY(pTwoName, pTwoStart);
chart1.Series["ProjectDurationSeries"].Points.AddXY(pOneName, pOneComplete);
chart1.Series["ProjectDurationSeries"].Points.AddXY(pTwoName, pTwoComplete);
chart1.Series["ProjectDurationSeries"].Points[0].Tag = "TestOne";
chart1.Series["ProjectDurationSeries"].Points[1].Tag = "TestTwo";
chart1.Series["ProjectRemainingSeries"].Points.AddXY(pOneName, pOneTotal - pOneComplete);
chart1.Series["ProjectRemainingSeries"].Points.AddXY(pTwoName, pTwoTotal - pTwoComplete);
chart1.Series["ProjectRemainingSeries"].Points[0].Tag = "TestCompleteOne";
chart1.Series["ProjectRemainingSeries"].Points[1].Tag = "TestCompleteTwo";
chart1.ChartAreas[0].AxisY.Minimum = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 0, 0, 0).ToOADate();
chart1.ChartAreas[0].AxisY.Maximum = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 23, 59, 59).ToOADate();
chart1.DataBind();
_dtpGraphEnd.MinDate = _dtpGraphStart.Value;
_dtpGraphStart.MaxDate = _dtpGraphEnd.Value;
}
private void DateTimeHandler(object sender, EventArgs e)
{
DateTimePicker dtp = (DateTimePicker)sender;
switch (dtp.Name)
{
case "_dtpGraphStart":
chart1.ChartAreas[0].AxisY.Minimum = new DateTime(dtp.Value.Year, dtp.Value.Month, dtp.Value.Day, 0, 0, 0).ToOADate();
_dtpGraphEnd.MinDate = dtp.Value;
break;
case "_dtpGraphEnd":
chart1.ChartAreas[0].AxisY.Maximum = new DateTime(dtp.Value.Year, dtp.Value.Month, dtp.Value.Day, 23, 59, 59).ToOADate();
_dtpGraphStart.MaxDate = dtp.Value;
break;
}
if ((chart1.ChartAreas[0].AxisY.Maximum - chart1.ChartAreas[0].AxisY.Minimum) < 3)
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "T";
if (((chart1.ChartAreas[0].AxisY.Maximum - chart1.ChartAreas[0].AxisY.Minimum) > 3)
&& ((chart1.ChartAreas[0].AxisY.Maximum - chart1.ChartAreas[0].AxisY.Minimum) < 30))
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "dd/MM";
if ((chart1.ChartAreas[0].AxisY.Maximum - chart1.ChartAreas[0].AxisY.Minimum) > 30)
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "MM/yyyy";
}
以上项目涵盖2011年1月1日00:00:00至01/01/2011 15:00:00,以及01/02/2011 12:00:00至01/07/2011 07: 00:00。
最初的日期限制是在今天的日期,没有特别的原因。
显示问题的图像。没有其他代码与此图表显示的内容有任何关系,除了较小的属性更改,但为了彻底,我将在设计器文件中添加以下内容。
chartArea1.AxisX.MajorGrid.Enabled = false;
chartArea1.AxisY.InterlacedColor = System.Drawing.Color.Lime;
chartArea1.AxisY.LabelStyle.Format = "T";
chartArea1.AxisY.MajorGrid.Enabled = false;
chartArea1.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea1);
this.chart1.Location = new System.Drawing.Point(0, 0);
this.chart1.Name = "chart1";
series1.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar;
series1.Color = System.Drawing.Color.White;
series1.Name = "StartSeries";
series2.BorderColor = System.Drawing.Color.Black;
series2.BorderWidth = 2;
series2.ChartArea = "ChartArea1";
series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar;
series2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
series2.EmptyPointStyle.Color = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
series2.Name = "ProjectDurationSeries";
series3.BackHatchStyle = System.Windows.Forms.DataVisualization.Charting.ChartHatchStyle.ForwardDiagonal;
series3.BackSecondaryColor = System.Drawing.Color.White;
series3.BorderColor = System.Drawing.Color.Black;
series3.BorderWidth = 2;
series3.ChartArea = "ChartArea1";
series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar;
series3.Color = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
series3.Name = "ProjectRemainingSeries";
series4.BackHatchStyle = System.Windows.Forms.DataVisualization.Charting.ChartHatchStyle.ForwardDiagonal;
series4.BorderColor = System.Drawing.Color.Black;
series4.BorderWidth = 2;
series4.ChartArea = "ChartArea1";
series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar;
series4.Color = System.Drawing.Color.Red;
series4.Name = "Series4";
this.chart1.Series.Add(series1);
this.chart1.Series.Add(series2);
this.chart1.Series.Add(series3);
this.chart1.Series.Add(series4);
this.chart1.Size = new System.Drawing.Size(727, 339);
this.chart1.TabIndex = 0;
this.chart1.Text = "chart1";
答案 0 :(得分:-1)
chartArea1.AxisX.MajorGrid.Enabled = false;
chartArea1.AxisY.InterlacedColor = System.Drawing.Color.Lime;
chartArea1.AxisY.LabelStyle.Format = "T";
chartArea1.AxisY.MajorGrid.Enabled = false;
chartArea1.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea1);
this.chart1.Location = new System.Drawing.Point(0, 0);
this.chart1.Name = "chart1";
series1.ChartArea = "ChartArea1";
series1.ChartType =
System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar;
series1.Color = System.Drawing.Color.White;
series1.Name = "StartSeries";
series2.BorderColor = System.Drawing.Color.Black;
series2.BorderWidth = 2;
series2.ChartArea = "ChartArea1";
series2.ChartType =
System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar;
series2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)
(192)))), ((int)(((byte)(0)))));
series2.EmptyPointStyle.Color = System.Drawing.Color.FromArgb(((int)(((byte)(0)))),
((int)(((byte)(192)))), ((int)(((byte)(0)))));
series2.Name = "ProjectDurationSeries";
series3.BackHatchStyle =
System.Windows.Forms.DataVisualization.Charting.ChartHatchStyle.ForwardDiagonal;
series3.BackSecondaryColor = System.Drawing.Color.White;
series3.BorderColor = System.Drawing.Color.Black;
series3.BorderWidth = 2;
series3.ChartArea = "ChartArea1";
series3.ChartType =
System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar;
series3.Color = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)
(((byte)(128)))), ((int)(((byte)(255)))));
series3.Name = "ProjectRemainingSeries";
series4.BackHatchStyle =
System.Windows.Forms.DataVisualization.Charting.ChartHatchStyle.ForwardDiagonal;
series4.BorderColor = System.Drawing.Color.Black;
series4.BorderWidth = 2;
series4.ChartArea = "ChartArea1";
series4.ChartType =
System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar;
series4.Color = System.Drawing.Color.Red;
series4.Name = "Series4";
this.chart1.Series.Add(series1);
this.chart1.Series.Add(series2);
this.chart1.Series.Add(series3);
this.chart1.Series.Add(series4);
this.chart1.Size = new System.Drawing.Size(727, 339);
this.chart1.TabIndex = 0;
this.chart1.Text = "chart1";