Skip to content

chartjs image is not correct #328

Description

@huyit88
@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);      
    }
}

Real result:
chart

Expected:
correct

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions