如何在 BIRT 中创建雷达图? (我在帖子中所做的示例)
我正在尝试使用 BIRT 在我的应用程序中以编程方式创建雷达图。 BIRT 似乎缺乏文档,所以我正在努力解决它(我想知道它如何在如此少的文档下如此受欢迎)。
所以我的问题是我不知道 API 以及我必须调用它才能拥有完全集成的图表的操作顺序。我想做的就是从数据库中获取一些数据并将它们显示在雷达图中(就像这些:如何标准化雷达图的统计数据)
所以现在,我创建了一个像这样的Servlet:
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();
}
}
/**
* @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
}
}
任何帮助都会非常感激,因为我什至不知道这是否正确。
多谢,
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();
}
}
/**
* @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,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系,
在开发 BIRT 报告驱动的应用程序时,在编码时尝试采用更高的抽象级别。我的意思是,无需针对低级 API 进行编码:只需获取 rptdesign 文件并利用 Birt Runtime API 直接对应用程序进行编码即可。如果我可以建议的话,我会说使用可用的主要 API,即报表引擎 API,它将加快您的开发速度。
它最酷的一点是,您有大量可用文档,因为这是开发 BIRT 支持的应用程序的最常见方法。
嘘……
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 ...