Page 1 of 1
Change the units of X-axis
Posted: Tue Aug 16, 2011 6:16 am
by 13051032
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
Re: Change the units of X-axis
Posted: Tue Aug 16, 2011 3:07 pm
by 10050769
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,