Page 1 of 1

Zooming Candle Chart

Posted: Wed Feb 04, 2015 11:22 am
by 16071129
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.

Re: Zooming Candle Chart

Posted: Thu Feb 05, 2015 10:57 am
by Christopher
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;
    }

Re: Zooming Candle Chart

Posted: Tue Feb 24, 2015 4:22 am
by 16071129
We tried the following code, it worked for us, but can you please include TeeChart Control's Size to calculate candle width?

Re: Zooming Candle Chart

Posted: Tue Feb 24, 2015 9:56 am
by Christopher
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.