Zooming Candle Chart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Zooming Candle Chart

Post by Quant » Wed Feb 04, 2015 11:22 am

While Zooming Candle Chart only candle height and space between candle increases. I also want that candle width must be increase automatically in same proportion.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Zooming Candle Chart

Post by Christopher » Thu Feb 05, 2015 10:57 am

Hello,

One possibility is to run code such as the following:

Code: Select all

    Candle series = new Candle();
    double widthRatio;
    int origCandleWidth;

  private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      tChart1.Series.Add(series);
      series.FillSampleValues();

      tChart1.Zoomed += tChart1_Zoomed;
      tChart1.UndoneZoom += tChart1_UndoneZoom;
      tChart1.BeforeDrawSeries += tChart1_BeforeDrawSeries;
      tChart1.Draw();

      origCandleWidth = series.CandleWidth;
      widthRatio = (tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum) / origCandleWidth;
    }

    bool zoomed = false;
    void tChart1_UndoneZoom(object sender, EventArgs e)
    {
      zoomed = true;
    }

    void tChart1_Zoomed(object sender, EventArgs e)
    {
      zoomed = true;
    }

    void tChart1_BeforeDrawSeries(object sender, Graphics3D g)
    {
      if(zoomed)
      {
        double range = tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum;
        double tmpRatio = range / origCandleWidth;

        if (widthRatio > 0 && widthRatio != tmpRatio)
        {
          series.CandleWidth = Utils.Round((widthRatio / tmpRatio) * origCandleWidth);
        }
        else
        {
          series.CandleWidth = origCandleWidth;
        }
      }
      zoomed = false;
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Re: Zooming Candle Chart

Post by Quant » Tue Feb 24, 2015 4:22 am

We tried the following code, it worked for us, but can you please include TeeChart Control's Size to calculate candle width?

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Zooming Candle Chart

Post by Christopher » Tue Feb 24, 2015 9:56 am

Quant wrote:We tried the following code, it worked for us, but can you please include TeeChart Control's Size to calculate candle width?
If you use the Control's size than the Candle width will not change when you zoom the Chart, which was the original request.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply