JAVAWEB ChartDirector报表生成器

报表图形对于目前各行各业都很重要,对于程序猿系统中展现出来的图形报表尤为的直观,给人简单易懂的数据展现,那么在JAVAWEB中做数据报表的插件第三方的也很多

今天讲一下ChartDirector在实际开发中的应用。

 ChartDirector 和jfreechaer 都是图形报表插件  ChartDirector商业版需要收费当然也有破解的网上一大把,JfreeChart是免费的开源的但是文档是需要收费的。不过JFreeChart目前应用广泛很多文档都很清楚网上也有很多示例参考学习。


ChartDirector做出来的图形界面比Jfreechart个人认为漂亮许多。

准备工作:

 1  需要下载ChartDirector的JAR包。

 2  新建一个WEB应用 把下载的ChartDirector导入项目中

<%@page import="ChartDirector.*" %>
<%
// Sample data for the Box-Whisker chart. Represents the minimum, 1st quartile,
// medium, 3rd quartile and maximum values of some quantities
double[] Q0Data = {40, 45, 35};
double[] Q1Data = {55, 60, 50};
double[] Q2Data = {62, 70, 60};
double[] Q3Data = {70, 80, 65};
double[] Q4Data = {80, 90, 75};
//上面的数据为报表呈现出来的数据组 当然这些数据组还可以进行WEBSERVERS获取或者数据库获取都可以。
// The labels for the chart
String[] labels = {"<*img=robot1.png*><*br*>Bipedal Type",
    "<*img=robot2.png*><*br*>Wolf Type", "<*img=robot5.png*><*br*>Bird Type"};
//Labels为生成图表后图表的数据标题
// Create a XYChart object of size 540 x 320 pixels
XYChart c = new XYChart(540, 320);
//进行绘制图表
// swap the x and y axes to create a horizontal box-whisker chart
c.swapXY();

//Set search path to current JSP directory for loading icon images
c.setSearchPath(getServletConfig().getServletContext(), request);

// Set the plotarea at (75, 25) and of size 440 x 270 pixels. Enable both horizontal
// and vertical grids by setting their colors to grey (0xc0c0c0)
c.setPlotArea(75, 25, 440, 270).setGridColor(0xc0c0c0, 0xc0c0c0);

// Add a title to the chart
c.addTitle("           Robot Shooting Accuracy Scores");

// Set the labels on the x axis and the font to Arial Bold
c.xAxis().setLabels(labels).setFontStyle("Arial Bold");

// Disable x axis ticks by setting the length to 0
c.xAxis().setTickLength(0);

// Set the font for the y axis labels to Arial Bold
c.yAxis().setLabelStyle("Arial Bold");

// Add a Box Whisker layer using light blue 0x9999ff as the fill color and blue
// (0xcc) as the line color. Set the line width to 2 pixels
c.addBoxWhiskerLayer2(Q3Data, Q1Data, Q4Data, Q0Data, Q2Data).setLineWidth(2);

// Output the chart
String chart1URL = c.makeSession(request, "chart1");

// Include tool tip for the chart
String imageMap1 = c.getHTMLImageMap("", "",
    "title='{xLabel}: min/med/max = {min}/{med}/{max}\n Inter-quartile range: " +
    "{bottom} to {top}'");
%>


Horizontal Box-Whisker Chart

<%=imageMap1%>

运行JSP页面方可看到效果。

你可能感兴趣的:(java,EE)