This is a migrated thread and some comments may be shown as answers.

Printing chart causes "No data to plot"

3 Answers 235 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 09 Feb 2015, 04:11 PM
I am printing a WPF screen, using the PrintDialog.PrintVisual method.  All of the bound controls on the screen print correctly except for the two Telerik controls - RadCartesianChart and RadPieChart.  Both of these controls display the message "No data to plot" on the printout.

The data in the controls is bound to the datacontext; and displays correctly in the screen when displayed, the only issue is when printed.  Would you expect bound Telerik controls to print correctly?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 11 Feb 2015, 12:21 PM
Hi Mark,

Unfortunately I wasn't able to reproduce the described behavior using PrintDialog.PrintVisual(). You can check also our Exporting demo, where the chart is printed correctly. The scenario is similar to yours - the chart is bound to a viewmodel and the print method is as follow:
private void Print()
{
    PrintDialog dialog = new PrintDialog();
    if (!(bool)dialog.ShowDialog())
    {
        return;
    }
 
    dialog.PrintVisual(this.chart, "MyDocument");
}

However, can you elaborate a bit more on your scenario by sending us a sample project which isolates the issue. This will allow us to test it locally and further investigate the reason behind this behavior. It is also important for us to know at which moment you print the chart, is it already displayed on the screen or not. 

Thank you in advance for your cooperation.

Regards,
Milena
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Mark
Top achievements
Rank 1
answered on 11 Feb 2015, 12:58 PM
The answer is, that at the moment of printing it is not displayed on the screen.  When I print a chart that is displayed on the screen it prints correctly.  So I have changed my application accordingly.

It is still interesting to note that other controls do print correctly even when these controls are not displayed (including charts by ComponentOne); whereas Telerik charts do not.
0
Milena
Telerik team
answered on 13 Feb 2015, 12:04 PM
Hi Mark,

PrintDialog.PrintVisual method can print all visible elements and I suppose that at the time you print the chart its draw-pass is still not executed. As the chart is a UI control which relies on the .Net framework for its layout,  we would recommend you printing it after the control is displayed on the screen. However, if your scenario requires to print the chart before it is visualized, you should force Measure and Arrange on the chart before printing it. So, you can add a method to prepare the chart for print:
private void PrepareChartForPrint()
{
    if (this.ActualWidth == 0 || this.ActualHeight == 0)
    {
        this.Chart.Measure(new Size(width, height));
        this.Chart.Arrange(new Rect(x, y, width, height));
    }
    this.Chart.UpdateLayout();
}

Please give this approach a try and let us know if it works for you.

Regards,
Milena
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Chart
Asked by
Mark
Top achievements
Rank 1
Answers by
Milena
Telerik team
Mark
Top achievements
Rank 1
Share this question
or