Applies to: Nevron Chart for .NET

How to customize the size of printed chart?

In order to customize the size of printed chart, you need to modify the chart bounds mode as well as location and size properties so that it occupies a larger area on the print page. Doing so requires you to create a replica (clone) of the control in order to preserve the original chart settings. The following code snippet shows how to achieve this in code:

[C#]
// create a duplicate of the current control
MemoryStream memStream = new MemoryStream();
nChartControl1.Serializer.SaveControlStateToStream(memStream, PersistencyFormat.Binary, null);
memStream.Seek(0, SeekOrigin.Begin);
NChartControl chartControl2 = new NChartControl();
chartControl2.Serializer.LoadControlStateFromStream(memStream, PersistencyFormat.Binary, null);
  
// set the bounds mode of the chart
NChart chart = (NChart)chartControl2.Charts[0];
chart.BoundsMode = BoundsMode.Stretch;
  
// set the chart to occupy 90% of the area available on 
// the page (page size minus margins specified by the page settings)
chart.Location = new NPointL(new NLength(5.0f, NRelativeUnit.ParentPercentage),
                 new NLength(5.0f, NRelativeUnit.ParentPercentage));
  
chart.Size = new NSizeL(new NLength(90.0f, NRelativeUnit.ParentPercentage), 
             new NLength(90.0f, NRelativeUnit.ParentPercentage));
  
NPrintManager printManager = new NPrintManager(chartControl2.Document);
  
// set page orientation to landscape
printManager.PageSettings.Landscape = true;
  
// this is optional - note that some printers will not be able to print
// with zero margins
printManager.PageSettings.Margins = new Margins(0, 0, 0, 0);
  
// Get size information on the printing target
printManager.ShowPrintPreview();

[VB.NET]
' create a duplicate of the current control
Dim memStream As New MemoryStream()
nChartControl1.Serializer.SaveControlStateToStream(memStream, PersistencyFormat.Binary, Nothing)
memStream.Seek(0, SeekOrigin.Begin)
Dim chartControl2 As New NChartControl()
chartControl2.Serializer.LoadControlStateFromStream(memStream, PersistencyFormat.Binary, Nothing)
  
' set the bounds mode of the chart
Dim chart As NChart = DirectCast(chartControl2.Charts(0), NChart)
chart.BoundsMode = BoundsMode.Stretch
  
' set the chart to occupy 90% of the area available on 
' the page (page size minus margins specified by the page settings)
chart.Location = New NPointL(New NLength(5F, NRelativeUnit.ParentPercentage), New NLength(5F, NRelativeUnit.ParentPercentage))
  
chart.Size = New NSizeL(New NLength(90F, NRelativeUnit.ParentPercentage), New NLength(90F, NRelativeUnit.ParentPercentage))
  
Dim printManager As New NPrintManager(chartControl2.Document)
  
' set page orientation to landscape
printManager.PageSettings.Landscape = True
  
' this is optional - note that some printers will not be able to print
' with zero margins
printManager.PageSettings.Margins = New Margins(0, 0, 0, 0)
  
' Get size information on the printing target
printManager.ShowPrintPreview()

Article ID: 72, Created On: 10/6/2010, Modified: 11/15/2010