Page 1 of 1

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

Posted: Tue Dec 04, 2012 4:48 pm
by 13052810
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!

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

Posted: Wed Dec 05, 2012 12:52 pm
by 10050769
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,

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

Posted: Fri Dec 07, 2012 5:07 pm
by 13052810
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?

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

Posted: Mon Dec 10, 2012 9:34 am
by narcis
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.

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

Posted: Mon Dec 10, 2012 5:01 pm
by 13052810
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!