0

Had installed both phantomjs and highcharts export server on my local machine. I'm running a script through phantomjs similar to https://joekuan.wordpress.com/2012/09/22/phantomjs-a-new-way-for-running-highcharts-on-the-server-side/

var svg = page.evaluate(function(opt) {

    Highcharts.setOptions ( {
      exporting: {
        url:'http://myserver:8080/export/'
      }
    } );

...

}, evalArg);

page.render(outputFilename); // save as png
phantom.exit();

It still able to save image even though myserver is down.

var chartOptions = {
   chart: {
       renderTo: 'container'
    },
    exporting: {
       url: 'http://myserver:8080/export/'
    },
    ...
};
var chart = new Highcharts.Chart(chartOptions);

Specifying the url under the chartOptions also doesn't help. It still able to save image even though myserver is down.

I even tried add it to

  return chart.getSVG({
      exporting: {
          url: 'http://myserver:8080/export/'
      }        
   });

but to no avail. Note: specifying the first option in jsp before the chart load works. Highcharts.setOptions ( { exporting: { url:'http://myserver:8080/export/' } } );

Anyone has any idea what's the correct way of passing my local export server url to Highcharts.

Thanks

zephyr -
  • 11
  • 3
  • Downloaded exporting.src.js and modified as follows: getSVG: function (additionalOptions) { var chart = this, chartExportingOptions = chart.options.exporting, chartCopy, ... sourceHeight, exportUrl, ...; – zephyr - Feb 11 '15 at 06:45
  • ... sourceHeight = options.exporting.sourceHeight || options.chart.height || (/px$/.test(cssHeight) && parseInt(cssHeight, 10)) || 400; exportUrl = options.exporting.url || chartExportingOptions.url; // override some options extend(options.chart, { animation: false, ... height: sourceHeight, exporting: { url: exportUrl } }); – zephyr - Feb 11 '15 at 06:49
  • Still not working. I don't see this in local exporting server if I ran the script through phantomjs. Feb 11, 2015 2:57:30 PM com.highcharts.export.interceptor.RequestInterceptor afterCompletion INFO: Time=Wed Feb 11 14:57:30 SGT 2015 :: Time taken(ms) 943 :: RequestMethod POST :: Status 200 :: Referer=http://myserver:8080/myApp/xxx.htm Feb 11, 2015 2:57:30 PM com.highcharts.export.interceptor.RequestInterceptor afterCompletion INFO: request count: 1, Error count: 0, Elapsed time (min): 13, Rate: 0 – zephyr - Feb 11 '15 at 07:00
  • Even revert exporting.src.js and modified as follows: // Add the export related options defaultOptions.exporting = { //enabled: true, //filename: 'chart', type: 'image/png', // url: 'http://export.highcharts.com/', url: 'http://myserver:8080/export/', it works even the local Highcharts exporting server is not started. Anyone know why? Thanks – zephyr - Feb 11 '15 at 07:21
  • I re-read the Export module @ http://www.highcharts.com/docs/export-module/export-module-overview. At the bottom, there is a section "Saving images without using the export server. Some modern browsers also support saving content from HTML5 canvas directly. This can be used as a way of exporting charts without involving any server side conversion. Since Highcharts is drawn in SVG, we need a way to convert it to a HTML5 canvas. A library called canvg does a great job here ". Think because of this, export server is not called, so it doesn't matter what url you set. Am I correct? – zephyr - Feb 11 '15 at 08:08
  • I'm sorry, but above solution by Joe is to render charts on the server side. Meanwhile you are trying to replace Highcharts exporting server. I think you should install [this exporting server](http://www.highcharts.com/docs/export-module/setting-up-the-server). - which is not only phantomJS based. Highcharts are sending SVG data to the exporting server, while Joe's solution requires JSON options. – Paweł Fus Feb 11 '15 at 15:44
  • Hi Pawel, what I'm trying to do is to render charts on the server side as well as using the Highcharts exporting server on my local server. I had downloaded the codes from github, build the source and deploy the highcharts-export-web.war to Tomcat. The rendering works fine, but I'm not sure where it sends the SVG data to. I want it to send to the local exporting server instead of Highcharts default one. Hope this clarifies. – zephyr - Feb 12 '15 at 03:08
  • http://myserver:8080/export/ is the url for Highcharts exporting server on my local server. – zephyr - Feb 12 '15 at 03:14
  • I just have tried to set any URL in the chart options: http://jsfiddle.net/b5y1ejfL/ - as you can see chart isn't exported, it's returning an error. The only thing comes to my mind is to update Highcharts library, maybe you are using version with some bug? – Paweł Fus Feb 12 '15 at 14:32
  • I'm using Highcharts JS v3.0.1, from Anna's post in http://stackoverflow.com/questions/8802528/how-to-save-an-image-of-the-chart-on-the-server-with-highcharts, she got the chart.getSvg() then do a post to the exporting server. Your reply "getSVG() creates copy of a chart from initial options and creates SVG" at http://stackoverflow.com/questions/17349258/highcharts-chart-getsvg-inconsistent-with-svg-on-the-page seem to suggest that when creating SVG no exporting server required. Thanks for your help. – zephyr - Feb 13 '15 at 07:25
  • You are using outdated version of Highcharts, try to upgrade to 4.0.4. Anyway, it would be great to know what exactly you want to achieve. – Paweł Fus Feb 13 '15 at 10:12

0 Answers0