C# 范围栏系列未居中

C# 范围栏系列未居中,c#,charts,series,microsoft-chart-controls,C#,Charts,Series,Microsoft Chart Controls,我正在使用c#表单应用程序中的范围条形图。当我将序列添加到图表中时,它们没有正确对齐。当我更改“DrawSideBySide=false”时,它工作得很好,但我需要一些系列并排 在此方面的任何帮助都将不胜感激 我的代码只是一个填充序列的列表,然后将这些序列添加到图表中 我循环浏览这个填充序列,并将它们添加到序列列表中。 填充- double yplot1 = (double)user.Projects[i].StartDate.ToOADate(); double yplot2 = (doub

我正在使用c#表单应用程序中的范围条形图。当我将序列添加到图表中时,它们没有正确对齐。当我更改“DrawSideBySide=false”时,它工作得很好,但我需要一些系列并排

在此方面的任何帮助都将不胜感激

我的代码只是一个填充序列的列表,然后将这些序列添加到图表中

我循环浏览这个填充序列,并将它们添加到序列列表中。 填充-

double yplot1 = (double)user.Projects[i].StartDate.ToOADate();
double yplot2 = (double)user.Projects[i].EndDate.ToOADate();
// Use a different series for each datapoint
Series seriesInstance = new Series();
//seriesInstance.Name = user.Name;
seriesInstance.Label = user.Projects[i].Name + " - " + (user.Projects[i].AllocationPercent * 100).ToString() + "%";
seriesInstance.AxisLabel = user.Name;

seriesInstance.ChartType = SeriesChartType.RangeBar;
// Have a start and end date so plotting 2 points on the y-axis
seriesInstance.YValuesPerPoint = 2;

//seriesInstance.CustomProperties = "DrawSideBySide=true";
//seriesInstance["PixelPointWidth"] = "200";
seriesInstance["MinPixelPointWidth"] = "150";

int xordinal = j;
seriesInstance.IsXValueIndexed = false;
seriesInstance.Points.AddXY(xordinal, yplot1, yplot2);
/*seriesInstance.Points[0].ToolTip = someTipText;
seriesInstance.Points[0].Color = resourceColor;
seriesInstance.Points[0].AxisLabel = xlabel;*/
seriesList.Add(seriesInstance);
然后我将列表中的所有系列添加到图表中

foreach (Series plotSeries in seriesList)
{
chart1.Series.Add(plotSeries);
}
// Force x-axis to show each task or resource

chart1.ChartAreas[0].AxisX.Interval = 1;

// Set y-axis to show each day of the month
chart1.ChartAreas[0].AxisY.Interval = 1;
ChartArea chartArea1 = chart1.ChartAreas[0];
chartArea1.AxisX.IsReversed = true;
// Set other y-axis properties
chartArea1.AxisX.ScrollBar.Enabled = true;
chartArea1.AxisX.IsLabelAutoFit = true;
chartArea1.AxisX.ScaleView.Size = 5;

chartArea1.AxisY.IsStartedFromZero = false;
chartArea1.AxisY.IsMarginVisible = false;
if ((lastDate - firstDate).TotalDays < 60)
{
chartArea1.AxisY.IntervalType = DateTimeIntervalType.Days;
}
else if (((lastDate - firstDate).TotalDays > 60) && ((lastDate - firstDate).TotalDays < 365))
{
chartArea1.AxisY.IntervalType = DateTimeIntervalType.Weeks;
}
else
{
chartArea1.AxisY.IntervalType = DateTimeIntervalType.Months;
}
// Set the y-axis labels
chart1.ChartAreas[0].AxisY.Minimum = firstDate.AddDays(-1).ToOADate();
chart1.ChartAreas[0].AxisY.Maximum = lastDate.AddDays(+1).ToOADate();
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "ddd M/d";
// Force redraw of chart
chart1.Update();
foreach(系列图系列列表中的系列)
{
图表1.系列。添加(绘图系列);
}
//强制x轴显示每个任务或资源
chart1.ChartAreas[0]。AxisX.Interval=1;
//设置y轴以显示每月的每一天
chart1.ChartAreas[0]。AxisY.Interval=1;
ChartArea ChartArea 1=chart1.ChartAreas[0];
chartArea1.AxisX.IsReversed=true;
//设置其他y轴特性
chartArea1.AxisX.ScrollBar.Enabled=true;
chartArea1.AxisX.IsLabelAutoFit=true;
chartArea1.AxisX.ScaleView.Size=5;
chartArea1.AxisY.IsStartedFromZero=false;
chartArea1.AxisY.IsMarginVisible=假;
如果((lastDate-firstDate).TotalDays<60)
{
chartArea1.AxisY.IntervalType=DateTimeIntervalType.Days;
}
否则,如果((lastDate-firstDate).TotalDays>60)和((lastDate-firstDate).TotalDays<365))
{
chartArea1.AxisY.IntervalType=DateTimeIntervalType.Weeks;
}
其他的
{
chartArea1.AxisY.IntervalType=DateTimeIntervalType.Months;
}
//设置y轴标签
chart1.ChartAreas[0].AxisY.Minimum=firstDate.AddDays(-1.ToOADate();
chart1.ChartAreas[0].AxisY.Maximum=lastDate.AddDays(+1.ToOADate();
chart1.ChartAreas[0].AxisY.LabelStyle.Format=“ddd M/d”;
//强制重画图表
图表1.Update();

发布一张显示错误的图片,代码初始化图表并用数据填充