Saving jqplot charts as image

1,665 views
Skip to first unread message

schabagh

unread,
Aug 1, 2014, 8:14:26 AM8/1/14
to jqplot...@googlegroups.com
Hi,

how can I save a jqplot charts as image?

Thanks

Brian Maschhoff

unread,
Aug 1, 2014, 11:47:52 AM8/1/14
to jqplot...@googlegroups.com

Add a function like:

 

   createImagePlot = function(){

                //after creating your plot do

                var imgData = $('#plot').jqplotToImageStr({}); // given the div id of your plot, get the img data

                var imgElem = $('<img/>').attr('src',imgData); // create an img and add the data to it

                $('#imgChart').append(imgElem);// append the img to the DOM

   }

 

Then add a div element with id=’imgChart’ and a button or something for calling createImagePlot after first generating the plot in a div with id=’plot’

 

To save, you then right click on image as usual – although javascript could possibly be used to trigger that automatically.

--
You received this message because you are subscribed to the Google Groups "jqplot-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jqplot-users...@googlegroups.com.
To post to this group, send email to jqplot...@googlegroups.com.
Visit this group at http://groups.google.com/group/jqplot-users.
For more options, visit https://groups.google.com/d/optout.

schabagh

unread,
Aug 1, 2014, 2:34:44 PM8/1/14
to jqplot...@googlegroups.com
Hi Brian,

thanks for your reply. I need an javascript-example for save an image and without right click. I would like to save the chart as an image with a button.

Thanks

Brian Maschhoff

unread,
Aug 1, 2014, 2:42:27 PM8/1/14
to jqplot...@googlegroups.com

You might google something like ‘Jquery simulate right click save as’ and look for a solution. I haven’t tried it. Perhaps someone else on this list has.

 

B.

Andy Shepherd

unread,
Aug 8, 2014, 10:11:34 AM8/8/14
to jqplot...@googlegroups.com
Some good stuff here


I think the following might work... if not google around this code, I found it from somewhere.....

Button
<a href="#" class="smlbtn" onClick="boob(div)">png</a>


Function

    function boob(mydiv){
        var img = $('#'+mydiv).jqplotToImage(50, 0);
        if (img) {
            open(img.toDataURL("image/png"));
        }
    }

Eugene De Villiers

unread,
Aug 11, 2014, 3:15:12 AM8/11/14
to jqplot...@googlegroups.com
This functionality was added as part of the library.

$('#chartdiv').jqplotToImageStr({});

Hope it helps!
Reply all
Reply to author
Forward
0 new messages