【发布时间】:2015-08-12 04:49:47
【问题描述】:
我正在尝试使用 C# .NET 中的 Chart 控件绘制一组代理任务的范围列图。我在 x 轴上绘制代理编号,在 y 轴上绘制任务时间。我唯一的问题是列数据不会与 x 轴上的代理编号正确对齐。有谁知道如何将列与相应的 x 轴标签对齐?
这是我的图表的图像:
这是我的代码:
chartSchedule.Titles.Add("Agent / Task Schedule");
chartSchedule.ChartAreas[0].AxisX.Title = "Agent";
chartSchedule.ChartAreas[0].AxisY.Title = "Time";
int index = 0;
foreach ( Agent a in _agents )
{
// Create a series for each agent and set up display details
Series agentSeries = chartSchedule.Series.Add("Agent " + a.Id);
agentSeries.ChartType = SeriesChartType.RangeColumn;
// Alternate colours of series lines
if ( index % 2 > 0 )
agentSeries.Color = Color.DodgerBlue;
else
agentSeries.Color = Color.Blue;
// Display start and end columns of every task
List<DataPoint> timeData = new List<DataPoint>();
foreach ( NodeTask t in a.AssignedTasks )
{
agentSeries.Points.AddXY(index + 1, t.StartTime, t.EndTime);
}
index++;
}
【问题讨论】:
-
谢谢。我编辑了帖子以包含指向我的图形图像的链接
-
这太棒了!我试过了,它完全符合我的要求。我只需要更改 Legends[0].CustomItems 行,它是 chartSchedule 而非 agentSeries 的属性。非常感谢您的帮助。
标签: c# charts alignment series