below a piece of code it keeps me in trouble:
private void ShowDatainChart()
{
Chart chart = this.chart1;
chart.Series.Clear();
int[] ser = { 1, 2, 3 };
foreach (int s in ser)
{
chart.Series.Add(s.ToString());
chart.Series[s - 1].XValueType = ChartValueType.Time;
chart.Series[s - 1].YValueType = ChartValueType.Time;
chart.Series[s - 1].ChartType = SeriesChartType.RangeBar;
}
string ser;
foreach (DataRow row in dt.Rows)
{
ser = row["BAT_QUEUE"].ToString();
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "MMM:dd HH:mm:ss";
chart.Series[ser].Points.AddXY(row["BATCH_NAME"],row["BEGIN"],row["END"]);
}
}
it takes data from datatable which contains for columns:
BAT_QUEUE string, BATCH_NAME string and two datetimes BEGIN and END. Generally three queues starts several batches every day and each of such batches takes a few seconds/minutes/hours.
The result I expect is something similar to "gantt chart" so it could gives me a tool to make some analyses.
As far as I searched the best choice for this task is RangeBar - unfortunately the type of chart used not so often.
The code above works perfect until I draw only one of three series ( doesn't metter which one). It draws several horizontal bars, one by one on different levels with different names. But when more series is choosen many bars is connected with wrong names.
It looks like the chart does not read seconds from BEGIN/END fields so if two batches from different queues starts at the same hour and minute but different second they are wrongly interpreted.
... it is pretty difficult to explain but I hope some of you understand what I mean and give me some hints what is wrong and how repair/solve my problem
thanks for any help in advance
ok, following Sinatr suggestions below the code which allows to show my problem. Right now, after a time spent on analyzes I see the problem is not with datetime format . It looks like a deeper one.
Every series starts from the same object created by the first series - and this in wrong. Anyway look at code . Of course it expects chart object created on windows form
private void ShowDatainChart()
{
DateTime a1 = new DateTime(2014, 07, 01, 00, 03, 00);
DateTime a2 = new DateTime(2014, 07, 01, 01, 17, 10);
DateTime b1 = new DateTime(2014, 07, 01, 00, 02, 33);
DateTime b2 = new DateTime(2014, 07, 01, 00, 44, 13);
DateTime a12 = new DateTime(2014, 07, 01, 01, 18, 00);
DateTime a22 = new DateTime(2014, 07, 01, 02, 22, 10);
chart1.Series.Clear();
string[] ser = { "1", "2" };
foreach (string s in ser)
{
chart1.Series.Add(s);
chart1.Series[s].ChartType = SeriesChartType.RangeBar;
chart1.Series[s].XValueType = ChartValueType.DateTime;
chart1.Series[s].YValueType = ChartValueType.DateTime;
}
chart1.Series["1"].Points.AddXY("A", a1, a2);
chart1.Series["1"].Points.AddXY("A1", a12, a22);
chart1.Series["2"].Points.AddXY("B", b1, b2);
}
Batches A and A1 from first series are displayed correct, but B from second series are displayed as A :(
See Question&Answers more detail:
os