JulsMan / googlevisualizationsdotnet

Each Google visualization is wrapped in a ASP.NET Web Control. Add them to your toolbar and drag them into your markup. Use .NET data tables to populate the chart or graph.
4 stars 2 forks source link

Render as png and access in code behind #10

Open jeffmun opened 9 years ago

jeffmun commented 9 years ago

I'm ultimately trying to get google charts saved into a PDF. So it seems like the first step is exporting them as png. I've been able to render them on the page as an image by inserting the following into the AjaxCallback function (found in SendAndDraw.js) right before the draw method.

        /* to render as png */
        google.visualization.events.addListener(chart, 'ready', function () {
            container.innerHTML = '<img src="' + chart.getImageURI() + '">';
            console.log(container.innerHTML);
        });

        chart.draw(view, options);

However, I'm not sure how to save this as a file on the server or how to access the binary image data directly in code behind and skip the save to file part. All my google charts are being created dynamically (based on DataTables that the user creates by selecting the data they wish to view) and are dynamically placed into table cells depending on the number of charts needed.

I only really need these images when the user clicks "Export to PDF". Before that I want to render them natively so that the tool tips, etc. are available.

Working with JavaScript is really new to me so I'm not very clear about where to implement getting the binary image data for each chart on the page. Any thoughts?

JulsMan commented 8 years ago

I don't have an answer but i did have to work this out for my own project ... The getImageURI() works on the client page not the server, I understand that you want to convert the image on the server to a PNG then place it in the PDF. I had to do this too ... I eventually just used PDFCrowd to send the page in HTML to their service and they send me back a PDF stream. Googlecharts work well with their service.