highcharts / node-export-server

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

Load event drawing #75

Closed benmann497 closed 7 years ago

benmann497 commented 7 years ago

Hello, we're adding a line to a chart using the chart.events.load function. This works fine in the browser, but isn't rendering when using the node export server.

Is there an alternative or a setting to make the load event fire?

Thanks.

cvasseng commented 7 years ago

Hi,

how are you POSTing to the server? It needs to be formatted as JavaScript rather than JSON for function callbacks to work (i.e. no escaping of properties).

benmann497 commented 7 years ago

Hi,

Thanks for the response. I am using the Node module, so am passing in a JS object with properties. Below is an example of the chart property, with load event. I have simplified the code for calculating where to draw the line, but even with static values it doesnt show...

chart: {
        type: 'column',
        backgroundColor: '#F8F9FA',
        events: {
          load: function () {
            const renderer = this.renderer;

            const lineWidth = 2;
            const xPlotPoint = 50;
            const yStartPlotPoint = 150;
            const yEndPlotPoint = 250;

            renderer.path(['M', xPlotPoint, yStartPlotPoint, 'L', xPlotPoint, yEndPlotPoint])
              .attr({
                'stroke-width': lineWidth,
                stroke: 'red',
                dashstyle: 'solid',
                zIndex: 5
              })
              .add();
          }
        }
      }

Thanks.

cvasseng commented 7 years ago

Unfortunatly, function when using the export server as a node module is not fully supported.

This has to do with having to serialize the options to pass them to phantomjs.

While we do have this kind of support on our radar, I can't give you an ETA right now on when/if it may be imlemented.

The only workaround currently is using either customCode or callback - the former may work for you.

Also, if you manage to transform your options into to a JavaScript string and pass that in as the options, everything should work as expected.

jb3-2 commented 7 years ago

Hi, if it's of any help: Actually I have just managed to have the export server export charts with quite elaborate functions in the load event. I do this by using export server's 'infile' property to load the chart options file which contains the functions.

benmann497 commented 7 years ago

Thanks for these, I will give them a go shortly.

benmann497 commented 7 years ago

Hello,

I was able to get this working by passing null as the dataOptions and customCode to add the load event.

Thanks for your help.

jb3-2 commented 7 years ago

Great, thanks for letting getting back on this!