Next
Prev
Save as Image
Save as PDF

This sample chart demonstrates how to save the chart to local PC. Try to click on the button at the bottom left of the chart or mouse over the top right of the chart.

function saveAsImage()
{
  // Check if the web browser is IE
  if(compIE())
    menus.items[0].callback();
}

function saveAsPDF()
{
  // Check if the web browser is IE
  if(compIE())
    menus.items[1].callback();
}

function compIE()
{
  var agent = navigator.userAgent;
  
  if( agent.indexOf("MSIE 7.0") > -1 || agent.indexOf("MSIE 8.0") > - 1 || 
      agent.indexOf("Trident 4.0") > -1) {
      
    alert("Sending the chart image to the server and saving the image file are not supported in IE7,8.");
    return false;
  }
  
  if(document.documentMode && document.documentMode <= 5) {
    alert("Sending the chart image to the server and saving the image file are not supported in Quirks mode");
    return false;
  }
  
  return true;
}

var menus = {
  options : {
    textField : "name", // for the menu item
    callbackField : "callback" // for the callback function when the menu item is clicked
  }, 
  items : [
    {
      name : "Save as PNG",
      callback : function(){
        KoolChart.downloadToLocal("KoolChart", "png", "http://www.koolchart.com/hsyu/downloadLocal.php", function(){
          return document.getElementById("chart1").saveAsImage();
        });
      }
    },{
      name : "Save as PDF",
      callback : function(){
        KoolChart.downloadToLocal("KoolChart", "pdf", "http://www.koolchart.com/hsyu/downloadLocal.php", function(){
          return document.getElementById("chart1").getSnapshot("jpeg"); // supports only JPEG 
        });
      }
    }
  ]
};

© 2017 KoolChart. All rights reserved.