highcharts / node-export-server

Highcharts Node.js export server
Other
354 stars 260 forks source link

Unable to export chart using HTTP server #51

Closed pcbulldozer closed 2 years ago

pcbulldozer commented 7 years ago

I'm new to this, but I cannot seem to get the HTTP server to return an actual chart. All i get are (image) files with the text "Chart input data error - TypeError: Request keys of a value that is not an object"

I've tried nodejs v4 and v6 I've tried highcharts-export-server v1.0.10, v1.0.14 and v1.0.15

Once starting the server, I've tried two charts:

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]}]}}' localhost:1337 -o mychart1.png

curl -H "Content-Type: application/json" -X POST -d '{"scale":1,"constr":"Chart","width":600,"infile":{"chart":{"type":"bar"},"title":{"text":"Fruit Consumption"},"xAxis":{"categories":["Apples","Bananas","Oranges"]},"yAxis":{"title":{"text":"Fruit eaten"}},"series":[{"name":"Jane","data":[1,0,4]},{"name":"John","data":[5,7,3]}]}}' localhost:1337 -o mychart2.png

Perhaps the problem is in the way I'm installing everything? Working on Ubuntu 14.04, installed the whole lot using:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - sudo apt-get install nodejs sudo ln -s /usr/bin/nodejs /usr/bin/node sudo ln -s /usr/bin/nodejs /usr/sbin/node sudo npm install highcharts-export-server@1.0.10 -g

Finally, starting the HTTP server itself using:

highcharts-export-server --enableServer 1 --host localhost --port 1337 --logLevel 4

Since the server runs --logLevel 4, this is the output produced by the server process for each of the two chart generation attempts above:

{ outfile: 'tmp/chart.3d33ee22cb254ecd941e8d058ef7b89d.png', instr: { title: { text: 'Steep Chart' }, xAxis: { categories: [Object] }, series: [ [Object] ], chart: { width: 600, height: 400 }, exporting: { enabled: false } }, constr: undefined, type: 'png', scale: undefined, width: false, svg: undefined, resources: false, callback: false, styledMode: false, asyncRendering: false, globalOptions: false, themeOptions: 'false', customCode: false, dataOptions: false, async: false, reqID: '3d33ee22cb254ecd941e8d058ef7b89d' }

{ outfile: 'tmp/chart.d65b4964f13a420290c2b22fa801a366.png', instr: { chart: { type: 'bar', width: 600, height: 400 }, title: { text: 'Fruit Consumption' }, xAxis: { categories: [Object] }, yAxis: { title: [Object] }, series: [ [Object], [Object] ], exporting: { enabled: false } }, constr: 'Chart', type: 'png', scale: 1, width: 600, svg: undefined, resources: false, callback: false, styledMode: false, asyncRendering: false, globalOptions: false, themeOptions: 'false', customCode: false, dataOptions: false, async: false, reqID: 'd65b4964f13a420290c2b22fa801a366' }

Fresh out of ideas, so anything welcome.

shijingxiang commented 7 years ago

I have encountered the same problem with v1.0.15. At last, i found that , the infile field requries an string, not a object. That is, you can try it like below: 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:3000 -o mychart.png

shivajain commented 6 years ago

I am also struggling with somehow same problem: When I sent request through postman application, I am getting this error: Thu Jun 07 2018 15:01:10 GMT+0530 (India Standard Time) [error] socket error: { Error: Parse Error, bytesParsed: 0, code: 'HPE_INVALID_METHOD', Packet:<Buffer 16 03 01 02 00 01 00 01 fc 03 03 74 3d ad 38 d0 cb 27 88 ec 95 9b c7 4c 87 9a 09 ed 26 7e ad 74 5d 90 50 7c ba ec 7d 26 28 c1 b1 20 3d f3 80 05 92 54 .. > }

My Postman request is : URL: https://localhost:3003 Content-Type:application/json Body: { "xAxis": { "categories": [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]x }, "series": [ { "data": [1,3,2,4], "type": "line" }, { "data": [5,3,4,2], "type":"line" } ] }

PaulDalek commented 2 years ago

HTTP exports work as expected (tested on: https://github.com/highcharts/node-export-server/tree/enhancement/puppeteer).