Skip to content

Add option to export graph data to table, csv, Excel #580

Open
dnschnur opened this Issue Sep 28, 2012 · 9 comments

1 participant

@dnschnur
Flot member

Original author: otis.gos...@gmail.com (April 01, 2011 20:17:25)

It would be great to be able to export the data from the graph into an inline HTML table, or csv, or Excel. The use-case is that while graphs are great for a bigger picture, people sometimes need to inspect individual data points, and making it possible to get a "dump" of them would make this possible.

Original Q on the ML: http://groups.google.com/group/flot-graphs/browse_thread/thread/5d6dd184dcc58cdf

Original issue: http://code.google.com/p/flot/issues/detail?id=501

@dnschnur
Flot member

From otis.gos...@gmail.com on April 02, 2011 04:12:54
Flotr has this functionality and it looks great. See http://gr5.org/flotr2a/examples/data-download.html . Flotr's home page is at http://solutoire.com/flotr/ .

@dnschnur
Flot member

From olau%iol...@gtempaccount.com on April 04, 2011 12:02:20
Hey!

It seems valuable. However, this is definitely something that should be done either in a plugin or outside Flot, in the interest of not complicating things too much. If you're interested in working on it and gain eternal fame, I suggest you go ahead and post your results to the mailing list.

@dnschnur
Flot member

From otis.gos...@gmail.com on April 04, 2011 16:40:13
Right. Marking this as WontFix may not be good for building a community of contributors, though. I think WontFix will hide this issue, so anyone looking to gain the fame you speak of by implementing the missing features will not see this issue, which is an opportunity to build something that people are asking for. Maybe you can leave it open or change the status to something that signals "community wants this, but it has to be a plugin, and not in the core".

@dnschnur
Flot member

From olau%iol...@gtempaccount.com on April 04, 2011 17:27:59
Sorry. I tend to agree with you, and as you can see, there are indeed quite a bunch of issues open in the issue tracker - it's mostly that as long as nobody is backing them up somehow, they do tend to clutter the whole thing. People generally mostly work on what they need themselves, so if you don't do it, this issue could sit here for many years.

But never mind, I'll reopen it for now. Maybe someone will pick it up. Thanks for reporting it anyway, forgot to say that before.

@dnschnur
Flot member

From otis.gos...@gmail.com on April 04, 2011 21:08:23
Thank you for being open to suggestions like this. +1.

@dnschnur
Flot member

From busk...@gmail.com on July 27, 2012 19:45:15
I can export as a PDF. It works on IE 9, Firefox and Chrome. If u want more information u can ask me.

@dnschnur
Flot member

From otis.gos...@gmail.com on July 28, 2012 00:31:13
Yes, I'm curious how you are doing it?

@dnschnur
Flot member

From busk...@gmail.com on August 13, 2012 19:16:00
;) ok here we go... hope this can help u (IT WORKS FOR ME):
First of all i edit the jquery.flot.js file and add it the line:

c.id = 'canvas_'+cls;

this goes into the function: function makeCanvas(skipPositioning, cls)---->

function makeCanvas(skipPositioning, cls) {
var c = document.createElement('canvas');
c.className = cls;
c.width = canvasWidth;
c.height = canvasHeight;

--->        c.id = 'canvas_'+cls;

This is very important because flot doesnt generate the canvas with an ID...

The next step:
include this on your html page->

U can obtain those files in -> http://www.nihilogic.dk/labs/canvas2image/

So now we have the id of the canvas that we want to convert to an image... Make a function like:

function print(){
//CONVERT YOUR CANVAS TO PNG
var oCanvas = document.getElementById("canvas_base");
var strDataURI = oCanvas.toDataURL();
var oImgPNG = Canvas2Image.saveAsPNG(oCanvas, true);

        //insert the image in the div PLACEHOLDER...
        document.getElementById("placeholder").appendChild(oImgPNG);

        //submit your form for exporting to pdf..
        document.getElementById("id_pagina").value = document.getElementById("grafico").innerHTML;
        document.id_hoja_impr.submit();

}

so thats it... my html for example looks like this..

and in impime_graf.php i have something like this:

require '../inc/pdfcrowd/pdfcrowd.php';
$grafico = $_POST["id_pagina"];
try
{

// create an API client instance
$client = new Pdfcrowd("...", "...");
// THIS STR_REPLACE is neccesary if the image is out of range...
$html = str_replace("http://www.google.com/');
$pdf = $client->convertHtml($html);

// set HTTP response headers
header("Content-Type: application/pdf");
header("Cache-Control: no-cache");
header("Accept-Ranges: none");
header("Content-Disposition: attachment; filename=\"grafico_pareto.pdf\"");

// send the generated PDF
echo $pdf;

}
catch(PdfcrowdException $why)
{
echo "Pdfcrowd Error: " . $why;
}

C.Knopel
Valdivia, Chile
08-2012

@dnschnur
Flot member

From busk...@gmail.com on August 13, 2012 19:19:47
it works with dompdf too... i have some problems with accents and special characters, so if u can help me with would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.