Comments (7)
Hi @cvasseng -
I've got a basic "pass javascript source to http server" going. Next I'll continue to try to adapt our legacy code to it.
For anyone else's help, here's what I learned:
Original:
curl -H "Content-Type: application/json" -X POST -d '{"infile":{"title": {"text": "Steep Chart"}, "xAxis": {"categories": ["Jan", "Feb", "Mar"]}, "series": [{"data": [29.9, 71.5, 106.4]}]}}' 127.0.0.1:7801 -o mychart.png
becomes:
curl -H "Content-Type: application/json" -X POST -d '{"infile":"{title: {text: \"Steep Chart\"}, xAxis: {categories: [\"Jan\", \"Feb\", \"Mar\"]}, series: [{data: [29.9, 71.5, 106.4]}]}"}' 127.0.0.1:7801 -o mychart.png
- POST payload must be structured as
{"infile": "<javascript>"}
where the POJO source javascript has to be encapsulated in "s for string. - Quotes (") within must be escaped as
\"
. - Newlines must be escaped as
\n
. - TABs as whitespace throw off the compiler and must also be sanitized out.
If you're getting a message like:
SyntaxError: Unexpected token i in JSON at position 4
then the JSON compiler doesn't recognize your payload as javascript. Check that the body of your payload is enclosed in "s.
Thanks
-Bronius
from node-export-server.
Glad you got it working.
For reference, the POST valid arguments/format is documented here.
I'm closing this since it seems like it's working for you now. Please feel free to re-open this if you have any further issues with it.
Thanks.
from node-export-server.
Hi,
Are you passing the options directly to the export-function as an instanced object, or loading it from file first?
Functions are not completely supported when running as a node module. That said, I've made some tweaks, and added a sample that contains functions, and use the server as a node module here. This seems to be working fine.
Please let me know if you're still having issues after updating your copy of the server to the latest one.
from node-export-server.
Hi, great, no exceptions anymore if there are functions in the chart options. My function, however, does not seem to work correctly in your server. If I use this options file in highcharts export server, not all dataLabels are drawn (correct, see https://github.com/statabs-test/indikatoren/blob/issue-127/images/portal/4132.svg). Now, if I use your server in node.js mode, all dataLabels are drawn (not correct, see this code and this image).
I also tried using the server in CLI mode using this file and the following command line:
highcharts-export-server --batch "4132.json=4132.svg;"
and could not get it to work, I only ever got the the following error:
uncaughtException: [ReferenceError: func is not defined]
Can you help me get it to work and get the same results as on export.highcharts.com? Thank you very much!
from node-export-server.
Getting functions to work properly when using as a node module and passing instanced objects to the export function is non-trivial, which, along with keeping the options as valid JSON, is why it's not supported (or rather, the support ends at "it won't produce syntax errors, but functions are effectively ignored").
As of aad1a5a you can add custom formatters by using the customCode
option in module mode, which is a function executed before initializing the chart where the options can be mutated:
var exportSettings = {
options: {
//Options goes here
},
customCode: function (options) {
// Functions can be added here too
options.title = {
text: 'Changed through custom code!'
};
}
};
// init code here
exporter.export(exportSettings, ..);
A full sample can be found here.
I've also added JavaScript support to the infile
option, so functions should work as expected when using that now (infile
attribute when using as a node module, --infile
when using through CLI. Expects the argument to be a filename).
If you need to pass in formatter functions etc. in the options themselves the best way is to run the server in HTTP mode, which is what export.highcharts.com is doing. In HTTP mode, the input is treated the same as with --instr
(and now --infile
), which injects the options into phantom as JavaScript and not JSON (this is largely done for legacy reasons - ideally the export server would only support JSON as there's a lot of additional magic that needs to be done for the inject to work, and the dataOptions/globalOptions/customCode/resources arguments can handle the use cases where e.g. functions are necessary).
from node-export-server.
I appreciate the discussion and work here and am trying to follow along.. Awesome work!
I am rendering charts via curl/http on my locally hosted highcharts-export-server but am generating chart options as json from a PHP array (json_encode). I couldn't figure out how to eval the javascript functions (as OP above), but I found that customCode is working for me ok.
In the discussion above, it was advised to use customCode for node module but that original pojo options should work via curl/http. Is there a recommended way to load eval'able functions into the json options payload?
from node-export-server.
@bronius: If you pass in JavaScript instead of JSON, things should "just work" over HTTP.
e.g. this will be interpreted as straight up JavaScript:
{
chart: {}
}
while this will be passed into JSON.parse:
{
"chart": {}
}
You can see this by going to the official server, and entering pure JavaScript into the options text area.
from node-export-server.
Related Issues (20)
- column chart export https://export.highcharts.com/ 500 error HOT 1
- Cannot add series-on-point module to the export server HOT 3
- Highcharts.AST.allowedAttributes HOT 8
- Preview and download are not generating in windows HOT 2
- Different export results on the first and the second requests HOT 1
- Previous version output result error HOT 6
- v3: compiled CLI via pkg not working HOT 6
- Image with URL included in the exported chart only sporadically HOT 1
- Chart being not rendering correctly in case of file format: image/svg+xml HOT 3
- Chart options object is not available in the customCode context in current node-export-server (master) HOT 5
- Please add tags to repo which correspond to the current version HOT 2
- v4: dist folder missing HOT 4
- Startup error: no such file or directory, open '/usr/lib/node_modules/highcharts-export-server//msg/startup.msg HOT 2
- v4 'cachePath' with absolute path HOT 1
- v4: outdated example for Node.js module usage HOT 1
- v4: getting error HOT 6
- v4: make userDataDir configurable HOT 1
- Export server run issue for multiple request HOT 2
- Data Limit/Inefficient data transfer of chart data (options) to the browser HOT 1
- Highcharts cache folder HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-export-server.