Adjust Right Axes based on data

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Jeff
Newbie
Newbie
Posts: 3
Joined: Fri Nov 15, 2002 12:00 am

Adjust Right Axes based on data

Post by Jeff » Wed Sep 29, 2004 2:37 am

This is probably a much asked question but I was unable to find the answer I needed. My question is this:

I have a stock chart with 300 points. I programatically control how many items are viewable in the chart based on a horizontal scroll bar. However, the right axis is always scaled to the Y min/max of the candle series. How can I programatically change the high of the right axis to be the high of the visible data, and the low to be the low of the visible data.

I know I could calculate where i am in the data (ie points 40-60) and calculate the min and max by iterating through the points, but this would be too slow for a scroll bar type function. Is there anything available to have the right axis automatically adjust to the data visible in the graph?

If nothing is available in the .Net version, what about if I use the ActiveX?

Thanks

- jeff

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Wed Sep 29, 2004 7:11 am

Hi.

I'm sorry, there is no "automatic" way to solve this problem. You'll have to manually calculate visible points minimum and maximum and then set right axis scale according to these values. The following code should do the trick:

Code: Select all

    private void FindMinMax(ValueList v, int firstPoint, int lastPoint, out double min, out double max)
    {
      min = v.Value[firstPoint];
      max = v.Value[lastPoint];
      for (int t=firstPoint; t<=lastPoint; t++)
      {
        if (v.Value[t] < min) min = v.Value[t];
        else if (v.Value[t] > max) max = v.Value[t];
      }
    }

    private void AdjustAxisScale(Series s, int firstPoint, int lastPoint, bool vertical)
    {
      double min, max;
      if (vertical)
      {
        FindMinMax(s.YValues,firstPoint,lastPoint,out min, out max);
        s.GetVertAxis.Automatic = false;
        s.GetVertAxis.SetMinMax(min,max);
      }
      else
      {
        FindMinMax(s.XValues,firstPoint,lastPoint, out min, out max);
        s.GetHorizAxis.Automatic = false;
        s.GetHorizAxis.SetMinMax(min,max);
      }
    }

    private void button1_Click(object sender, System.EventArgs e)
    {
      tChart1.Page.Previous();
      if (checkBox1.Checked) AdjustAxisScale(candle1,candle1.FirstVisibleIndex,candle1.LastVisibleIndex,true);
      else candle1.GetVertAxis.Automatic = true;
    }

    private void button2_Click(object sender, System.EventArgs e)
    {
      tChart1.Page.Next();
      if (checkBox1.Checked) AdjustAxisScale(candle1,candle1.FirstVisibleIndex,candle1.LastVisibleIndex,true);
      else candle1.GetVertAxis.Automatic = true;
    }
This example will be included in next TeeChart .NET maintenance release.
Marjan Slatinek,
http://www.steema.com

Jeff
Newbie
Newbie
Posts: 3
Joined: Fri Nov 15, 2002 12:00 am

What about the activex control?

Post by Jeff » Wed Sep 29, 2004 2:01 pm

What if I use the activex control? Is it easier in that version since the .NET version does not seem quite as robust yet. I noticed something about a VisibleMax or MaxVisible property ???? Could I do it better in that control?

- jeff

Jeff
Newbie
Newbie
Posts: 3
Joined: Fri Nov 15, 2002 12:00 am

Still need an answer here

Post by Jeff » Fri Oct 01, 2004 10:23 pm

I still need to know the answer to this question:

What if I use the activex control? Is it easier in that version since the .NET version does not seem quite as robust yet. I noticed something about a VisibleMax or MaxVisible property ???? Could I do it better in that control?

- jeff

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Re: What about the activex control?

Post by Marjan » Mon Oct 04, 2004 3:31 pm

6926932 wrote:What if I use the activex control? Is it easier in that version since the .NET version does not seem quite as robust yet. I noticed something about a VisibleMax or MaxVisible property ???? Could -
jeff
Hmm... I think in the end you'll still have to use the same approach and manually calculate visible points minimum and maximum value and then adnjust vertical axis scale according to these two limits (use the same approach, but slightly different code).
Marjan Slatinek,
http://www.steema.com

glikoz
Newbie
Newbie
Posts: 34
Joined: Mon May 05, 2003 4:00 am

Is there any improvement about this subject?

Post by glikoz » Tue Feb 28, 2006 8:15 am

my chart has custom vertical axes and many series (related with custom axes)
I try to adjust minimum and maximum values for every Custom Vertical Axis.But each vertical custom axis has got own series (series,function more than one )..
Its very hard to adjust all series,functions related custom vertical axes(Because for example ;Moving Average begins after n day from base series )
So are automatic minimum and automatic maximum abilities ready?
And whats your suggestion about this situation (mine)
Thx..

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

Post by Narcís » Tue Feb 28, 2006 9:51 am

Hi glikoz,

Yes, custom axes work automatically and that's the approach I would use. Please notice that Marjan's reply is from October 2004. Since then, a lot of things have been done in TeeChart for .NET and in June 2005 TeeChart for .NET v2 was released.
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

glikoz
Newbie
Newbie
Posts: 34
Joined: Mon May 05, 2003 4:00 am

Post by glikoz » Tue Feb 28, 2006 11:50 am

Please open
Welcome !\Functions\Financial\CCI (Commodity Channel Index)
Then zoom in ...
Altough,

Code: Select all

tChart1.Axes.Custom[0].Automatic=true 
Its behaviour is different ...Always about 200 is maximum value of tChart1.Axes.Custom[0] 's ...
I have same problem as i show..
is it not enough to set axis's automatic property to true ?

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

Post by Narcís » Tue Feb 28, 2006 1:09 pm

Hi glikoz,

