将参数注入节点模块时出现问题

时间:2017-08-24 07:01:31

标签: javascript node.js highcharts asp.net-core highmaps

上下文

我目前正在开发一个引擎,用Asp.Net Core生成HighMaps脚本。

为了做到这一点,我使用API​​ Microsoft.AspNetCore.NodeServices 来执行HighChart提供的节点模块(参见https://github.com/highcharts/node-export-server)。

我已按照此链接实施解决方案https://davidsekar.com/angular/server-side-rendering-of-highcharts-in-net-core

问题

我的代码包含在下面:

节点模块

/**
 * https://github.com/highcharts/node-export-server
 */

const exporter = require('highcharts-export-server');

// Set up a pool of PhantomJS workers
let config = {
    maxWorkers: 10,
    initialWorkers: 5,
    reaper: true,
    listenToProcessExits: true
};
// exporter.logLevel(4);
exporter.initPool(config);

// Export settings 
// var exportSettings = { type: 'png', options: { title: { text: 'My Chart' }, xAxis: { categories: ["Jan", "Feb", "Mar", "Apr", "Mar", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] }, series: [{ type: 'line', data: [1, 3, 2, 4] }, { type: 'line', data: [5, 3, 4, 2] }] } };

module.exports = {
    generateHighChart: (callback, configurationHighMaps) => {
        try {

            //console.log(configurationHighMaps);

            console.log(exporter);

            //var exportSettings2 = { type: exportSettings.type, options: exportSettings.chartOptions, scale: 2, sourceWidth: '1170', sourceHeight: '300' };

            // Perform an export
            // Export/Chart settings corresponds to the available CLI arguments.
            exporter.export(configurationHighMaps,
                (err, res) => {

                    // try {
                    // The export result is now in res.
                    // If the output is not PDF or SVG, it will be base64 encoded (res.data).
                    // If the output is a PDF or SVG, it will contain a filename (res.filename).
                    // exporter.killPool();
                    // process.exit(1); Immediate exit will cause error in .Net Core NodeServices
                    //} catch (innerError) {
                    //  exporter.log(4, 'Kill throws error : ' + innerError);
                    //}
                    //callback(err, res);
                    callback(err, JSON.stringify(res));
                });
        } catch (err) {
            callback(err, null);
        };
    }
};

// For testing
// exp.generateHighChart(function () { }, exportSettings);

控制器:

private async Task<StructureFichier> GenererCarteStatistiqueAsync(ConfigurationHighMaps poConfigurationHighMaps)
    {
        JObject loConfigurationHighMaps = JObject.FromObject(poConfigurationHighMaps);

        string lbytFichier = await mNodeServices.InvokeExportAsync<string>(@"wwwroot\HighMaps\v5\Moteur\MoteurHighMaps.js",
                                                                            "generateHighChart",
                                                                            loConfigurationHighMaps.ToString());

        string lsrCheminComplet = Directory.GetCurrentDirectory() + "/modeles/" + "test.png";

        //System.IO.File.WriteAllBytes(lsrCheminComplet, lbytFichier);

        return new StructureFichier(lsrCheminComplet);
    }

当我执行方法GenererCarteStatistiqueAsync时,我遇到InvokeExportAsync引发的错误。

  

调用节点模块失败,错误:未给出输入

问题

我提供的参数有什么问题?

0 个答案:

没有答案