Page 1 of 1

Controlling zoom and scroll level

Posted: Tue Nov 24, 2015 7:56 am
by 18276989
I have a candle chart, which can be zoomed and scrolled only horizontally. The series contain 30 to 180 candles. I am trying to limit the max zoom level to 10 candles but I can't figure it out. I can disable the zoom once there are only 10 candles visible (using first visible and last visible), but I can't turn it back on. The next issue is that I can't limit the scrolling to not exceed the first value of the series.

Re: Controlling zoom and scroll level

Posted: Tue Nov 24, 2015 8:55 am
by Christopher
Hello Ilia,
IliaStoilov wrote:I have a candle chart, which can be zoomed and scrolled only horizontally. The series contain 30 to 180 candles. I am trying to limit the max zoom level to 10 candles but I can't figure it out. I can disable the zoom once there are only 10 candles visible (using first visible and last visible), but I can't turn it back on. The next issue is that I can't limit the scrolling to not exceed the first value of the series.
This code may give you some pointers toward a possible solution:

Code: Select all


    Candle candle1;
    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      candle1 = new Candle(tChart1.Chart);
      candle1.FillSampleValues(100);

      tChart1.Zoom.Direction = ZoomDirections.Horizontal;
      tChart1.Zoomed += TChart1_Zoomed;
      tChart1.Scroll += TChart1_Scroll;
    }

    private void TChart1_Scroll(object sender, EventArgs e)
    {
      double first = candle1.XValues.First;

      if(tChart1.Axes.Bottom.Maximum < first)
      {
        tChart1.Axes.Bottom.Maximum = first;
      }
    }

    private void TChart1_Zoomed(object sender, EventArgs e)
    {
      List<double> xvalues = candle1.XValues.Value.ToList();
      double first = xvalues.First(x => x >= tChart1.Axes.Bottom.Minimum);
      int firstIndex = xvalues.IndexOf(first);
      double last = xvalues[firstIndex + 9];

      tChart1.Axes.Bottom.Maximum = last;
    }