Setting left and right side of bottom axis (Time Mode)

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
tirby
Newbie
Newbie
Posts: 84
Joined: Mon Mar 16, 2009 12:00 am

Setting left and right side of bottom axis (Time Mode)

Post by tirby » Tue Dec 04, 2012 4:48 pm

Hi,

I'm reading a time stamp string from a file in the form of hhmmss.

I want the bottom axis to display in the form of hh:mm:ss.
I believe I have set this part correctly with:

Code: Select all

tChart1.Axes.Bottom.Labels.DateTimeFormat = "hh:mm:ss";
The axis shows 12:00:00 at every vertical line which is at every 4th tic.
I need to set the left side with the start time from the file, and set the right side to start time + 60 minutes.
I need a tick mark every 1 minute, and a vertical line every 5 minutes.

Also how do I rotate the text on the bottom axis from horizontal to vertical?

Can someone help with these issues?

Thanks!

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

Re: Setting left and right side of bottom axis (Time Mode)

Post by Sandra » Wed Dec 05, 2012 12:52 pm

Hello triby,

I have made a simple code where I have tried to reproduce your request and I think you can use something similar as next to achieve as you want:

Code: Select all

 public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        Steema.TeeChart.Styles.Line Series1,Series2;
        DateTime data;
        Axis custombottom;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Dock = DockStyle.Fill;
            
            //Series
            data = DateTime.Now;
            Series1 = new Line(tChart1.Chart);
            Series2 = new Line(tChart1.Chart);
            Random rnd = new Random();
            Series1.XValues.DateTime = true;
            Series2.XValues.DateTime = true;
            for (int i = 0; i < 20; i++)
            {
                Series1.Add(data, rnd.Next(100));
                data = data.AddMinutes(1);
                data = data.AddMilliseconds(3);

            }
            Series2.DataSource = Series1;
            //CreateCustomAxis
            custombottom = new Axis(tChart1.Chart);
            tChart1.Axes.Custom.Add(custombottom);

            custombottom.Horizontal = true;
            custombottom.StartPosition = 50;
            custombottom.EndPosition = 100;
            custombottom.AxisPen.Color = Color.Red;
            Series2.CustomHorizAxis = custombottom;
            custombottom.Labels.DateTimeFormat = "mm:ss";
            custombottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(DateTimeSteps.OneMinute);
            custombottom.Labels.Angle = 90;
            
            //Bottom
            tChart1.Axes.Bottom.StartPosition = 0;
            tChart1.Axes.Bottom.EndPosition = 49;
            Series1.CustomHorizAxis = tChart1.Axes.Bottom;
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "mm:ss";
            tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(DateTimeSteps.OneMinute);
            tChart1.Axes.Bottom.Labels.Angle = 90;
            tChart1.AfterDraw += new PaintChartEventHandler(tChart1_AfterDraw);
        }

        void tChart1_MouseMove(object sender, MouseEventArgs e)
        {
            this.Text = e.X.ToString() + "," + e.Y.ToString();
        }

        void tChart1_AfterDraw(object sender, Graphics3D g)
        {
            Point p0, p1;
            Axis axisauxBottom, axisauxLeft; 
            axisauxBottom = tChart1.Axes.Bottom;
            axisauxLeft= tChart1.Axes.Left;
            for (int i = 0; i < Series1.Count; i++)
            {
                if (i % 5 == 0)
                {
                    p0 = new Point(axisauxBottom.CalcPosValue(Series1.XValues[i]), axisauxLeft.CalcPosValue(axisauxLeft.Minimum));
                    p1 = new Point(axisauxBottom.CalcPosValue(Series1.XValues[i]), axisauxLeft.CalcPosValue(axisauxLeft.Maximum));
                    g.Pen.Color = Color.Red;
                    g.Line(p0, p1);
                }     
            }
           
            for (int i = 0; i < Series2.Count; i++)
            {
                if (i % 5 == 0)
                {
                    p0 = new Point(custombottom.CalcPosValue(Series2.XValues[i]), axisauxLeft.CalcPosValue(axisauxLeft.Minimum));
                    p1 = new Point(custombottom.CalcPosValue(Series2.XValues[i]), axisauxLeft.CalcPosValue(axisauxLeft.Maximum));

                    g.Pen.Color = Color.Black;
                    g.Line(p0, p1);
                }
            }
        
        }
If you have any questions or problems, please let me know.

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

tirby
Newbie
Newbie
Posts: 84
Joined: Mon Mar 16, 2009 12:00 am

Re: Setting left and right side of bottom axis (Time Mode)

Post by tirby » Fri Dec 07, 2012 5:07 pm

Thanks Sandra,

I tried to run the code you posted but I'm getting this error:

Unable to resolve type 'Steema.TeeChart.TChart, TeeChart' C:\AxisTest\AxisTest\AxisTest\Properties\licenses.licx 1 AxisTest

Any ideas?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Setting left and right side of bottom axis (Time Mode)

Post by Narcís » Mon Dec 10, 2012 9:34 am

Hi tirby,

This problem probably indicates that your project is not referencing TeeChart.dll correctly or that the design-time license is not correctly compiled into the application. Please have a look at tutorial 17 for more information. Tutorials can be found at TeeChart's program group.
Best Regards,
Narcís Calvet / 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

tirby
Newbie
Newbie
Posts: 84
Joined: Mon Mar 16, 2009 12:00 am

Re: Setting left and right side of bottom axis (Time Mode)

Post by tirby » Mon Dec 10, 2012 5:01 pm

Thanks Narcís,

Turns out the issue is with your latest version of TChart (3.5.3700), it is not compatible with .Net Framework version 4.
I had to change my project to 3.5 to get rid of the error!

Hope this helps others whom may have experienced this issue.

Now, back to the original task of testing/trying the example posted here by Sandra!

Thanks again!

Post Reply