Hi
I have a following problem:
I am using Teechart for CF. My purpose is to implement chart moving left/right.
My x axis is DateTime and lets say I have total ammount of data for 1 year in 2 hours resolution (4320 values).
I want to display 2 months data and to give the user ability to move the chart left or right thus moving each time 2 months.
I know that there are 2 method - scrolling and paging.
I have tryed paging - first of all last page issue - i want to show it from last xvalue 2 months back (and not as it is divided automatically).
Second, when the chart iz zoomed and i try to go next/prev page - x values change but the chart doesnt.
Hope I was clear enough:)
Any ideas?
Thanks
partial data displaying / chart moving
Re: partial data displaying / chart moving
Hi Igor,
In a first view I thought that you would like the navigation to work as by default only changing the last page to show the last 720 values. In the following example that's what I'm doing:
But note that this way, in page 6/7 there remain very few values not shown in the right so at page 7/7 we sill show those few values and a lot of values taken from the previous page 6/7.
And besides, with this way the zoom won't still work because automatic pagination needs the bottom axis to be set as automatic and, in essence, the zoom makes a SetMinMax that changes this automatic property.
So probably a more accurate solution could be working always with SetMinMax. So it means that we should do the pagination manually. Here is a quite complete example (but surely improvable) of how you could do it:
In a first view I thought that you would like the navigation to work as by default only changing the last page to show the last 720 values. In the following example that's what I'm doing:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
Bar bar1;
private void InitializeChart()
{
chartController1.Chart = tChart1;
bar1 = new Bar(tChart1.Chart);
DateTime StartTime = new DateTime(2008, 7, 7, 0, 0, 0);
Random Rnd = new Random();
for (int i = 0; i < 4380; i++)
{
bar1.Add(StartTime + new TimeSpan(i*2, 0, 0), Rnd.Next(1000));
}
tChart1.Page.MaxPointsPerPage = 720;
tChart1.Aspect.View3D = false;
bar1.Marks.Visible = false;
tChart1.Header.Text = tChart1.Page.Current.ToString() + " / " + tChart1.Page.Count;
}
private void PageDown_Click(object sender, EventArgs e)
{
if (tChart1.Page.Current == tChart1.Page.Count)
{
tChart1.Axes.Bottom.Automatic = true;
}
tChart1.Page.Previous();
tChart1.Header.Text = tChart1.Page.Current.ToString() + " / " + tChart1.Page.Count;
}
private void PageUp_Click(object sender, EventArgs e)
{
tChart1.Page.Next();
if (tChart1.Page.Current == tChart1.Page.Count)
{
tChart1.Axes.Bottom.SetMinMax(bar1.XValues[bar1.Count - tChart1.Page.MaxPointsPerPage - 1], bar1.XValues[bar1.Count - 1]);
}
tChart1.Header.Text = tChart1.Page.Current.ToString() + " / " + tChart1.Page.Count;
}
And besides, with this way the zoom won't still work because automatic pagination needs the bottom axis to be set as automatic and, in essence, the zoom makes a SetMinMax that changes this automatic property.
So probably a more accurate solution could be working always with SetMinMax. So it means that we should do the pagination manually. Here is a quite complete example (but surely improvable) of how you could do it:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
Bar bar1;
int DefaultPointsShown, ActualPointsShown, ActualPage, TotalPages, FirstIndexShown;
private void InitializeChart()
{
chartController1.Chart = tChart1;
bar1 = new Bar(tChart1.Chart);
DateTime StartTime = new DateTime(2008, 7, 7, 0, 0, 0);
Random Rnd = new Random();
for (int i = 0; i < 4380; i++)
{
bar1.Add(StartTime + new TimeSpan(i*2, 0, 0), Rnd.Next(1000));
}
tChart1.Aspect.View3D = false;
bar1.Marks.Visible = false;
FirstIndexShown = 0;
DefaultPointsShown = 720;
ActualPointsShown = DefaultPointsShown;
ActualPage = 1;
TotalPages = (int)Math.Ceiling((double)bar1.Count / ActualPointsShown);
tChart1.Axes.Bottom.SetMinMax(bar1.XValues[FirstIndexShown], bar1.XValues[FirstIndexShown + ActualPointsShown]);
tChart1.Header.Text = ActualPage + " / " + TotalPages;
tChart1.Zoomed += new EventHandler(tChart1_Zoomed);
tChart1.UndoneZoom += new EventHandler(tChart1_UndoneZoom);
}
void tChart1_UndoneZoom(object sender, EventArgs e)
{
tChart1.Refresh();
FirstIndexShown = bar1.FirstVisibleIndex;
ActualPointsShown = DefaultPointsShown;
TotalPages = (int)Math.Ceiling((double)bar1.Count / ActualPointsShown);
if (FirstIndexShown == 0)
{
ActualPage = 1;
}
else
{
ActualPage = (int)Math.Floor((double)FirstIndexShown * TotalPages / bar1.Count)+1;
}
tChart1.Header.Text = ActualPage + " / " + TotalPages;
}
void tChart1_Zoomed(object sender, EventArgs e)
{
tChart1.Refresh();
FirstIndexShown = bar1.FirstVisibleIndex;
ActualPointsShown = bar1.LastVisibleIndex - FirstIndexShown;
TotalPages = (int)Math.Ceiling((double)bar1.Count / ActualPointsShown);
ActualPage = (int)Math.Ceiling((double)FirstIndexShown * TotalPages / bar1.Count)+1;
tChart1.Header.Text = ActualPage + " / " + TotalPages;
}
private void PageDown_Click(object sender, EventArgs e)
{
if (FirstIndexShown > 0)
{
ActualPage -= 1;
if ((FirstIndexShown - ActualPointsShown) > 0)
{
FirstIndexShown = FirstIndexShown - ActualPointsShown - 1;
}
else
{
FirstIndexShown = 0;
}
tChart1.Axes.Bottom.SetMinMax(bar1.XValues[FirstIndexShown], bar1.XValues[FirstIndexShown + ActualPointsShown]);
}
tChart1.Header.Text = ActualPage + " / " + TotalPages;
}
private void PageUp_Click(object sender, EventArgs e)
{
if ((bar1.Count - 1) > (FirstIndexShown + ActualPointsShown + 1))
{
ActualPage += 1;
if ((bar1.Count - 1) > (FirstIndexShown + (ActualPointsShown * 2)))
{
FirstIndexShown = FirstIndexShown + ActualPointsShown + 1;
}
else
{
FirstIndexShown = bar1.Count - ActualPointsShown - 1;
}
tChart1.Axes.Bottom.SetMinMax(bar1.XValues[FirstIndexShown], bar1.XValues[FirstIndexShown + ActualPointsShown]);
}
tChart1.Header.Text = ActualPage + " / " + TotalPages;
}
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: partial data displaying / chart moving
Hi
Thanks, that exactly what I was thinking to do...
I will try
Thanks, that exactly what I was thinking to do...
I will try