I am trying to programmatically create a Radar Chart in my app with BIRT. It seems that BIRT lacks documentation so I am struggling with it (I'm wondering how it can be so popular with so little documentation).
So my problem is that I don't know the API and the sequence of action I have to invoke on it to have a fully integrated Chart. All I want to do is fetch some data from a DB and display them in a RADAR CHART (like theses ones : how to normalize statistics for a radar chart)
So for now, I have created a Servlet like this :
public class ChartRenderingServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private ChartEngine chartEngine = null;
private Chart chart = null;
private IDeviceRenderer iDeviceRenderer = null;
private IDisplayServer iDisplayServer = null;
private IGenerator iGenerator = null;
private String fontName = "Arial";
private float size = 10;
private boolean bBold = false;
private boolean bItalic = false;
private ColorDefinition cd = ColorDefinitionImpl.BLACK();
/**
* @see HttpServlet#HttpServlet()
*/
public ChartRenderingServlet() {
super();
// Starting platform
PlatformConfig platformConfig = new PlatformConfig();
platformConfig.setProperty("STANDALONE", true);
// Creating chart Engine
chartEngine = ChartEngine.instance(platformConfig);
iGenerator = chartEngine.getGenerator();
try {
iDeviceRenderer = chartEngine.getRenderer("dv.PNG");
iDisplayServer = iDeviceRenderer.getDisplayServer();
} catch (Exception e) {
e.printStackTrace();开发者_StackOverflow社区
}
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
RunTimeContext context;
chart = ChartWithoutAxesImpl.create();
chart.setType("RADAR");
try {
// PREPARE PHASE
context = Generator.instance().prepare(chart, null, null, ULocale.getDefault());
// BIND PHASE
//Long id = Long.valueOf(request.getParameter("id"));
NumberDataSet orthoValues = NumberDataSetImpl.create(new double[] {25, 35, 15, 5, 20});
RadarSeries radarSeries = RadarSeriesImpl.create();
radarSeries.setDataSet(orthoValues);
// RENDER PHASE
GeneratedChartState generatedChartState = iGenerator.build(iDisplayServer, chart, null, null, context);
iGenerator.render(iDeviceRenderer, generatedChartState);
} catch (ChartException e) {
e.printStackTrace();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
Any help would really be appriciated because I don't even know whether this is correct or not.
Thanks a lot,
Never mind,
when developing BIRT report-powered app, try to take a higher abstraction level when coding. I mean, there's no need to code against the low-level API : just take your rptdesign file and leverage the Birt Runtime API to code the app directly. If I can suggest something, I would say use the main API available which is Report Engine API, it will speed up your development.
And the cool thing with it is that, you have a lot of documentation available since it's the most common way of developing a BIRT-powered app.
tchusss ...
精彩评论