Auto save chart as PNG?


https://www.nevron.com/Forum/Topic8464.aspx
Print Topic | Close Window

By Jonathan Green - 10 Years Ago
Is it possible to save charts as PNG images automatically to a temp dir?

And or render the chart as a temp file and control the filename?
By Nevron Support - 10 Years Ago
Yes - you can do that with custom C# injected in the control. As the code is executed after the chart is populated with data and before the actual rendering, you can save to arbitrary image. You can have a 0x0 render Width & Height to avoid any output to the browser.

Why do you need to do that? What is the actual scenario?
By Jonathan Green - 10 Years Ago
Hi we generate all our charts with nevron in SharePoint.

We would like to leverage this work by re using the charts for a separate
mobile site( not based on Sharepoint).

If the charts are available in png format and we are able to specify
The file names then we would be are to grab them and use then on our mobile site.
By Nevron Support - 10 Years Ago
This is a very strange requirement, but anyway you may not need to go through a temporary file to do that.

First the Chart Web Part is fully AJAXed, meaning that even the generated images are served defferly in separate POST requests.
For modern browsers (IE 8.0 and higher, Chrome, FF, etc.) the images are usually packed in the response (as base64 encoded images).
Anyway the server command that generates HTML that contains a generated image is RefreshWebPart.

So it may be only necessary to send an HTTP request to the SharePoint server and the NChartCommander.aspx handler,
and it will respond with an HTML that you need to embed in your HTML page. This of course means that the SharePoint site running the chart is kind of public.

Of course there may be more details about this type of integration, but I think we can implement them as part of our consulting services.
Please contact sales@nevron.com if you are interested in having Nevron develop this type of integration for you.
By Jonathan Green - 10 Years Ago
The SharePoint site would not be public.

We simply need to generate named png images of the nevron charts that we have created in SharePoint to a temp folder.

We would then use a script to push the png images to our mobile site.

This look to be possible with the .net version but not with the SharePoint version of nevron?

By Nevron Support - 10 Years Ago

This code will help you automatically save your charts as .png files on the server:

using System.Drawing;
using Nevron.GraphicsCore;
using Nevron.Chart;
using Nevron.Chart.View;
using Nevron.ReportingServices;

namespace MyNamespace
{
                /// <summary>
                /// Sample class
                /// </summary>
                public class MyClass
                {
                                /// <summary>
                                /// Main entry point
                                /// </summary>
                                /// <param name="context"></param>
                                public static void RSMain(NRSChartCodeContext context)
                                {
                                                using (NChartRasterView view = new NChartRasterView(context.Document, new NSize(400, 300), NResolution.ScreenResolution))
                                                {
                                                                using (NRasterImage image = view.RenderImage(new NPngImageFormat()))
                                                                {
                                                                                image.SaveToFile("c:\\chartimage.png", new NPngImageFormat());
                                                                }
                                                }
                                }
                }
}