Hi All,<br />
<br />
We currently have a number of report design files that contain a single chart. I'd like to be able to create an image representing that chart from that definition, and then return the URL for that image to a web application for display.<br />
<br />
Currently, the only way I see to do this is to use the HTMLRenderOption, set the image directory to one available to the web application, and run the report. The chart will be automatically created as an image, and included into the generated HTML report, but also be available as an image from the specified image directory.<br />
<br />
I'd like to bypass having to create the HTML file, and just create the chart directly, using the data set defined in the design file, or even switching it out for another one at runtime based on the input parameters from the web application.<br />
<br />
So far, the only thing I've been able to accomplish is to write a simple test application that extracts the chart from the design file, and use a Generator object to render the chart. The only problem with this is that this method doesn't seem to automatically use the data set defined in the design file to populate the chart with data. Here's the simple class I wrote:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
import org.eclipse.birt.chart.device.IDeviceRenderer;
import org.eclipse.birt.chart.exception.ChartException;
import org.eclipse.birt.chart.model.ChartWithAxes;
import org.eclipse.birt.chart.util.PluginSettings;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.DesignFileException;
import org.eclipse.birt.report.model.api.ExtendedItemHandle;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.extension.ExtendedElementException;
import org.eclipse.birt.chart.factory.GeneratedChartState;
import org.eclipse.birt.chart.factory.Generator;
import org.eclipse.birt.chart.factory.RunTimeContext;
import org.eclipse.birt.chart.model.attribute.Bounds;
import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;
import com.ibm.icu.util.ULocale;
public class ChartTest
{
private void createChart()
{
ReportDesignHandle designHandle = null;
DesignConfig config = new DesignConfig();
// config.setBIRTHome("C:/birt/birt-runtime-2_5_1/birt-runtime-2_5_1/ReportEngine ");
IDesignEngine engine = null;
try
{
Platform.startup(config);
IDesignEngineFactory factory = (IDesignEngineFactory) Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);
engine = factory.createDesignEngine(config);
}
catch(Exception ex)
{
ex.printStackTrace();
}
SessionHandle sessionHandle = engine.newSessionHandle((ULocale) null);
try
{
designHandle = sessionHandle.openDesign("/nethome/eblack04/AnomalyGraphTemplate.rptdesign");
}
catch(DesignFileException e)
{
e.printStackTrace();
}
ExtendedItemHandle eih = (ExtendedItemHandle) designHandle.getBody().getContents().get(4);
ChartWithAxes chart = null;
try
{
chart = (ChartWithAxes)eih.getReportItem().getProperty("chart.instance");
System.out.println("Chart is " + (chart == null ? "" : "not ") + "null");
PluginSettings ps = PluginSettings.instance();
IDeviceRenderer renderer = ps.getDevice("dv.PNG");
renderer.setProperty(IDeviceRenderer.FILE_IDENTIFIER, "/nethome/eblack04/AnomalyGraphTemplate.png");
RunTimeContext rtc = new RunTimeContext( );
rtc.setULocale( ULocale.getDefault( ) );
final Generator gr = Generator.instance( );
GeneratedChartState gcs = null;
//Set the chart size
Bounds bounds = BoundsImpl.create( 0, 0, 450, 300 );
gcs = gr.build( renderer.getDisplayServer( ), chart, bounds, null, rtc, null );
//generate the chart
gr.render(renderer, gcs);
}
catch(ExtendedElementException e)
{
e.printStackTrace();
}
catch(ChartException e)
{
e.printStackTrace();
}
}
/**
* execute application
*
*
@param args
*/
public static void main(String[] args)
{
new ChartTest().createChart();
}
}
</pre>
<br />
Do I have to pull out the data set defined in the report design file as well as the chart, and then set that data set into the chart before using the generator to create it? If so, how? Any help would be greatly appreciated on this.<br />
<br />
Thanks,<br />
<br />
Todd