Google API for Charts

Google API for Charts

Postby byron.hopp » Tue Aug 08, 2023 11:20 pm

When using Google API for Charts in a WinForms application is there a way to return the chart drawn by Google in a graphic file format so it can be displayed in the Winforms app dialog, and printed, and so on?
Thanks,
Byron Hopp
Matrix Computer Services
byron.hopp
 
Posts: 382
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA

Re: Google API for Charts

Postby Antonio Linares » Wed Aug 09, 2023 6:45 am

Dear Byron,

From javascript you can use this:
Code: Select all  Expand view
// Get the element you want to capture as a screenshot
const targetElement = document.getElementById('elementId'); // Replace 'elementId' with the ID of the element you want to capture

// Create a temporary canvas
const canvas = document.createElement('canvas');
canvas.width = targetElement.offsetWidth;
canvas.height = targetElement.offsetHeight;

// Capture the element's image onto the canvas
const context = canvas.getContext('2d');
context.drawWindow(
  window,
  targetElement.getBoundingClientRect().left,
  targetElement.getBoundingClientRect().top,
  targetElement.offsetWidth,
  targetElement.offsetHeight,
  'rgb(255,255,255)'
);

// Create a link to download the screenshot
const screenshotImage = canvas.toDataURL('image/png');
const downloadLink = document.createElement('a');
downloadLink.href = screenshotImage;
downloadLink.download = 'screenshot.png';
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
 


From FWH you may use oWnd:SaveToBmp( cBmpFile )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42065
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Google API for Charts

Postby byron.hopp » Wed Aug 09, 2023 7:18 am

Thank you, I will try this out.
Thanks,
Byron Hopp
Matrix Computer Services
byron.hopp
 
Posts: 382
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 57 guests