DateTime Axis Scroll

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
theyield
Newbie
Newbie
Posts: 16
Joined: Thu Sep 22, 2016 12:00 am

DateTime Axis Scroll

Post by theyield » Wed Mar 15, 2017 2:22 am

hi,
i have a chart with a datetime x axis. I want to prevent scrolling beyond my start and end dates.
How can I do this?
I have tried this
tChart.Chart.Axes.Bottom.SetMinMax(startDate, endDate);

with no change.


Also, how I can scroll to a specific date ?
Tried this..
tChart.Axes.Bottom.Scroll(DateTime.Now.ToOADate(), false);

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

Re: DateTime Axis Scroll

Post by Christopher » Mon Mar 20, 2017 9:40 am

Hello,

Apologies for the delay in response to these questions.

You can modify default scroll behaviour using the ScrollMod event, e.g.

Code: Select all

    private void InitializeChart()
    {
      Line series = new Line(tChart1.Chart);

      DateTime today = DateTime.Today;
      Random rnd = new Random();

      for (int i = 0; i < 20; i++) 
      {
        series.Add(today, rnd.Next(500));

        today = today.AddDays(2);
      }

      tChart1.Axes.Bottom.Labels.Angle = 90;

      tChart1.ScrollMod += TChart1_ScrollMod;
    }

    private void TChart1_ScrollMod(Axis a, ScrollModEventArgs e)
    {
      double max = new DateTime(2017, 5, 1).ToOADate();

      if (a.Equals(tChart1.Axes.Bottom))
      {
        e.Max = max;    
      }
    }
To scroll to a specific date using a button, you could do:

Code: Select all

    private void button2_Click(object sender, EventArgs e)
    {
      tChart1.Axes.Bottom.SetMinMax(new DateTime(2017, 4, 22), new DateTime(2017, 5, 1));
    }
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

theyield
Newbie
Newbie
Posts: 16
Joined: Thu Sep 22, 2016 12:00 am

Re: DateTime Axis Scroll

Post by theyield » Mon Jun 26, 2017 4:29 am

That is the only way to prevent scrolling past the enddate and startdate?
It doesn't work if using series.HorizAxis = HorizontalAxis.Both;

I have the date displaying on top axis with topAxis.Labels.DateTimeFormat = "d MMM";
and bottomAxis.Labels.DateTimeFormat = "hh:mm tt";
Any other suggestions?

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

Re: DateTime Axis Scroll

Post by Christopher » Mon Jun 26, 2017 10:21 am

Hello,

You can make a small modification to the previous code by checking for both axes in the event, e.g.

Code: Select all

    private void InitializeChart()
    {
      Line series = new Line(tChart1.Chart);

      DateTime today = DateTime.Today;
      Random rnd = new Random();

      for (int i = 0; i < 20; i++)
      {
        series.Add(today, rnd.Next(500));

        today = today.AddDays(2);
      }

      tChart1.Axes.Bottom.Labels.Angle = 90;

      series.HorizAxis = HorizontalAxis.Both;
      tChart1.Axes.Top.Labels.DateTimeFormat = "d MMM";
      tChart1.Axes.Bottom.Labels.DateTimeFormat = "hh:mm tt";

      tChart1.ScrollMod += TChart1_ScrollMod;
    }

    private void TChart1_ScrollMod(Axis a, ScrollModEventArgs e)
    {
      double max = new DateTime(2017, 8, 3).ToOADate();

      if (a.Equals(tChart1.Axes.Bottom) || a.Equals(tChart1.Axes.Top))
      {
        e.Max = max;
      }
    }
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