与木偶戏的高图

时间:2019-08-06 07:32:40

标签: node.js highcharts puppeteer

下面的代码可以很好地执行,但是呈现的PDF不会显示pdf系列。其余所有报告的组成部分均以PDF格式显示。请添加评论以帮助相同。

高位图和木偶。没有highchart导出服务器。

/**
 * This file creates a highchart, 
 * no html page is required.  The html is crafted
 * within this script.
 */
const puppeteer = require('puppeteer')
const fs = require('fs')

async function run() {

   const browser = await puppeteer.launch({
        headless: true
    })
    // const browser = await puppeteer.launch({
    //     headless: false,
    //     slowMo: 2000,
    //     devtools: true
    // })

   const page = await browser.newPage()

   const loaded = page.waitForNavigation({
        waitUntil: 'load'
    })

   const html = 

    `<!DOCTYPE html>
        <html lang="en">
            <head>
                <meta charset="UTF-8">
                <title>Highcharts Test 4</title>
            </head>
            <body>
                <div id="container" style="width:100%; height:400px;"></div>
            </body>
        </html>`

   await page.setContent(html)
   await loaded

   async function loadChart() {

       page.evaluate( fs.readFileSync('./lib/highcharts/highcharts.js', 'utf8'));

       await page.evaluate(async (fs) => {

           console.log('page.evaluate Highcharts.version=' + Highcharts.version)

           var myChart = Highcharts.chart('container', {
                chart: {
                    type: 'bar'
                },
                title: {
                    text: 'Fruit Consumption'
                },
                xAxis: {
                    categories: ['Apples', 'Bananas', 'Oranges']
                },
                yAxis: {
                    title: {
                        text: 'Fruit eaten'
                    }
                },
                series: [{
                    name: 'Jane',
                    data: [1, 0, 4]
                }, {
                    name: 'John',
                    data: [5, 7, 3]
                }]
            });
        }, fs)
    }

    await loadChart()
    await browser.close()
}

run()

0 个答案:

没有答案