johnt Posted May 12, 2009 Report Share Posted May 12, 2009 I'm evaluating ChartFX for WPF for an application that generates reports. We are trying to create report pages in XAML and then export them to XPS documents. It has worked very well except we've had trouble getting charts to work right (not just ChartFX...). When the charts are written to the XPS document, only the borders/background of the chart appear. The main pane, axes, series, etc. do not show. I saw a similar problem that happened when printing charts that were not visually displayed so it may be related. Here is some sample code that reproduces this. I place the chart control in a FixedDocument and then write that document using XpsDocumentWriter.Write(Visual visual). The chart appears fine when the document is displayed in a document viewer, but it is not correct in the XPS file which leads me to believe its only an issue when "drawing" the chart in the XpsDocumentWriter. Size pageSize = new Size(96 * 8.5, 96 * 11); // create the fixed pageFixedPage fixedPage = new FixedPage();fixedPage.Background = Brushes.White; fixedPage.Width = pageSize.Width; fixedPage.Height = pageSize.Height; // add the chart controlChart chart = new Chart(); chart.Background = new SolidColorBrush(Colors.Green);FixedPage.SetLeft(chart, 96 * 0.75);FixedPage.SetTop(chart, 96 * 0.75); chart.Width = 300; chart.Height = 300;fixedPage.Children.Add((UIElement)chart); // update sizesfixedPage.Measure(pageSize);fixedPage.Arrange(new Rect(new Point(), pageSize)); fixedPage.UpdateLayout(); // create the documentFixedDocument document = new FixedDocument(); document.DocumentPaginator.PageSize = pageSize; PageContent pageContent = new PageContent();((IAddChild)pageContent).AddChild(fixedPage); document.Pages.Add(pageContent); // save as xpsstring fileName = "chart.xps"; Package package = Package.Open(fileName, FileMode.Create);XpsDocument xpsDocument = new XpsDocument(package);XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument); xpsWriter.Write(document); package.Flush(); package.Close(); Quote Link to comment Share on other sites More sharing options...
JuanC Posted May 15, 2009 Report Share Posted May 15, 2009 We have fixed this issue on our internal builds although you will need an additional line of code for charts that won't be displayed on the screen but only used for XPS generation. chart.AdvancedSettings |= ChartSettings.RenderBeforeLoad;Send an email to support at softwarefx dot com if you want to test this before it is released. Regards, JuanC Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.