Page 1 of 1

TeeCHart Newbie Q1 of 1022 Zooming and Scrolling

Posted: Fri Jul 02, 2010 5:30 am
by 8751509
Greetings.

I am trying to implement a scrollbar to use with Teechart.
How does one keep track of "how zoomed in" a chart is ...
you can zoom a chart in by a given percent(.ZoomPercent Method)
But there is no read value that I can see ...

Please point me in the right direction ... do I use a property of the axis ? which I would assume I'd store intial value and compare to the axis value after a zoom and ' then 'do the math'

Is there a property that will tell me the size of the chart area unzoomed and another that will tell me the size of the 'zoomed window' with which I can calculate a percentage zoom ?

Or is there a better way ???

Re: TeeCHart Newbie Q1 of 1022 Zooming and Scrolling

Posted: Fri Jul 02, 2010 11:29 am
by 10050769
Hello Snarkle,

I have proposed a simple solution that calculates the ZoomPercent of Chart Zoom, using values of Axes and Zoomed and Unzoomed Events. Could you please check next code works as you want?

Code: Select all

  public Form1()
        {

            InitializeComponent();

            InitializeChart();

        }

        private double XRange0;

        private double YRange0;



        private double GetAxisRange(Steema.TeeChart.Axis axis)
        {

            return axis.Maximum - axis.Minimum;

        }



        private void DisplayZoomPercentage(double x, double y)
        {

            tChart1.Header.Text = "Horizontal zoom: " + x.ToString("0.##") + ",Vertical zoom: " + y.ToString("0.##");

        }



        private void InitializeChart()
        {

            Steema.TeeChart.Styles.Line line1 = new
      Steema.TeeChart.Styles.Line(tChart1.Chart);

            line1.FillSampleValues();



            tChart1.Draw();



            XRange0 = GetAxisRange(tChart1.Axes.Bottom);

            YRange0 = GetAxisRange(tChart1.Axes.Left);



            tChart1.Zoomed += new EventHandler(tChart1_Zoomed);

            tChart1.UndoneZoom += new EventHandler(tChart1_UndoneZoom);

        }



        void tChart1_UndoneZoom(object sender, EventArgs e)
        {

            DisplayZoomPercentage(0, 0);

        }



        void tChart1_Zoomed(object sender, EventArgs e)
        {

            double XRange1 = GetAxisRange(tChart1.Axes.Bottom);

            double YRange1 = GetAxisRange(tChart1.Axes.Left);



            double XZoom = 100 - ((XRange1 / XRange0) * 100);

            double YZoom = 100 - ((YRange1 / YRange0) * 100);



            DisplayZoomPercentage(XZoom, YZoom);

        }
I hope will helps.

Thanks,

Re: TeeCHart Newbie Q1 of 1022 Zooming and Scrolling

Posted: Mon Jul 05, 2010 4:55 am
by 8751509
Thanks Sandra ... that code snippet has pointed me in the right direction ...
However I have another question regarding the code snippet.

Currently the only way I can find to get the intial value for XRange0 is from the event

Code: Select all


 private bool doneOnce = false;
 private double XRangeMax = 0;
       
 private void StockChart_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            XRange0 = GetAxisRange(StockChart.Axes.Bottom);
            
            if (XRange0 != 0 && doneOnce == false)
            {
                /// I need the second value from this event.
                XRangeMax = XRange0;
                doneOnce = true;
            }
        }
The first time this event fires I get a zero, soon after the event fires again and I get the value that I require and I can store.
I am nervous about this method .. I am not sure this approach is even approaching being consistent.

Everywhere else I put this code the result always came back as zero
Is there a property that can always tell me what the axis.maximum and axis.minimum are regardless of how zoomed it is ???
i.e. .. as soon as I zoom the chart XRange0 will be overwritten with a new value.
I tried calling XRange0 = GetAxisRange(StockChart.Axes.Bottom); Directly after populating a candle series and adding it to a chart but again I got a 0.

OH and another quick question how can I scroll to an exact position ... there is a scroll method(Steema.TeeChart.Axis.Scroll) that takes an offset and scrolls from the current position in the direction of the offset but what if I want to scroll to predefined positions in the chart 1.e. the Starting point, 50% of the chart 75% of the chart etc ... what method can I use.


Cheers Phil.

Re: TeeCHart Newbie Q1 of 1022 Zooming and Scrolling

Posted: Mon Jul 05, 2010 10:10 am
by 10050769
Hello Phil,
Currently the only way I can find to get the intial value for XRange0 is from the event

private bool doneOnce = false;
private double XRangeMax = 0;

private void StockChart_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
XRange0 = GetAxisRange(StockChart.Axes.Bottom);

if (XRange0 != 0 && doneOnce == false)
{
/// I need the second value from this event.
XRangeMax = XRange0;
doneOnce = true;
}
}


The first time this event fires I get a zero, soon after the event fires again and I get the value that I require and I can store.
I am nervous about this method. I am not sure this approach is even approaching being consistent.

Everywhere else I put this code the result always came back as zero
Is there a property that can always tell me what the axis.maximum and axis.minimum are regardless of how zoomed it is ???
i.e. .. as soon as I zoom the chart XRange0 will be overwritten with a new value.
I tried calling XRange0 = GetAxisRange(StockChart.Axes.Bottom); Directly after populating a candle series and adding it to a chart but again I got a 0.
Method tChart1.Draw() paints the complete Axis (Ticks, Grid, Labels, Title) using the Axis.ParentChart.Canvas. Normally you do not need to call the Draw method directly, but in it case is necessary, because until chart isn't painted, properties that you use for get values, can not have been calculated and you don't have correctly values.

Could you please check if our code works fine for you?
OH and another quick question how can I scroll to an exact position ... there is a scroll method(Steema.TeeChart.Axis.Scroll) that takes an offset and scrolls from the current position in the direction of the offset but what if I want to scroll to predefined positions in the chart 1.e. the Starting point, 50% of the chart 75% of the chart etc ... what method can I use.
I recommend that use SetMinMax() method, for calculate scroll with your values. You can find examples about it in TeeChart .net Demo concretely in All Features\Welcome !\Miscellaneous\Zoom and Scroll.

I hope will helps.

Thanks,