简体   繁体   English

使用ClojureScript中的highcharts节点导出服务器的问题 - “执行图表生成时出现0x03错误”

[英]Issues using highcharts node export server from ClojureScript - “0x03 error when performing chart generation”

I have a clojurescript app on Node.js, and am attempting to use the highcharts export server as a Node.js module in order to generate charts for the purpose of PDF generation. 我在Node.js上有一个clojurescript应用程序,并且我正在尝试将highcharts导出服务器用作Node.js模块,以生成用于生成PDF的图表。

I have followed the example as seen under "Using as a Node.js Module" here: https://github.com/highcharts/node-export-server . 我在这里按照“使用作为Node.js模块”中的示例进行了跟踪: https//github.com/highcharts/node-export-server This example uses the following javascript object as input data for the chart: 此示例使用以下javascript对象作为图表的输入数据:

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]
            }
        ]
    }
};

Replicating this example in clojurescript, defining the export settings as a clojurescript map and converting it back to a javascript object: 在clojurescript中复制此示例,将导出设置定义为clojurescript映射并将其转换回javascript对象:

(def test-chart (clj->js {: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]}]}}))

Logging the test-chart object to console confirms it's identical to the javascript object used in the example: 将测试图对象记录到控制台确认它与示例中使用的javascript对象相同:

{ type: 'png',  
  options: { title: { text: 'My Chart' },     
             xAxis: { categories: [Array] },     
             series: [{ type: 'line', data: [ 1, 3, 2, 4 ] },
                      { type: 'line', data: [ 5, 3, 4, 2 ] }] 
    } 
}

Further calling the required Highcharts functions to set up a phantom.js worker pool and generate the chart as seen in the example: 进一步调用所需的Highcharts函数来设置phantom.js工作池并生成图表,如示例所示:

(doto Highcharts
(.initPool)
(.export test-chart (fn [err res]
                      (when err (println "****" err))))
(.killPool))

When calling export with the converted clojure map as input data, the error "0x03 error when performing chart generation: please check your input data" is seen. 当使用转换后的clojure映射作为输入数据调用export时,会看到错误“执行图表生成时出现0x03错误:请检查输入数据”

The documentation example does work in regular Node.JS, but when calling export from clojurescript using input data converted from a clojure map, the export fails with this input data error. 文档示例在常规Node.JS中工作,但是当使用从clojure映射转换的输入数据从clojurescript调用导出时,导出会因此输入数据错误而失败。 As the converted object looks correct from console, and everything else should be identical just done through javascript interop, I am not sure what the issue could be here. 由于转换后的对象从控制台看起来是正确的,并且其他所有内容都应该通过javascript互操作完成,我不确定这里的问题是什么。

Is there something that would cause the exporter to be unable to parse the input data object if converted from a clojure map? 如果从clojure映射转换,是否会导致导出器无法解析输入数据对象? Or could the issue be something else, and checking input data is a misleading error message? 或者问题可能是其他问题,检查输入数据是误导性的错误信息?

Your ClojureScript code is not equivalent to the example code in the readme. 您的ClojureScript代码不等同于自述文件中的示例代码。 In the example, killPool is called in the callback function passed into export . 在示例中, killPool在传递给export的回调函数中调用。 In your version, you call killPool immediately after calling export so chart generation likely does not have time to finish. 在您的版本中,您在调用导出后立即调用killPool ,因此图表生成可能没有时间完成。 I suspect this is causing the error. 我怀疑这是导致错误的原因。

The updated ClojureScript would look like this: 更新后的ClojureScript如下所示:

(doto Highcharts
  (.initPool)
  (.export test-chart (fn [err res]
                        (when err (println "****" err))
                        (.killPool Highcharts))))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM