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.
I have followed the example as seen under "Using as a Node.js Module" here: https://github.com/highcharts/node-export-server . This example uses the following javascript object as input data for the chart:
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:
(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:
{ 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:
(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.
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. 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.
Is there something that would cause the exporter to be unable to parse the input data object if converted from a clojure map? 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. In the example, killPool
is called in the callback function passed into export
. In your version, you call killPool
immediately after calling export so chart generation likely does not have time to finish. I suspect this is causing the error.
The updated ClojureScript would look like this:
(doto Highcharts
(.initPool)
(.export test-chart (fn [err res]
(when err (println "****" err))
(.killPool Highcharts))))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.