我用jfreechart 生成了一个柱形图,在并且设置了生成链接,也就是每个柱子上都有超链接来请求另一个页面。可是,链接加上后,连问号都给转成了%形式,请高手指教,怎样搞定???
这是我的代码。
我是用的struts 架构
action中
public ActionForward LockChe(ActionMapping am,ActionForm af,HttpServletRequest req,HttpServletResponse res) throws Exception {
CreateChartServiceImpl pm = new CreateChartServiceImpl(lockd,datelist,imgpath,res); ??pm.makeBarChart();? ?? //生成柱状图 ??String chemap=readMap(req); ??req.setAttribute("chemap",chemap); //map对象
?
private String readMap(HttpServletRequest req) { ?String?filepath=req.getSession().getServletContext().getRealPath("/")+"lockpng/locks.map"; ?String file_str=null; ??try { ???File f=new File(filepath); ???FileInputStream fis=new FileInputStream(f); ???byte[] fbt=new byte[(int)f.length()]; ???fis.read(fbt); ???file_str=new String(fbt); ??} catch (Exception e) { ???// TODO 自动生成 catch 块 ???System.out.println("类:方法:执行:发生SQLServer异常"); ???e.printStackTrace(); ??} ??return file_str; ?}
?
public class CreateChartServiceImpl { private String? CHART_PATH = ""; private double[][] lockdata =null; private String[]?? lockdate =null; HttpServletResponse res=null;
public CreateChartServiceImpl(double[][] data,String[] datetime,String imgpath,HttpServletResponse res){ ?this.lockdata=data; ?this.lockdate=datetime; ?this.CHART_PATH=imgpath; ?this.res=res; }
/** * 生成柱状图 */ public void makeBarChart() { //double[][] data = new double[][] //{ //{ 672,766,223,540,126 } }; String[] rowKeys = { "在锁车" }; //String[] columnKeys = //{ "北京","上海","广州","成都","深圳" }; CategoryDataset dataset = getBarData(this.lockdata,rowKeys,this.lockdate); createBarChart(dataset,"日期","在锁车(台)","十五天内在锁车记录","bar.png"); }
/** * 柱状图 * *@param dataset 数据集 * @param xName x轴的说明(如种类,时间等) * @param yName y轴的说明(如速度,时间等) * @param chartTitle 图标题 * @param charName 生成图片的名字 * @return */ public String createBarChart(CategoryDataset dataset,String xName, ??????? String yName,String chartTitle,String charName) { JFreeChart chart = ChartFactory.createBarChart(chartTitle,// 图表标题 ??????? xName,// 目录轴的显示标签 ??????? yName,// 数值轴的显示标签 ??????? dataset,// 数据集 ??????? PlotOrientation.VERTICAL,// 图表方向:水平、垂直 ??????? true,// 是否显示图例(对于简单的柱状图必须是false) ??????? true,// 是否生成工具 ??????? true // 是否生成URL链接 ??????? ); Font labelFont = new Font("SansSerif",Font.TRUETYPE_FONT,12); /* * VALUE_TEXT_ANTIALIAS_OFF表示将文字的抗锯齿关闭, * 使用的关闭抗锯齿后,字体尽量选择12到14号的宋体字,这样文字最清晰好看 */ ?chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); chart.setTextAntiAlias(false); chart.setBackgroundPaint(Color.white); // create plot CategoryPlot plot = chart.getCategoryPlot(); // 设置横虚线可见 plot.setRangeGridlinesVisible(true); // 虚线色彩 plot.setRangeGridlinePaint(Color.gray); // 数据轴精度 //NumberAxis vn = (NumberAxis) plot.getRangeAxis(); // vn.setAutoRangeIncludesZero(true); //DecimalFormat df = new DecimalFormat("#0"); //vn.setNumberFormatOverride(df); // 数据轴数据标签的显示格式 // x轴设置 CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLabelFont(labelFont);// 轴标题 domainAxis.setTickLabelFont(labelFont);// 轴数值
// Lable(Math.PI/3.0)度倾斜 domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // 横轴上的 // domainAxis.setCategoryLabelPositions(CategoryLabelPositions // .createUpRotationLabelPositions(Math.PI / 3.0));
domainAxis.setMaximumCategoryLabelWidthRatio(0.6f);// 横轴上的 Lable 是否完整显示
// 设置距离图片左端距离 domainAxis.setLowerMargin(0.01); // 设置距离图片右端距离 domainAxis.setUpperMargin(0.01); // 设置 columnKey 是否间隔显示 // domainAxis.setSkipCategoryLabelsToFit(true);
plot.setDomainAxis(domainAxis); // 设置柱图背景色(注意,系统取色的时候要使用16位的模式来查看颜色编码,这样比较准确) plot.setBackgroundPaint(new Color(255,255,204));
// y轴设置 ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setLabelFont(labelFont); rangeAxis.setTickLabelFont(labelFont); // 设置最高的一个 Item 与图片顶端的距离 rangeAxis.setUpperMargin(0.15); // 设置最低的一个 Item 与图片底端的距离 rangeAxis.setLowerMargin(0.15); plot.setRangeAxis(rangeAxis);
BarRenderer renderer = new BarRenderer(); // 设置柱子宽度 renderer.setMaximumBarWidth(0.05); // 设置柱子高度 renderer.setMinimumBarLength(0.2); // 设置柱子边框颜色 renderer.setBaSEOutlinePaint(Color.BLACK); // 设置柱子边框可见 renderer.setDrawBarOutline(true);
// // 设置柱的颜色 renderer.setSeriesPaint(0,new Color(204,255)); renderer.setSeriesPaint(1,new Color(153,204,255)); renderer.setSeriesPaint(2,new Color(51,204));
// 设置每个地区所包含的平行柱的之间距离 renderer.setItemMargin(0.0);
?
// 显示每个柱的数值,并修改该数值的字体属性 renderer.setIncludeBaseInRange(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true);
plot.setRenderer(renderer); // 设置柱的透明度 plot.setForegroundAlpha(1.0f); //设置URL StandardCategoryURLGenerator ddr=new StandardCategoryURLGenerator("detail.jsp","datetime","taici"); renderer.setBaseItemURLGenerator(ddr); PrintWriter pw = null; FileOutputStream fos_cri = null; FileOutputStream fos_jpg = null; try { isChartPathExist(CHART_PATH); String chartName = CHART_PATH + charName; fos_jpg = new FileOutputStream(chartName); ChartRenderingInfo info = new ChartRenderingInfo(new? StandardEntityCollection());
//ChartUtilities.writeChartAsPNG(fos_jpg,chart,400,320,true,10); ChartUtilities.writeChartAsPNG(fos_jpg,info);
pw = new PrintWriter(fos_cri);??? res.setContentType("text/html;charset=utf-8"); fos_cri=new FileOutputStream(CHART_PATH+"locks.map"); ChartUtilities.writeImageMap(pw,"querysmap",info,true); pw.flush(); return chartName; } catch (Exception e) { e.printStackTrace(); return null; } finally { try { pw.close(); fos_cri.close(); fos_jpg.close(); } catch (Exception e) { e.printStackTrace(); } } }
}
?
?
map文件中的
href="detail.jsp%3Fdatetime%3D%25E5%259C%25A8%25E9%2594%2581%25E8%25BD%25A6%26amp%3Btaici%3D05-06""
链接明显是不正常的。所以很困惑。请高手指教!~~~
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|