Ok, custom axes don't zoom automatically you need to implement it as told here. This is a Delphi example but you shouldn't have any problem porting it to C#.
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

glikoz
Newbie
Newbie
Posts: 34
Joined: Mon May 05, 2003 4:00 am

Post by glikoz » Tue Feb 28, 2006 5:18 pm

in my application ...

Code: Select all

this.Zoom.Direction = ZoomDirections.Horizontal;
Its about "scaling" to Datas....
If user zooms between two dates i draw custom axis for CCI graphic between CCImax(at this interval)- CCImin(at this interval) values apart from where zoom begin (vertically) ...

Could i explain ? If we look history

I have a stock chart with 300 points. I programatically control how many items are viewable in the chart based on a horizontal scroll bar. However, the right axis is always scaled to the Y min/max of the candle series. How can I programatically change the high of the right axis to be the high of the visible data, and the low to be the low of the visible data.

I know I could calculate where i am in the data (ie points 40-60) and calculate the min and max by iterating through the points, but this would be too slow for a scroll bar type function. Is there anything available to have the right axis automatically adjust to the data visible in the graph?
I have a candle and three functions ; some functions start at 8. day (i couldnt easily calculate max,min values for verticalaxis)
I hope i could explain ...
Thx.

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

Post by Narcís » Wed Mar 01, 2006 10:55 am

Hi glikoz,

If the automatic scaling is not what youe wants then you'll have to do something similar to what Marjan suggested on his first reply. Also, don't forget that, as I told in my previous post, code has to be implemented to get custom axes to zoom.

If that's not clear enough or that's not what are you really looking for, could you please send us an example we can run "as-is" to reproduce the problem here?

You can post your files at news://www.steema.net/steema.public.attachments newsgroup.
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

glikoz
Newbie
Newbie
Posts: 34
Joined: Mon May 05, 2003 4:00 am

I couldnt implement

Post by glikoz » Mon Mar 06, 2006 8:23 am

Maybe picture could tell us everything ...
Image

We have one main series(candle) and two functions (related with main series)..One of the function is Our Custom Volume Function the other is Custom Moving Average (of Volume Function)..Because of the nature of Moving Average , it doesnt start from starting point of Chart (period)..
So i couldnt use these variables(startIndex,endIndex) for MovingAverage:

Code: Select all

 void RChart_Zoomed(object sender, EventArgs e)
        {
            int startIndex = Convert.ToInt32(this.Axes.Bottom.CalcPosPoint(this.Zoom.x0));
            int endIndex = Convert.ToInt32(this.Axes.Bottom.CalcPosPoint(this.Zoom.x1));
}
These values are usable for Candle series(Main series) and Volume series ,but not for Moving Average...I couldnt access starting and ending point of MovingAverage ...
This code is useless too :

Code: Select all

 void RChart_Zoomed(object sender, EventArgs e)
        {
//Application.DoEvents();
int a=MovingAverage.CustomPoint.FirstVisibleIndex;
}
I will calculate Maximum and minimum values for every CustomVerticalAxis by means of related Series(Functions')

Thx for best aids..

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

Post by Narcís » Mon Mar 06, 2006 11:23 am

Hi glikoz,

Sorry but I still don't understand what are you exactly trying to achieve. Could you please extend on that or modify the image you posted drawing what would you like to get?

Thanks in advance.
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

glikoz
Newbie
Newbie
Posts: 34
Joined: Mon May 05, 2003 4:00 am

Post by glikoz » Mon Mar 06, 2006 12:59 pm

I try to make "Adjust Scaling " same as in this topic, but it is more complex because of Many Functions :)
For our sample graph ;
For sample zoom;

First Custom Vertical Axis's maximum must be equal about 43000
Firts Custom Vertical Axis's minimum must be equal 0

15.1.1998 is first value of 2nd Function (Moving Average)
I have to collect
12,13,14,15,16,19,20 th values of Volume and
15,16,19,20 th values of Moving Average
and calculate min and max values fromthis collection ...
I can access Volume Values by help of MouseClick :

Code: Select all

 
private void RChart_Zoomed(object sender, EventArgs e)
        {
            int startIndex = Convert.ToInt32(this.Axes.Bottom.CalcPosPoint(this.Zoom.x0));
            int endIndex = Convert.ToInt32(this.Axes.Bottom.CalcPosPoint(this.Zoom.x1));
int MaxVolume=0;
           for (int i=startIndex;i<=endIndex;i++){
if (VolumeFunction.CustomPoint[0].Y>MaxVolume)
  MaxValue=VolumeFunction.CustomPoint[0].Y;
}
 
}
            
But i couldnt use same approach for MovingAverage BECAUSE :

MovingAverageFunction.CustomPoint[0].X not equal VolumeFunction.CustomPoint[0].X

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

Post by Narcís » Mon Mar 06, 2006 3:45 pm

Hi glikoz,

It works fine for me here using:

Code: Select all

		private void Form1_Load(object sender, System.EventArgs e)
		{
			this.candle1.FillSampleValues();
			this.volume1.FillSampleValues();			
		}

		private void tChart1_Zoomed(object sender, System.EventArgs e)
		{
			axis1.SetMinMax(Math.Min(volume1.GetVertAxis.CalcPosPoint(tChart1.Zoom.y1),line1.GetVertAxis.CalcPosPoint(tChart1.Zoom.y1)),
							Math.Max(volume1.GetVertAxis.CalcPosPoint(tChart1.Zoom.y0),line1.GetVertAxis.CalcPosPoint(tChart1.Zoom.y0)));
			
		}

		private void tChart1_UndoneZoom(object sender, System.EventArgs e)
		{
			axis1.Automatic=true;
		}
Where line1 is the moving average function series.
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

Post Reply