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?
They are positioned using Row/Column location. This uses the series and point locations in the data to position the annotations on top of the corresponding primitive in the chart.
oops, i missed that detail from your last post. if you could send a sample project, steps to reproduce, or just screenshots, that would help me address the problem - providing a workaround or fixing it for a future hotfix release.
I am having the same issue. I have several BoxAnnotations on my ScatterChart that were position by Pixel, but when they print, the positions are way off. I tried a test and placed several BoxAnnotations by percentage and still these did not position correctly when printed.
How else can I handle this without exporting to an image first? How would I go about making this work in the PrintPage event as you suggested?
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.
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);
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.
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; }
this code worked for me without any problems using version 8.3.20083.1009. what version of the dll are you using? does this code work for you?
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 doc = this.ultraChart1.PrintDocument; doc.Print(); //this.ultraChart1.PrintChart(); }
I know it will potentially change the locations of things set by pixel location (which makes sense) or percentage location (which makes no sense, whether the object is 10 pixes or 10000 pixels in size, 1 percent is still 1 percent).
However, I located my annotations by row/column location. Again, just as with percentage, a row is a row, and a column is a column, and the locations of the annotations should appear over the row and column where they have been located regardless of whether the size of the chart changes to fit the page. If these things are not working correctly, in my opinion, there is a bug in the software.
Have you actually tested this out, is there a fix coming anytime in the forseeable future? Everything else appears to be resized and relocated correctly, I am not sure why it is that custom annotations can not be handled in this way as well.