Printing chart causes "No data to plot"

4 posts, 0 answers
  1. Mark
    Mark avatar
    2 posts
    Member since:
    Aug 2014

    Posted 09 Feb 2015 Link to this post

    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.
  2. Milena
    Admin
    Milena avatar
    203 posts

    Posted 11 Feb 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Mark
    Mark avatar
    2 posts
    Member since:
    Aug 2014

    Posted 11 Feb 2015 in reply to Milena Link to this post

    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.
  5. Milena
    Admin
    Milena avatar
    203 posts

    Posted 13 Feb 2015 Link to this post

    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.

     
Back to Top