@Test
public void testGenerateChart() throws Exception {
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
webClient.getOptions().setCssEnabled(true);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.waitForBackgroundJavaScript(25);
final HtmlPage page = webClient.getPage("https://www.chartjs.org/samples/latest/charts/bar/vertical.html");
Window window = page.getEnclosingWindow().getScriptableObject();
int i = 0;
do {
System.out.println("start animation " + i);
i = window.animateAnimationsFrames();
System.out.println("end animation");
} while (i > 0);
HtmlCanvas canvas = page.querySelector("#canvas");
HTMLCanvasElement picelem = (HTMLCanvasElement) canvas.getScriptableObject();
String png = picelem.toDataURL("image/png");
System.out.println(png);
byte[] decodedBytes = Base64.getDecoder().decode(png.substring(22));
String filename="D:/temp/chart.png";
FileUtils.writeByteArrayToFile(new File(filename), decodedBytes);
}
}
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too