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);
DateTime Axis Scroll
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: DateTime Axis Scroll
Hello,
Apologies for the delay in response to these questions.
You can modify default scroll behaviour using the ScrollMod event, e.g.
To scroll to a specific date using a button, you could do:
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;
}
}
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 |
Re: DateTime Axis Scroll
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?
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?
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: DateTime Axis Scroll
Hello,
You can make a small modification to the previous code by checking for both axes in the event, e.g.
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 |