Page 1 of 1
Setting the range for y-axis
Posted: Tue Jan 24, 2006 6:41 pm
by 9637357
I have a teechart with datetime on x-axis and Price on y-axis.
x and y axes are set automatically depending on the data to the chart.
Now, my question is what if I want my y-axis to have a much wider range of values, i.e for ex if the range of value to the y-axis varies from 10 to 20 then I want the y-axis value to vary from 0 to 30.
Is there a way to set the y-axis range? Please let me know
Thanks.
Posted: Wed Jan 25, 2006 8:55 am
by narcis
Hi TeeUser,
Yes, this is possible using axis
SetMinMax method or
Minimum and
Maximum properties:
Code: Select all
tChart1.Axes.Left.SetMinMax(0,30);
or
Code: Select all
tChart1.Axes.Left.Minimum=0;
tChart1.Axes.Left.Maximum=30;
Posted: Wed Jan 25, 2006 3:18 pm
by 9637357
Hi,
Thanks a lot for the reply.
The data for my teechart is dynamic, meaning I cannot hard code the min and max value. Dpending on the data from the database max value has to be (max val from the database+ 10) and the min val has to be (min val from the database-10).
Is there a way to set it dynamically.
Thanks.
Posted: Wed Jan 25, 2006 3:41 pm
by narcis
Hi TeeUser,
Yes, you can do something like the code below every time you add values to your series:
Code: Select all
private void LeftAxisUpdate()
{
tChart1.Axes.Left.Automatic = false;
tChart1.Axes.Left.Minimum=tChart1[0].YValues.Minimum-10;
tChart1.Axes.Left.Maximum=tChart1[0].YValues.Maximum+10;
}
private void Form1_Load(object sender, System.EventArgs e)
{
line1.FillSampleValues();
LeftAxisUpdate();
}
Another option is using axis MinimumOffset and MaximumOffset:
Code: Select all
private void Form1_Load(object sender, System.EventArgs e)
{
line1.FillSampleValues();
tChart1.Axes.Left.MinimumOffset=10;
tChart1.Axes.Left.MaximumOffset=10;
}
Please the unit for the offset units are pixels.
Posted: Wed Jan 25, 2006 7:38 pm
by 9637357
That helped a lot, Thanks.
I just have one other question, What if I want to keep the date time in x-axis between 9.00am and 4.00pm constant.
Thanks.
Posted: Thu Jan 26, 2006 11:58 am
by narcis
Hi TeeUser,
Yes, you can use something like:
Code: Select all
tChart1.Axes.Bottom.Labels.DateTimeFormat = "hh:mm";
tChart1.Axes.Bottom.SetMinMax(new DateTime(2006,1,23,9,00,00).ToOADate(),
new DateTime(2006,1,23,16,00,00).ToOADate());
Please notice that a date is necessary and you'll have to consider that.