Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving a jqPlot graph to an image file

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?

like image 742
user2023359 Avatar asked Dec 04 '25 06:12

user2023359


1 Answers

Try this:

$('#FinancialsLineGraph').jqplotSaveImage()
like image 52
Liang Avatar answered Dec 06 '25 18:12

Liang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!