FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Google API for Charts
Posts: 408
Joined: Sun Nov 06, 2005 03:55 PM
Google API for Charts
Posted: 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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Google API for Charts
Posted: Wed Aug 09, 2023 06:45 AM
Dear Byron,

From javascript you can use this:
Code (fw): Select all Collapse
// 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
Posts: 408
Joined: Sun Nov 06, 2005 03:55 PM
Re: Google API for Charts
Posted: Wed Aug 09, 2023 07:18 AM

Thank you, I will try this out.

Thanks,

Byron Hopp

Matrix Computer Services

Continue the discussion