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}'");
%>
<html>
<body style="margin:5px 0px 0px 5px">
<div style="font-size:18pt; font-family:verdana; font-weight:bold">
    Horizontal Box-Whisker Chart
</div>
<hr color="#000080">
<div style="font-size:9pt; font-family:verdana; margin-bottom:1.5em">
    <a href="viewsource.jsp?file=<%=request.getServletPath()%>">View Source Code</a>
</div>
<img src='<%=response.encodeURL("getchart.jsp?"+chart1URL)%>'
    usemap="#map1" border="0">
<map name="map1"><%=imageMap1%></map>
</body>
</html>

運行JSP頁面方可看到效果。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章