When trying to print the chart out using the ultrachart's PrintDocument property, custom annotations appear in the wrong location and modifications made during the FillSceneGraph and ChartDrawItem events do not appear as part of the print document. Is there any way to solve this problem?
You are correct, I am not using the latest version. If this is an issue that has been fixed, that is great.
As for the annotations, I am using row/column location to position them on the chart. It looks like what is happening to them has less to do with the chart being resized, and more to do with the fact that the annotations dont seem to factor in the margins on the page moving the chart's start point. I believe this is the case because in the tests I have done, the chart is always narrower on the print preview than it was in my control, and yet all of the annotations appear to the left of where they should. The annotations themselves appear to be correctly spaced, but their location is entirely not where it should be. This may be a bug you might want to look into.
I know that its possible to render the image to a print document, in fact I have done that just to prove that it works, but I much prefer the appearance of the print document from the chart object, minus the problems I am getting. I will look into the pdf option.
Thank you for the reply. If you have any more feedback on the annotation issue it would be much appreciated.
how are you positioning the annotations? are their X and Y coordinates specified by percent values, data values, or pixel values?
by default, the chart will resize to fit the page, so the size and aspect ratio will be altered, making pixel and percentage-based locations invalid from one image to the next.
if you access the PrintDocument property of the control and handle its PrintPage event before invoking the Print method, i think you can change the target size of the chart.
you could also just create your own PrintDocument object and add the chart to its graphics (e.Graphics in PrintPage) as a bitmap.
If I want to go down the road of saving the chart as an image and then printing it, how do I go about doing that?
jcaplantrp:
private void Form1_Load(object sender, EventArgs e) { this.ultraChart1.Data.DataSource = Infragistics.UltraChart.Data.DemoTable.Table(); this.ultraChart1.Data.DataBind(); BoxAnnotation boxAnno = new BoxAnnotation(); boxAnno.PE = new PaintElement(Color.PaleGreen); boxAnno.Text = "hello"; boxAnno.Location.Type = LocationType.RowColumn; boxAnno.Location.Row = boxAnno.Location.Column = -2; this.ultraChart1.Annotations.Add(boxAnno); PrintDocument myPrintDoc = new PrintDocument(); myPrintDoc.PrintPage += new PrintPageEventHandler(myPrintDoc_PrintPage); myPrintDoc.Print(); } void myPrintDoc_PrintPage(object sender, PrintPageEventArgs e) { Image chartImage = this.ultraChart1.Image; e.Graphics.DrawImage(chartImage, Point.Empty); e.HasMorePages = false; }
I am using version 8.2.20082.1000 of the chart. One difference is that I am using a Location.Type of Pixels. I am creating the Annotations when the user clicks on a DataElement and I am offsetting it by using BoxAnnotation.GetRenderPointFromParent()
I can get the labels to appear correctly if I use the example above and use the chart as an image. The output doesn't look as nice, but it works.
I also experimented with saving to a PDF by using chart.RenderPdfFriendlyGraphics(r.AddSection().AddCanvas().CreateGraphics()). This works and the output in the PDF looks good with the labels in the correct place as long as I don't send in a width or height to the above call. My charts are wide and get chopped off in the PDF. Is there a way to specify that the page in the PDF is landscape when the chart is written? If I open the PDF and change the setup to landscape, it is too late since the chart was already rendered to the PDF.
Report r = new Report(); ISection sec = r.AddSection(); sec.PageOrientation = PageOrientation.Landscape; this.ultraChart1.RenderPdfFriendlyGraphics(sec.AddCanvas().CreateGraphics()); r.Publish("C:\\blah.pdf", FileFormat.PDF);