Nevron Forum

Chart Export Resolution

https://www.nevron.com/Forum/Topic2517.aspx

By Patrick R - Friday, July 24, 2009

Is it possible to export charts at a resolution higher than 72dpi?

I need my chart to be 300dpi for good print quality. I am importing my chart image into an Adobe InDesign document for PDF generation.

Thanks!
By Blagovest Milanov 1 - Friday, July 24, 2009

Hello Patrick,

 

Yes you can export chart images with different size and resolution. Here is a sample code:

 

nChartControl1.ImageExporter.SaveToFile("c:\\temp\\chart.png", new NSize(400, 400), new NResolution(300, 300), new NPngImageFormat());

 

You can also check the image exporter from the Chart examples.

 

Hope this helps – let me know if you have any questions or comments.

 

Best regards.

Bob

By Patrick R - Friday, July 24, 2009

Thanks Bob.

I have tried this. When I add "new NResolution(300, 300)" to the parameter list for ImageExporter.SaveToFile() the export image of the chart is mostly black with my chart shrunk down and cruched into the top left corner. I have attached two images exported from the code below. Any ideas?

Thanks!

Patrick



NChartControl nChartCtrl = new NChartControl();

nChartCtrl.Settings.ShapeRenderingMode = ShapeRenderingMode.AntiAlias;

nChartCtrl.BackgroundStyle.FrameStyle.Visible = false;
nChartCtrl.Width = 600;
nChartCtrl.Height = 500;

NChart nChart = nChartCtrl.Charts[0];
nChart.Dock = System.Windows.Forms.DockStyle.Fill;

nChart.DockMargins = new NMarginsL(20, 0, 20, 0);

Random rand = new Random(DateTime.Now.Millisecond);

NLineSeries line = (NLineSeries)nChart.Series.Add(SeriesType.Line);
line.Values.FillRandom(rand, 10);

NPngImageFormat pngFormat = new NPngImageFormat();
pngFormat.PixelFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb;

NResolution resolution = new NResolution(300, 300);

nChartCtrl.ImageExporter.SaveToFile("C:\\Test\\chart300.png", new NSize((int)nChartCtrl.Width, (int)nChartCtrl.Height), resolution, pngFormat);

nChartCtrl.ImageExporter.SaveToFile("C:\\Test\\chart72.png", new NSize((int)nChartCtrl.Width, (int)nChartCtrl.Height), NResolution.ScreenResolution, pngFormat);
By Patrick R - Monday, July 27, 2009

I actually just noticed that if I remove the line:

pngFormat.PixelFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb;

The black space disappears and the chart fills the entire image. However, all the contents of the chart remain crammed together.

How can I preserve the intended look of the chart (72dpi) when I export to 300dpi?

I have attached a recent version.


Thanks!

Patrick
By Blagovest Milanov 1 - Monday, July 27, 2009

Hi Patrick,

 

Regarding the black image - I was not able to reproduce it with the current version of the control, even if I change the pixel format.

 

NChartControl nChartCtrl = new NChartControl();

nChartCtrl.Settings.ShapeRenderingMode = ShapeRenderingMode.AntiAlias;

nChartCtrl.BackgroundStyle.FrameStyle.Visible = false;

nChartCtrl.Width = 600;

nChartCtrl.Height = 500;

 

NChart nChart = nChartCtrl.Charts[0];

nChart.Dock = System.Windows.Forms.DockStyle.Fill;

 

Random rand = new Random(DateTime.Now.Millisecond);

 

NLineSeries line = (NLineSeries)nChart.Series.Add(SeriesType.Line);

line.Values.FillRandom(rand, 10);

 

NPngImageFormat pngFormat = new NPngImageFormat();

pngFormat.PixelFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb;

 

NResolution resolution = new NResolution(300, 300);

 

float xScale = resolution.DpiX / NResolution.ScreenResolution.DpiX;

float yScale = resolution.DpiX / NResolution.ScreenResolution.DpiY;

 

nChartCtrl.ImageExporter.SaveToFile("C:\\temp\\chart300.png", new NSize((int)(xScale * nChartCtrl.Width), (int)(yScale * nChartCtrl.Height)), resolution, pngFormat);

 

nChartCtrl.ImageExporter.SaveToFile("C:\\temp\\chart72.png", new NSize((int)nChartCtrl.Width, (int)nChartCtrl.Height), NResolution.ScreenResolution, pngFormat);

 

I used the above code - in general you also need to scale the chart dimensions - the resolution setting will generally change the size of 2D objects like texts as well as everything else that uses absolute measurement units.

 

Hope this helps - let me know if you have any questions or meet any problems.

 

Best regards,
Bob