原創|其它|編輯:郝浩|2012-10-24 16:27:36.000|閱讀 2435 次
概述:以前一直是用JFreeChart畫統計圖,不過JFreeChart畫出來的圖形不夠精細,看起來有些模糊,今天用了另外一個工具ChartDirector,這是一個商業版本的工具,生成的圖形非常精細,可以說是我用過的最精細的一個。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
以前一直是用JFreeChart畫統計圖,不過JFreeChart畫出來的圖形不夠精細,看起來有些模糊,今天用了另外一個工具ChartDirector,這是一個商業版本的工具,生成的圖形非常精細,可以說是我用過的最精細的一個。
下面是它的一個柱狀圖例子:

范例程序:
<%@page import="ChartDirector.*" %>
<%
//The data for the bar chart
double[] data = {85, 156, 179.5, 211, 123};
//The labels for the bar chart
String[] labels = {"Mon", "Tue", "Wed", "Thu", "Fri"};
//Create a XYChart object of size 300 x 280 pixels
XYChart c = new XYChart(300, 280);
//Set the plotarea at (45, 30) and of size 200 x 200 pixels
c.setPlotArea(45, 30, 200, 200);
//Add a title to the chart
c.addTitle("Weekly Server Load");
//Add a title to the y axis
c.yAxis().setTitle("MBytes");
//Add a title to the x axis
c.xAxis().setTitle("Work Week 25");
//Add a bar chart layer with green (0x00ff00) bars using the given data
c.addBarLayer(data, 0xff00).set3D();
//Set the labels on the x axis.
c.xAxis().setLabels(labels);
//output the chart
String chart1URL = c.makeSession(request, "chart1");
//include tool tip for the chart
String imageMap1 = c.getHTMLImageMap("", "", "title='{xLabel}: {value} MBytes'")
;
%>
<html>
<body topmargin="5" leftmargin="5" rightmargin="0">
<div style="font-size:18pt; font-family:verdana; font-weight:bold">
3D Bar Chart
</div>
<hr color="#000080">
<a href="viewsource.jsp?file=<%=request.getServletPath()%>">
<font size="2" face="Verdana">View Chart Source Code</font>
</a>
</div>
<br>
<img src='<%=response.encodeURL("getchart.jsp?"+chart1URL)%>'
usemap="#map1" border="0">
<map name="map1"><%=imageMap1%></map>
</body>
</html>
如果要在柱的頂部顯示數值,可以調用Layer的setDataLabelFormat方法設置
范例:
layer.setDataLabelFormat("{value}");
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉載自:BlogJava