1

現在、Highcharts を使用する既存のアプリケーションを持っています。アプリケーション内のすべてが完全に機能し、すべてのブラウザーで機能します。グラフは、すべて異なる色の複数のシリーズで構成されています。

最近、PhantomJS を使用して、さまざまなアプリケーション ページから自動化された PDF レポートを生成する機能をサーバー側に追加しました。Highcharts でレンダリングされたグラフを含みます。

次のコマンドを使用してこれを行います。

phantomjs convertpage.js url file size

convertpage.js には以下が含まれます。

var page = require('webpage').create(),
system = require('system'),
address, output, size;

if (system.args.length < 3 || system.args.length > 5) {
    console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
    console.log('  paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
    phantom.exit(1);
} else {
    address = system.args[1];
    output = system.args[2];
    page.viewportSize = { width: 600, height: 600 };
    if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
        size = system.args[3].split('*');
        page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
                                       : { format: system.args[3], orientation: 'portrait', margin: '1cm' };
    }
    if (system.args.length > 4) {
        page.zoomFactor = system.args[4];
    }
    page.open(address, function (status) {
       if (status !== 'success') {
            console.log('Unable to load the address!');
            phantom.exit();
       } else {
        var timeout = address.indexOf('graphs')>-1 ? 20000 : 500;
        console.log('Timeout: '+timeout);
        window.setTimeout(function () {
            page.render(output);
            phantom.exit();
        }, timeout);
    }
 });
}

チャートをレンダリングしているアプリケーションページで、次の方法でシリーズを設定しています。これは、ブラウザーを介してページ自体でうまく機能しています。

$.each(dbFields, function (key, field){
    var tmp = new Object();
    tmp.name = fieldsObject[key];
    tmp.color = colorsObject[key];
    tmp.data = filtered[field];
    tmp.min = 0;
    tmp.lineWidth = 1.5;
    seriesCalculated.push(tmp);
});

ただし、上記のスクリプトと PhantomJS を使用して生成すると、色も線の太さも適用されません...各シリーズの非常に太いライトグレーの線です。

どんな助け/アイデアも大歓迎です!

間違った出力のサンプルはここにあります

4

0 に答える 0