Page 1 of 1
GetAxisLabel is not working correctly with date time?
Posted: Wed May 18, 2005 3:33 am
by 8119968
Hello,
I have three problems with .NET- sorry it might be a long one. I really appreciate any helps or suggestions.
1- With GetAxisLabel event- it seem doesn't work with date/time on XAxis. For example my baseline date is 05-Jan-2005 04:00:00 and my series is plotting from 04-Jan-2005 00:00:00, 04-Jan-2005 01:00:00, etc to 06-Jan-2005 20:00:00 and I set the format of my bottom axes to
Code: Select all
ctrChart.Axes.Bottom.Labels.DateTimeFormat = "HH:mm:ss";
so that I hide all date from the bottom axis. What I want to do is to change color of the bottom axes to RED when it's smaller than the base line date 05-Jan-2005 04:00:00 and Blue when it's greater than. But it seems doesn't work because it's just compare the time but not date so any time <04:00:00 becomes RED and the rest are blue. This is not correct.
Code: Select all
private void ctrChart_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
{
DateTime xValue = Convert.ToDateTime(e.LabelText);
if (sender==ctrChart.Axes.Bottom)
{
if (xValue< datBaseLine)
((Axis)sender).Labels.Font.Color=Color.Red;
else
((Axis)sender).Labels.Font.Color=Color.Blue;
}
}
2- Another thing is that I want to plot a few series and each series on each custome X,Y axes. They must plot on the different Axes but on the same chart control at RUN TIME only. I worked it out but somehow it doesn't show XAxes for every series. It doesn show YAxis.
3- Could you please suggest how can we use TeeChart to chart with clear grid the same as perfermance chart in Windows Task manager. What I mean is that I want to build my chart the same it CPU Usage History line chart.
Many thanks
LG
Posted: Wed May 18, 2005 11:16 am
by narcis
Hello LG,
1.- This is a working example:
Code: Select all
private DateTime datBaseLine;
private void Form1_Load(object sender, System.EventArgs e)
{
tChart2.Axes.Bottom.Labels.DateTimeFormat = "HH:mm:ss";
Random randObj = new Random( 100 );
tChart2.Legend.Visible = false;
tChart2.Axes.Bottom.Labels.Angle = 90;
line2.Add(DateTime.Parse("01/08/2005 14:00:00"),randObj.Next(), DateTime.Parse("01/08/2005 14:00:00").ToString("dd/MM/yyyy HH:mm:ss"));
line2.Add(DateTime.Parse("01/08/2005 14:30:00"),randObj.Next(), DateTime.Parse("01/08/2005 14:30:00").ToString("dd/MM/yyyy HH:mm:ss"));
line2.Add(DateTime.Parse("01/08/2005 15:00:00"),randObj.Next(), DateTime.Parse("01/08/2005 15:00:00").ToString("dd/MM/yyyy HH:mm:ss"));
line2.Add(DateTime.Parse("01/08/2005 15:30:00"),randObj.Next(), DateTime.Parse("01/08/2005 15:30:00").ToString("dd/MM/yyyy HH:mm:ss"));
line2.Add(DateTime.Parse("01/08/2005 16:00:00"),randObj.Next(), DateTime.Parse("01/08/2005 16:00:00").ToString("dd/MM/yyyy HH:mm:ss"));
line2.Add(DateTime.Parse("01/08/2005 16:30:00"),randObj.Next(), DateTime.Parse("01/08/2005 16:30:00").ToString("dd/MM/yyyy HH:mm:ss"));
datBaseLine = Convert.ToDateTime("01/08/2005 15:00:00");
}
private void tChart2_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
{
if(e.ValueIndex != -1)
{
DateTime xValue = DateTime.Parse(e.LabelText);
e.LabelText = xValue.ToString("HH:mm:ss");
if (sender.Equals(tChart2.Axes.Bottom))
if (xValue< datBaseLine)
((Steema.TeeChart.Axis)sender).Labels.Font.Color=Color.Red;
else
((Steema.TeeChart.Axis)sender).Labels.Font.Color=Color.Blue;
}
}
2.- This may be that all series horizontal and vertical axes are not setted properly. You can do this at the chart editor, series tab and general tab. You can also have a look at
Tutorial 4 - Axis Control. Tutorials can be found at TeeChart program group.
3.- You could use PerformanceCounter component which is available from the
Components tab of the VS.NET ToolBox. Then you should be able to use this to extract the information you need and then add this information to tChart.
Posted: Wed May 18, 2005 12:06 pm
by 8119968
Dear Narcis,
Thanks. It works fine with your sample but if I add another line of code to it
Code: Select all
line2.Add(DateTime.Parse("30/07/2005 17:00:00"),randObj.Next(), DateTime.Parse("30/07/2005 17:00:00").ToString("dd/MM/yyyy HH:mm:ss"));
It it doesn't work correctly. Another problem in my acutal code, I add the teeChart control at run-time because I need many controls and I stick the event to each control but some how e.ValueIndex is always =-1 so it does nothing. Would you have any suggestion on this?
Regards,
LG
Posted: Wed May 18, 2005 1:01 pm
by narcis
Hi LG,
It works fine here, however as axes are authomatically set it may seem it is not working fine as the gap from this point to the others is big. Is that your case?
Regarding ValueIndex, could you please specify when this problem occurs or send an example project we can run "as-is" to reproduce the problem here?
You can post your projects at [url]news://
www.steema.net/steema.public.attachments[/url] newsgroup.
Posted: Thu May 19, 2005 5:23 am
by 8119968
Dear Narcis,
I already posted my sample codes and please have a look.
Regards,
LG
Posted: Thu May 19, 2005 7:17 am
by Marjan
Hi.
I think the problem is your bottom axis labels initially show only time part (HH:mm:ss) of datetime value and when you use DateTime.Parse method, only the time part is transformed (missing date part). To fix this problem you should initially set bottom axis datetime format to "dd-MM-yyyy HH:mm:ss" and then reformat it in GetAxisLabel event. Modified code:
Code: Select all
private void Chart_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
{
Steema.TeeChart.Axis axis = (Steema.TeeChart.Axis)sender;
if (sender==axis.Chart.Axes.Bottom)
{
// note - e.LabelText must initially hold complete datetime, not only time part!
System.DateTime datValue = System.DateTime.Parse(e.LabelText);
if (datValue< datBaseLine) axis.Labels.Font.Color=Color.Red;
else axis.Labels.Font.Color=Color.Blue;
e.LabelText = datValue.ToString("HH:mm:ss");
}
}
Also, I added the following:
Code: Select all
teeChart.Axes.Bottom.Labels.DateTimeFormat = "dd.MM.yyyy HH:mm:ss";
and removed the:
Code: Select all
tChart1.Axes.Bottom.Labels.DateTimeFormat = "HH:mm:ss";
tChart2.Axes.Bottom.Labels.DateTimeFormat = "HH:mm:ss";
I also posted modified units at attachment newsgroup.