Relative vs. absolute time values on x-axis.

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
CKBN
Newbie
Newbie
Posts: 21
Joined: Mon Apr 11, 2011 12:00 am

Relative vs. absolute time values on x-axis.

Post by CKBN » Wed Jun 22, 2011 8:48 am

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
relTime.jpg
relTime.jpg (8.91 KiB) Viewed 6641 times
to
absTime.jpg
absTime.jpg (8.15 KiB) Viewed 6641 times
and vice versa, without having to change the x-values within the line serie?

Thanks in advance.

BR,
Christian

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Relative vs. absolute time values on x-axis.

Post by Sandra » Wed Jun 22, 2011 3:40 pm

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:

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);

        }
Could you tell us if previous code works as you expected?

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
Image Image Image Image Image Image
Instructions - How to post in this forum

CKBN
Newbie
Newbie
Posts: 21
Joined: Mon Apr 11, 2011 12:00 am

Re: Relative vs. absolute time values on x-axis.

Post by CKBN » Tue Jun 28, 2011 2:39 pm

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 :shock: :D

Anyway - if this is the only way to it, I guess that is that.

Again, thanks for your reply.

BR,
Christian

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Relative vs. absolute time values on x-axis.

Post by Sandra » Wed Jun 29, 2011 11:18 am

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:

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();
                }
            }
        }
Could you check if previous code works as you expected?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

CKBN
Newbie
Newbie
Posts: 21
Joined: Mon Apr 11, 2011 12:00 am

Re: Relative vs. absolute time values on x-axis.

Post by CKBN » Wed Jun 29, 2011 2:32 pm

Hi again Sandra,

This was exactly what I was hoping for.
Thanks a million!!!

BR
Christian

Post Reply