I am using dotNetcharting to do my charts and I wanted to do paging after certain amount of elements in chart. I have seen examples of it in the dotnetcharting website but they haven't help me a lot. So far I have been able to show the annotation but no luck with the limit in the SeriesCollection or the paging, in other words still shows everything in the series in just one page.
This is my code so far:
private int currentPage = 1;
private int pageSize = 5;
private Chart chart;
private void LoadChart() {
// Get a new chart
chart = CreateNewChart();
SeriesCollection tempSeriesCollection = GetChartData();
if (Request.QueryString["Page"] != null)
currentPage = Convert.ToInt32(Request.QueryString["Page"]);
chart.SeriesCollection.Add(GetChartData(currentPage));
chart.SeriesCollection[0].Limit = currentPage.ToString() + "x" + pageSize.ToString();
chart.SeriesCollection[0].LimitMode = LimitMode.Top;
chart.SeriesCollection[0].ShowOther = false;
chart.Height = SetChartHeight(chart.SeriesCollection[0].Elements.Count);
// Create an annotation button
if (chart.SeriesCollection[0].Elements.Count > 0) {
Annotation an2 = new Annotation(" < Previous");
setAnnotation(an2);
an2.Position = new Point(533, 43);
an2.CornerTopLeft = BoxCorner.Cut;
an2.CornerTopRight = BoxCorner.Square;
an2.Size = new Size(85, 16);
chart.Annotations.Add(an2);
// Activate it
if (currentPage > 1) {
an2.URL = "PagingElements.aspx?page=" + Convert.ToString(currentPage - 1);
}
else {
an2.Label.Color = Color.Gray;
}
chart.PostDataProcessing += new PostDataProcessingEventHandler(OnPostDataProcessing);
}
AddControlToPlaceHolder(chart);
}
private void setAnnotation(Annotation an) {
// Set default annotation properties
an.DefaultCorner = BoxCorner.Square;
an.Size = new Size(66, 16);
an.Background = new Background(Color.FromArgb(241, 250, 180), Color.White, 90);
an.Label.Font = new Font("Verdana", 7.7f, FontStyle.Bold);
an.CornerTopRight = BoxCorner.Cut;
an.Padding = 2;
}
private void OnPostDataProcessing(Object sender) {
int totalElements = chart.SeriesCollection[0].TotalElements;
int totalPage = totalElements % pageSize == 0 ? totalElements / pageSize : (totalElements / pageSize) + 1;
if (totalPage < 1) {
totalPage = 1;
}
//Create the next button annotation
Annotation an = new Annotation("Next >");
setAnnotation(an);
an.Position = new Point(708, 43);
// Activate it
if (totalPage > currentPage) {
an.URL = "PagingElements.aspx?page=" + Convert.ToString(currentPage + 1);
}
else
an.Label.Color = Color.Gray;
Annotation an2 = new Annotation("(Page " + currentPage + " of " + totalPage + ")");
setAnnotation(an2);
an2.Size = new Size(90, 16);
an2.Position = new Point(618, 43);
an2.CornerTopRight = BoxCorner.Square;
an2.Label.Font = new Font("Arial", 7.7f);
an2.Label.Color = Color.DarkBlue;
chart.Annotations.Add(an, an2);
}
I will appreciate anyone can help me.
thanks,
Erick