Change the units of X-axis

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
asupriya
Advanced
Posts: 179
Joined: Mon Dec 01, 2008 12:00 am

Change the units of X-axis

Post by asupriya » Tue Aug 16, 2011 6:16 am

I have a sinusoidal wave form display. It can be displayed with Time (seconds) on X-axis or number of cycles of waveform. I can populate the series as per the user option at the time of loading the graph. However, if the user initially opts for x-axis in seconds, then once it is displayed, he wants to change to cycles, is there an easy way to switch the X-axis values without processing the whole series's X-values to generate cycles out of rate and frequency of the waveform?

How can I let user change the X-axis display units at runtime?
Also, if we want to update the X-axis values from seconds to minutes, is there an easier way to do?

Please suggest something.

Thanks

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

Re: Change the units of X-axis

Post by Sandra » Tue Aug 16, 2011 3:07 pm

Hello asupriya,
How can I let user change the X-axis display units at runtime?
To change units in runtime you only must change, the labels of Axis in GetAxesLabels event as do in next example of code:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        Steema.TeeChart.Styles.Line line1;
        Random rnd;
        DateTime  absolute;
        TimeSpan oneSecond;
         private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);

            //Absolute time.
            tChart1.Series.Clear();
            line1 = new Steema.TeeChart.Styles.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 oneFrenquency = Math.Round(1 / Math.Abs(absolute.ToOADate() - tmpLabelDate.ToOADate()), 4);
                    e.LabelText = oneFrenquency.ToString();
                }
            }
        }
Also, if we want to update the X-axis values from seconds to minutes, is there an easier way to do?
I think that next code, can help you update the X-axis values from seconds to minutes, so in it you get the absolute value of DateTime:

Code: Select all

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


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

Post Reply