Hi there,
I hope you can help me.
Our x-axis is always a DateTime axis. However, we would like to be able to switch between relative and absolute time, eg. switching from
to
and vice versa, without having to change the x-values within the line serie?
Thanks in advance.
BR,
Christian
Relative vs. absolute time values on x-axis.
Re: Relative vs. absolute time values on x-axis.
Hello Christian,
I have made a simple code that works with absolute and relative values. The absolute value is the DateTime of now and relative value is the subtract of absolute, DateTime now, and OldTime, DateTime there is when you initialize Chart:
Could you tell us if previous code works as you expected?
I hope will helps.
Thanks,
I have made a simple code that works with absolute and relative values. The absolute value is the DateTime of now and relative value is the subtract of absolute, DateTime now, and OldTime, DateTime there is when you initialize Chart:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
Steema.TeeChart.Styles.Line line1;
Random rnd;
DateTime oldTime,relative;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
line1 = new Line(tChart1.Chart);
oldTime = DateTime.Now;//Time to initializeChart.
relative = new DateTime();
}
private void button1_Click(object sender, EventArgs e)
{
//Absolut time.
tChart1.Series.Clear();
line1 = new Line(tChart1.Chart);
line1.XValues.DateTime=true;
line1.DateTimeFormat = "HH:mm:ss";
TimeSpan oneSecond = TimeSpan.FromSeconds(10);
DateTime absolut = DateTime.Now;
rnd = new Random();
for(int i = 1; i <= 15; ++i)
{
line1.Add(absolut, rnd.Next(100), Color.Red);
absolut += oneSecond;
}
tChart1.Axes.Bottom.Labels.DateTimeFormat = "HH:mm:ss";
tChart1.Axes.Bottom.Labels.Angle = 90;
tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.FiveSeconds);
}
private void button2_Click(object sender, EventArgs e)
{
//relative value.
tChart1.Series.Clear();
line1 = new Line(tChart1.Chart);
line1.XValues.DateTime=true;
line1.DateTimeFormat = "HH:mm:ss";
rnd = new Random();
for(int i = 1; i <= 15; ++i)
{
DateTime absolut = DateTime.Now;
TimeSpan oneSecond = absolut.Subtract(oldTime);
relative += oneSecond;
line1.Add(relative, rnd.Next(100), Color.Red);
}
tChart1.Axes.Bottom.Labels.DateTimeFormat = "HH:mm:ss";
tChart1.Axes.Bottom.Labels.Angle = 90;
tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TenSeconds);
}
I hope will helps.
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Relative vs. absolute time values on x-axis.
Hi Sandra,
Thanks for your reply. You example works as stated.
I was just hoping that there was some way to subtract a constant value from the shown values on an axis, if you get my meaning. In your example, I would have to clear the entire chart, and redraw everything, including color lines, annotations, draw lines ect., and of course all the series. We got up to 200 series, each with up to 60.000 points. As you can imagine, it would take some time to redraw everything
Anyway - if this is the only way to it, I guess that is that.
Again, thanks for your reply.
BR,
Christian
Thanks for your reply. You example works as stated.
I was just hoping that there was some way to subtract a constant value from the shown values on an axis, if you get my meaning. In your example, I would have to clear the entire chart, and redraw everything, including color lines, annotations, draw lines ect., and of course all the series. We got up to 200 series, each with up to 60.000 points. As you can imagine, it would take some time to redraw everything
Anyway - if this is the only way to it, I guess that is that.
Again, thanks for your reply.
BR,
Christian
Re: Relative vs. absolute time values on x-axis.
Hello Christian,
I have made a simple code that change absolute DateTime to relative DateTime, using a checkbox and GetAxisLabel method and I you can do something as next:
Could you check if previous code works as you expected?
Thanks,
I have made a simple code that change absolute DateTime to relative DateTime, using a checkbox and GetAxisLabel method and I you can do something as next:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
Steema.TeeChart.Styles.Line line1;
Random rnd;
DateTime oldTime, relative, absolute;
TimeSpan oneSecond;
String tmpLabel;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
line1 = new Line(tChart1.Chart);
//Absolute time.
tChart1.Series.Clear();
line1 = new Line(tChart1.Chart);
line1.XValues.DateTime = true;
line1.DateTimeFormat = "HH:mm:ss";
oneSecond = TimeSpan.FromSeconds(10);
absolute = DateTime.Now;
rnd = new Random();
for (int i = 1; i <= 15; ++i)
{
line1.Add(absolute, rnd.Next(100), Color.Red);
absolute += oneSecond;
}
checkBox1.Checked = true;
tChart1.Axes.Bottom.Labels.DateTimeFormat = "HH:mm:ss";
tChart1.Axes.Bottom.Labels.Angle = 90;
tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.FiveSeconds);
tChart1.GetAxisLabel += new Steema.TeeChart.GetAxisLabelEventHandler(tChart1_GetAxisLabel);
checkBox1.CheckedChanged += new EventHandler(checkBox1_CheckedChanged);
}
void checkBox1_CheckedChanged(object sender, EventArgs e)
{
tChart1.Refresh();
}
void tChart1_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
{
if (sender == tChart1.Axes.Bottom)
{
if (!checkBox1.Checked)
{
//Convert string to Correct DateTime.
DateTime tmpLabelDate = DateTime.Parse(e.LabelText);
//Calculate difference to absolute value and labelValue.
Double oneSecondValue = Math.Abs(absolute.ToOADate() - tmpLabelDate.ToOADate());
//ConvertDouble result to DateTime.
relative = DateTime.FromOADate(oneSecondValue);
e.LabelText = relative.ToLongTimeString();
}
}
}
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Relative vs. absolute time values on x-axis.
Hi again Sandra,
This was exactly what I was hoping for.
Thanks a million!!!
BR
Christian
This was exactly what I was hoping for.
Thanks a million!!!
BR
Christian