Printing a readable chart could be a tricky task, especially, while printing charts with large data. Depending on the use case and requirement, there can be multiple ways in which a chart can be printed. For instance, printing a chart on a single page is a good idea when chart has less data or you want to understand the overall pattern of data without knowing the detailed data points. On the other hand, when you want to study chart details, you can display one chart on each page or even a single chart divided into sub-charts or strip charts on multiple pages.
In FlexChart, you can carry out printing by using the C1.Chart.FlexChart.Printing assembly that can be obtained by building the product sample named C1.Chart.FlexChart.Printing and accessing obj\Debug folder inside the project. This assembly provides the ChartPrinter class to achieve printing in FlexChart. The sections below discuss how this class can be used in various printing scenarios.
Note: C1.Chart.FlexChart.Printing sample is located at \Documents\ComponentOne Samples\WinForms\v4.5.2\C1FlexChart\CS\FlexChartPrint on your system, if you have installed the samples while installing WinForms Edition using ComponentOneC1ControlPanel.exe.
In FlexChart, you can print a chart on a single page by creating an instance of the above-mentioned ChartPrinter class. The constructor takes two parameters, one is the target FlexChart instance and other one is a Boolean value that indicates whether to display the print dialog or not. You, then need to specify whether you need to scale the chart for printing by using the PrintScale enumeration which lets you set the chart scaling to none, fit, stretch and zoom according to the available space. You can also opt to set the custom page and printer settings, grayscale etc. as per the requirement and then call the PrintCtrl method which accepts PrintScale and some of the settings as its parameters.
There can be various scenarios in which a chart or charts are required to be printed on multiple pages. To achieve the multi-page printing, we need to use the above-mentioned ChartPrinter class in conjunction with the PrintDocument class. The PrintDocument class, along with the settings related to the print, provides the PrintPage event which is required to implement the main printing job. You can use PrinterCtrlToPage method of the ChartPrinter class, DrawChart method of the FlexChart class or DrawImage method of the Graphics class as per the layout requirements. In this example, we have demonstrated how to print a single chart on multiple pages in the form of sub-charts.
For more printing scenarios and detailed implementation, see FlexChartExplorer sample which is shipped with the control. To see this feature in action, you can also download the FlexChartExplorer demo from our website.