原創|其它|編輯:郝浩|2012-10-16 15:40:14.000|閱讀 772 次
概述:ChartDirector For JSP的使用步驟,方便學習
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
<servlet> <servlet-name>GetSessionImage</servlet-name> <servlet-class>ChartDirector.GetSessionImage</servlet-class> </servlet> <servlet-mapping> <servlet-name>GetSessionImage</servlet-name> <url-pattern>*.chart</url-pattern> </servlet-mapping>
<%@page import="ChartDirector.*" %><% try { out.clear(); GetSessionImage.getImage(request, response); if (Math.max(1, 2) == 2) return; } catch (IllegalStateException e) { response.sendRedirect(response.encodeRedirectURL( "getchart.chart?" + request.getQueryString())); return; } %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="ChartDirector.*;"%> <% request.setCharacterEncoding("UTF-8"); //以兩個系列數據為例 double[] data = {185, 156, 179.5, 211, 123}; double[] data1 = {55, 76, 34.5, 88, 43}; //數據列名 String[] labels = {"一月", "二月", "三月", "四月", "五月"}; //生成圖片大小 250 x 250 XYChart c = new XYChart(550, 350); Chart.setLicenseCode("ME7YWN3DBFQU2C7MB3971677"); //圖標題 c.addTitle("第一個圖","",15); //支持中文 c.setDefaultFonts("SIMSUN.TTC","simhei.ttf"); //圖表在圖片中的定位及區域大小 c.setPlotArea(30, 40, 400, 250); //========================= //加入單個數據 //BarLayer layer = c.addBarLayer(data,0xff3456,"我的測試"); //========================= //加入多個BAR數據(多個datasets) BarLayer layer = c.addBarLayer2(Chart.Side, 3); layer.addDataSet(data, 0xff8080, "我測試1"); layer.addDataSet(data1, 0x008080, "你也測2"); //3d化 layer.set3D(); //設置BAR邊框形式 layer.setBarShape(0); //bar寬度 layer.setBarWidth(50); //設置BAR邊框顏色 //layer.setBorderColor(0xff9999); //圖例形式 layer.setLegend(1); //每個BAR頂部加入數據顯示 layer.setAggregateLabelStyle(); //設置BAR底部的名稱顯示 TextBox t = c.xAxis().setLabels(labels); //名稱文字大小 t.setFontSize(9); //加圖例 //LegendBox legend = c.addLegend(260, 120,true); //legend.addKey("錢財",0xff8080); //圖例位置 c.addLegend(450, 120,true); //output the chart String chart1URL = c.makeSession(request, "chart1"); //include tool tip for the chart String imageMap1 = c.getHTMLImageMap("#", "", "title='{xLabel}: US${value}K'"); %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>圖表測試</title> </head> <body> <h1>中文</h1> <hr color="#000080"> <br> <img src='<%=response.encodeURL("getchart.jsp?"+chart1URL)%>' usemap="#map1" border="0"> <map name="map1"><%=imageMap1%></map> <% out.println(chart1URL); out.println(response.encodeURL(chart1URL)); %> </body> </html>
以上就是ChartDirector的使用過程,由于效果圖上傳不了,大家自己運行試試
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:搜狐博客