Sign in to follow this  
jonthemiller

exportChart and hasRendered

Recommended Posts

Getting an error when trying to auto-save to server. The right click and save works fine, just using javascript to do the export doesn't, the error being that .hasRendered() and .exportChart() are said to not be functions by Firebug.

 

Here's my relevant code:

 

 

 

function createLineChart() {

 

var lineChart = new FusionCharts("../Charts/Line.swf", "lineChart", "1135", "600", "0", "1");

 

lineChart.setDataXML(<%= @line_string %>);

 

lineChart.render("lineChartDiv");

 

}

 

function ExportMyChart() {

 

var chartObject = getChartFromId("lineChart");

 

if(chartObject.hasRendered()) {

 

chartObject.exportChart( {exportFormat: "JPG"} );

 

}

 

}

 

 

 

<%= javascript_tag("createLineChart();") %>

 

<%= javascript_tag("ExportMyChart();") %>

 

 

 

It works when done manually, but I'm wanting it to initiate upon page load and that isn't working.

Edited by Guest

Share this post


Link to post
Share on other sites

Maybe explaining it more will get a response.

 

I have a page with multiple charts, and since in firefox the charts aren't shown when the page is printed (Flash bug, I know), I was going to do a background server-side export of a jpg of the chart and embed that image (all with javascript) in an alt-div. Upon File -> Print, a print.css will change the layout so the flash objects aren't shown, just the alt-divs containing pictures. Okay, so the chart will manually export (via the right click menu) but the javascript function that is done upon page load will not work. I have every other piece of this working except this one vital part. Here is the relevant code:

 

The chart tag in the generated chart's XML string:

 

 

 

chart labelDisplay='Rotate' slantLabels='1' animation='0' showValues='0' xAxisName='Date (MM.DD)' yAxisName='Total Page Views' caption='Page Views Between #{begin_date.strftime('%m.%d')} and #{end_date.strftime('%m.%d')}' subcaption='click on a datapoint to see detailed information' exportEnabled='1' exportAtClient='0' exportCallback='lineCallBack' exportHandler='http://localhost:3000/fusioncharts/fc_exporter/index' exportAction='save'

 

 

 

The javascript function generating the chart:

 

function createLineChart() {

 

var lineChart = new FusionCharts("../Charts/Line.swf", "lineChart", "1135", "600", "0", "1");

 

lineChart.setDataXML(<%= @line_string %>);

 

lineChart.render("lineChartDiv");

 

}

 

 

 

And finally the javascript function exporting the chart:

 

function ExportMyChart() {

 

var exportLine = getChartFromId("lineChart");

 

if(exportLine.hasRendered()) { exportLine.exportChart( {exportFormat: "JPG"} ); }

 

}

 

 

 

Now, if anyone can see anything wrong with this that would cause firebug to tell me that .hasRendered() and .exportChart aren't functions, let me know. The browser is pulling the necessary js files, and I can't see any differences between my functions and those in the demos (which also won't export via javascript)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this