![]() |
Contents page Previous | Next |
If the data source for your Chart contains more data than can be legibly displayed on one Chart screen you may wish to divide the Chart into pages that can be leafed through. This can be achieved via the Chart Editor or programmatically.
Contents |
Paging with the Chart Editor Paging with the TChartPageNavigator component Paging by code Printing a multipage Chart Print-previewing a multipage Chart |
Page sizes may be defined with the Chart Editor. It will still be necessary to add paging buttons to your project or you could make the Chart Editor available at runtime to allow users to change pages with the Editor.
At design time, select the Paging page in the Chart Editor.
In the Points per Page: box, type (or scroll to) the number of Series points you wish to see on the Chart page. If you're coding the data values for the Series, the navigation buttons will not be highlighted until you run the project, populate the Series and show the Chart Editor at runtime. If you are connected to a Datasource you should see paging take effect immediately at design time.
Runtime:
To access paging properties via the chart editor at runtime use the EditChart or EditDBChart methods.
e.g. (You need to add EditChar and Editpro to the uses part of your project)
EditChart(Self, Chart1);
The TChartPageNavigator component offers easy intuitive Chart page navigation, similar to existing navigators for database recordsets.
Set the Navigator's Chart property to the Chart Panel you wish to Page.
Paging properties and methods are available via the TChart component. See the Page property
Steps required to add paging to your Chart:
Use MaxPointsPerPage to define the number of points to display on each page.
e.g.
Chart1.MaxPointsPerPage := 10;
Example:
First Page
Chart1.Page := 0;
Advance a page
Chart1.NextPage;
Go to a previous page
Chart1.PreviousPage;
Last Page
Chart1.Page := Chart1.Numpages;
The last page is unlikely to have exactly the correct number of points to match the point quantity in the other Chart pages. You may choose to Scale the Last page which will 'best fit' the remaining points to the page, adjusting the axis scale accordingly, or you may treat the page as previous pages with the same number of points which may leave the last page rather empty if there are not many points on the page.
Chart1.ScaleLastPage := False; (default = True)
The TChart OnPageChange event may be used to show the user the existing page number. Here using a Label for the Page number:
Label1.Caption := IntToStr(Chart1.Page) + ' of ' + IntToStr(Chart1.Numpages);
To print a multipage Chart use the Chart PrintPages method.
procedure TPrintPagesForm.Button1Click(Sender: TObject); begin With PrintDialog1 do begin FromPage:=1; ToPage:=Chart1.NumPages; MinPage:=FromPage; MaxPage:=ToPage; if Execute then Chart1.PrintPages(FromPage,ToPage); end; end;
Multipage Charts may be print previewed whilst being navigated. Simply set the Previewer's Panel property to the Chart which you wish to view then use the TChartPageNavigator component to page the Chart.
![]() |
![]() |