Hello,
I am having Chart which consists of different chart areas. Currently if I click on Print Preview all Charts are displayed on single page. I want each chart to be displayed on separate page. I cant access each chart individually and call PrintPreview method but I can access each Chart Area so please help me to print each chart area on different page.
Hi Suraj,
After investigating printing each Chart Area in a different page issue and doing some research, printing each Chart Area in a different page has been determined to be a new product idea. You can suggest new product ideas for future versions (or vote for existing ones) at <http://ideas.infragistics.com>.
Submitting your idea will allow you to communicate directly with our product management team, track the progress of your idea at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.
Remember when submitting your idea to explain the context in which a feature would be used and why it is needed as well as anything that would prevent you from accomplishing this today. You can even add screenshots to build a stronger case. Remember that for your suggestion to be successful, you need other members of the community to vote for it. You can also link back to this thread for additional details.
However there is an alternative way to achieve this. You can add each Chart Area to a separate UltraChart and print each one of them in order to print each Chart area in a different page. Please let me know if I may be of further assistance in implementing this approach.
Thank you in advance to submitting your product idea.
Sincerely,Sahaja KokkalagaddaAssociate Software Developer
Hi,
I am able to print preview each chart area on separate page but now the order of pages are reversed so can you please help me to correct the order and print pages in correct order.
Here is the part of code I am using to check count of Chart Area and then calculate its height, width and then previewing each chart area on separate page.
public void Preview()
{
pageCount = Chart.ChartAreas.Count();
Manager.PrintPreview();
}
private void PrintDocument_PrintPage(object sender, PrintPageEventArgs ev)
try
BeforePrint(ev);
if (charts.Count == 0) {
foreach (ChartArea c in Chart.ChartAreas)
charts.Add(new Chart());
if (pageCount > 3 )
ev.HasMorePages = true;
pageCount = pageCount-1;
else if(pageCount>2)
pageCount = pageCount - 1;
else if(pageCount>1)
else
ev.HasMorePages = false;
float widthOfChartArea = Chart.ChartAreas[pageCount -1].Position.Width;
float heightOfChartArea = Chart.ChartAreas[pageCount - 1].Position.Height;
// Calculate first chart position rectangle
Rectangle chartAreaPosition = new Rectangle (ev.MarginBounds.X, ev.MarginBounds.Y, (Int32)widthOfChartArea, (Int32)heightOfChartArea);
// Scale chart position on the page
double chartScale = Math.Min((float)ev.MarginBounds.Width / (float)widthOfChartArea, (float)ev.MarginBounds.Height / (float)heightOfChartArea);
chartAreaPosition.Width = (int)((float)chartAreaPosition.Width * chartScale);
chartAreaPosition.Height = (int)((float)chartAreaPosition.Height * chartScale);
//Display units mean different thing depending if chart is rendered on the display or printed.
//Typically pixels for video displays, and 1/100 inch for printers.
if (ev.Graphics.PageUnit == GraphicsUnit.Display)
// Chart is always expecting to draw in pixels
ev.Graphics.PageUnit = GraphicsUnit.Pixel;
//Scale chart size from 1/100 of an inch to expected pixels.
chartAreaPosition.Width = (int)((float)chartAreaPosition.Width * ev.Graphics.DpiX / 100.0f);
chartAreaPosition.Height = (int)((float)chartAreaPosition.Height * ev.Graphics.DpiY / 100.0f);
chartAreaPosition.X = (int)((float)chartAreaPosition.X * ev.Graphics.DpiX / 100.0f);
chartAreaPosition.Y = (int)((float)chartAreaPosition.Y * ev.Graphics.DpiY / 100.0f);
//Chart.Printing.PrintPaint(ev.Graphics, chartAreaPosition);
Chart c = charts[pageCount-1 ];
ChartArea ca = Chart.ChartAreas[pageCount -1];
ca.AlignmentOrientation = AreaAlignmentOrientations.Vertical;
ca.AlignWithChartArea = "";
c.ChartAreas.Add(ca);
c.Printing.PrintPaint(ev.Graphics, chartAreaPosition);
finally
AfterPrint(ev);
if there are two chart areas then this code work fine but if there are more than three charts then they are printed in order like 2,1,3.. So please help me to fix this.
After looking at your code I realized that you were not using any Infragistics controls in your application. I recommend contacting Microsoft support or Stack overflow support for resolving this ChartAreas PrintPreview issue as this is outside the scope of Infragistics Developer Support.
However, I noticed the below things in your code that might be a reason why ChartAreas are showing up in the wrong order in PrintPreview.
1. PageCount is equal to ChartAreas count and it is decremented by one when its >3, 2 and 1. So this causing the previous Chart& pervious ChartArea to show up in the PrintPreview.2. When you have two charts this works fine because you have ‘If’ followed by ‘else’ if the PageCount is >2 and1. But looking at the below forum post you don’t have an else part for if (PageCount>=3) statement which is causing the PageCount to decrement by one twice. So this is reversing the order in which your ChartAreas are being printed. http://www.infragistics.com/community/forums/p/108098/509152.aspx#509152
Thank you for contacting Infragistics Developer Support.
Hi
I have made few changes but still pages are displayed in reverse order. Here is part of code I am using in my application.
public static int pageCount = 1;
private
voidPrintDocument_PrintPage(objectsender, PrintPageEventArgsev)
if
(pageCount < Chart.ChartAreas.Count())
pageCount --;
pageCount = pageCount - Chart.ChartAreas.Count() + 1 ;
Chart c = charts[pageCount - 1];
Here suppose if Chart.ChartAreas.Count() is 2, then 'if' block will execute making pageCount 2 and charts[1] will be accessed. In next iteration 'else' block will execute making pageCount=1 and charts[0] will be accessed. So these are accessed in Reverse order so please help me to display them in correct order.
Thanks.
If ChartAreas count is two then if block will execute making the PageCount zero as it is previously 1 and accessing charts[-1] will give you an exception. I suggest decrementing the PageCount after you add the corresponding ChartArea to the Chart.
As you are using Microsoft Chart, Please contact Microsoft support for further assistance regarding this issue.