Hey there, i want to include a chart in my report. Therefore i created a UserControl containing all layout stuff i want to have in my xps/print. It is just a simple line-chart and in the constructor i bind to sample data. If i display this control in a "real" window
<infragisticsChart:UserControl1 x:Name="MyTestInstance"/>
and then print it
var reportObj = new Report();reportObj.Sections.Add(new EmbeddedVisualReportSection(MyTestInstance));reportObj.Export(OutputFormat.XPS, "c:\\temp\\test.xps");
everything is fine. However, if i want to render the xps without having it in a real wpf window / page, the chart is not rendering anything. If i do
var reportObj = new Report();reportObj.Sections.Add(new EmbeddedVisualReportSection(new UserControl1()));reportObj.Export(OutputFormat.XPS, "c:\\temp\\test.xps");
I tried setting the size, InvalidateMeasure, InvalidateVisual and other things on the control, but it is just not rendering the chart.
The question is: How can i create a report with a chart on a console app / server / service? How do i tell / force a Chart to do its calculations and actually generate the view?
Thanks
Hello Martin,
Thank you for your post. I have been looking into it and I can say that the reports work with visual elements, which means that they should be in the visual tree of the application.
Hope this helps you.
Thanks for your answer. So am i right, that there is NO way to build a non-graphical Windows-Service that generates reports? I mean, if there is no visual tree? This would be a fairly large restricton...
You can try to call the chart's Measure and Arrange methods and after that you should be able to render it in the Report.
I have modified your sample, so now it works as you want. Bascially I removed all the Bindings yo uuse in the Chart, becasue when it is not visualized, the DataContext is not set and the Bindings doesn't work. Also instead of calling Measure and Arrange, I just set the control's Width and Height Properties. Pelase let me know if this helps you or you need further assistnace on this matter.
Looking forward for your reply.
Here is the full project, if somebody is interested
http://bettercode.de/downloads/Test.Chartreport.zip
I tried, but that didn't work either. I squezed the problem into the simplest Workspace ever. One xaml project with the chart control (that works) and one console project that puts the chart control into a report (what doesn't work). Maybe you can have a look into it? In the main mehtod of the console app i made a TODO where i expect you to insert the (hopefully) one line, that helps...
The lines in question are as follows
[STAThread] static void Main(string[] args) { var reportObj = new Report(); // TODO What do do here to make the control/chart to actually render?? var control = new ChartControl(); control.Measure(new Size(500, 500)); // doesn't help control.Arrange(new Rect(0, 0, 500, 500)); // doesn't help either // TODO what to do with the section to make it actually render?? var section = new EmbeddedVisualReportSection(control); reportObj.Sections.Add(section); reportObj.Export(OutputFormat.XPS, "c:\\temp\\test.xps"); }
Thanks again for your help.