Saving a jqPlot graph to an image file

user2023359 picture user2023359 · Feb 14, 2013 · Viewed 9.9k times · Source

I am using jqPlot to display many graphs on some webpages. I am wanting to be able to save these graphs to an image file.

What is the best way to do this? Is it possible to have a right click menu option on the graph that enables the graph to be saved to an image file?

Here is some code for one of my graphs:

var plotCogsLineGraph = $.jqplot('FinancialsLineGraph', [[30,31,34,40,45], [34,38,31,42,38]], 
{ 
            axes:
            {
                xaxis:
                {
                      ticks: ['5','4','3','2','1']
                },
                yaxis:
                {
                    label:'%',
                    pad: 1.05,
                    ticks: ['0','15','30','45','60']
                }
            },

            width: 480, height: 270,
            legend:{show:true, location: 's', placement: 'insideGrid', renderer: $.jqplot.EnhancedLegendRenderer},
    seriesDefaults: 
    {
                rendererOptions: {smooth: true}
    },
    series:[ 
                {
                    lineWidth:1, 
                    label:'COGS',
                    markerOptions: { size:1, style:'dimaond' }
                }, 
                {
                    lineWidth:1, 
                    label:'Wages',
                    markerOptions: { size: 1, style:"dimaond" }
                }
                ]
    }
); 

What needs to be added to this above code to enable saving the graph to an image file?

Answer

Liang picture Liang · Aug 1, 2013

Try this:

$('#FinancialsLineGraph').jqplotSaveImage()