DanielAttard
DanielAttard

Reputation: 3615

How to save Legend with a FLOT chart

I am using FLOT to create a chart. Because I have upgraded to version 0.8.1 of the FLOT javascript library, this allows the chart axis to be saved with the canvas. The only issue I am having is that the chart legend is not being saved to the chart.

What do I need to do to get the legend onto my canvas?

Here is the HTML:

<div class="widget" id="flot_widget" data-collapsed="false" data-collapsible="true" data-icon="buildings" >
<h3 class="handle">Market Data for: <input  type="text" 
    placeholder="Municipality"  
    id="flotAverageSalePricesCity"
    style="float:inherit; font-size: 15px; width:90px;"     
    required 
    data-regex="^[a-zA-Z. ]+$" /> 
    <span id="c3"></span>
</h3>
<div class="demo-container" id="demo-container" style="display:none; ">
    <div id="placeholder" class="demo-placeholder" ></div>        
</div>
</div>

and here is the javascript:

$("#flotAverageSalePricesCity").result(function(event, data, formatted) {
if (data){
    $.ajax({ 
        url: sURL + "utility/ajaxmuniChart1c",
        type: "POST",
        data: {muni: data[0]},
        dataType: 'json',               
        success: function(json){
            if  (data) {                    
                myWidth =  (document.getElementById('flot_widget').offsetWidth-15)+"px";
                myHeight = (document.getElementById('flot_widget').offsetWidth*.66)+"px";
                document.getElementById('demo-container').style.display = 'block';                  
                document.getElementById('placeholder').style.width = myWidth;
                document.getElementById('placeholder').style.height = myHeight;                 
                var options = {
                    canvas: true,
                    series: {
                        lines: { show: true, fill: false, fillColor: "rgba(255, 255, 255, 0.8)" },
                        points: { show: true, fill: true }
                    }
                }; 
                if (document.getElementById('c3').childElementCount > 0){
                    document.getElementById('c3').innerHTML = "";
                };                                      
                var plotArea = $.plot("#placeholder", [json], options);                 
                var ctx = plotArea.getCanvas();                                 
                loc = sURL + 'php/saveme.php';
                var cs = new CanvasSaver(loc);                  
                var btnDownload = cs.generateButton('Download', ctx, 'PTS_Chart');                  
                c3.appendChild(btnDownload);                    
            }
        }
    })
}
})

Thanks for the help.

Upvotes: 0

Views: 727

Answers (1)

DNS
DNS

Reputation: 38199

Currently this is not possible in-page. You'll need to use a whole-page renderer like WKHTML2PDF.

Rendering the legend to canvas is one of the main projects for Flot 0.9.

Upvotes: 2

Related Questions