- 浏览: 169294 次
- 性别:
- 来自: 大连
文章分类
最新评论
-
panghaoyu:
实现一个智能提示功能需要ajax、数据库、jsp/php、算法 ...
solr 下拉提示功能 -
Java_大猫:
tinguo002 写道配置相对地址的时候 老出错,在这里找到 ...
solr4.1集成配置 -
tinguo002:
配置相对地址的时候 老出错,在这里找到答案了,只是为什么 ,这 ...
solr4.1集成配置 -
tinguo002:
太感谢了~ <env-entry-value>.. ...
solr4.1集成配置 -
gwgyk:
Java_大猫 写道gwgyk 写道不写velocity.pr ...
velocity.properties配置说明 【转】
前不久了解了下有关chart图方面的,首先对于JAVA的来说,比较好的应该是jfreechart了。至于具体介绍,我就不对此做介绍了。这里我做了两个小的例子。分别是柱状图 具体就作为参考吧。网上关于jfreechart的资料很多。
代码如下:
当然这里你需要有个xml配置 也就是上面设计的 graphURL 部分
配置如下
JSP页面需
代码如下:
HttpSession session = request.getSession(); response.setContentType("image/jpeg"); request.setCharacterEncoding("UTF-8"); CreateDate creat = new CreateDate(); CategoryDataset dateSet= creat.getDataSet(); JFreeChart chart = ChartFactory.createBarChart3D("水果销量图统计", null, null, dateSet, PlotOrientation.VERTICAL,true,true,true); CategoryPlot plot = chart.getCategoryPlot(); BarRenderer3D renderer = new BarRenderer3D(); //设置图表的纵轴和横轴org.jfree.chart.axis.CategoryAxis CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.1);//设置距离图片左端距离此时为10% domainAxis.setUpperMargin(0.1);//设置距离图片右端距离此时为百分之10 domainAxis.setCategoryLabelPositionOffset(10);//图表横轴与标签的距离(10像素) domainAxis.setCategoryMargin(0.2);//横轴标签之间的距离20% //设定柱子的属性 ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setUpperMargin(0.1);//设置最高的一个柱与图片顶端的距离(最高柱的10%) renderer.setBaseOutlinePaint(Color.red); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());//显示鼠标提示 renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER)); renderer.setBaseItemLabelsVisible(true); renderer.setSeriesPaint(0, new Color(0, 255, 255));//计划柱子的颜色为青色 renderer.setSeriesOutlinePaint(0,Color.green);//边框为黑色 renderer.setSeriesPaint(1, new Color(0, 255, 0));//实报柱子的颜色为绿色 renderer.setSeriesOutlinePaint(1,Color.red);//边框为红色 renderer.setItemMargin(0.1);//组内柱子间隔为组宽的10% //显示每个柱的数值,并修改该数值的字体属性 domainAxis.setTickLabelFont(new Font("宋体",Font.PLAIN,15)); /*------设置X轴的标题文字------------*/ domainAxis.setLabelFont(new Font("宋体",Font.PLAIN,15)); /*------设置Y轴坐标上的文字-----------*/ rangeAxis.setTickLabelFont(new Font("宋体",Font.PLAIN,15)); /*------设置Y轴的标题文字------------*/ rangeAxis.setLabelFont(new Font("黑体",Font.PLAIN,15)); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelFont(new Font("黑体",Font.BOLD,12));//12号黑体加粗 renderer.setItemLabelPaint(Color.black);//字体为黑色 renderer.setItemLabelsVisible(true); plot.setRenderer(renderer);//使用我们设计的效果 //设置纵横坐标的显示位置 plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);//学校显示在下端(柱子竖直)或左侧(柱子水平) plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); //人数显示在下端(柱子水平)或左侧(柱子竖直) TextTitle textTitle = chart.getTitle(); textTitle.setFont(new Font("黑体", Font.PLAIN, 20)); chart.setTitle(textTitle); chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12)); //设置热点提示 Shape shape = new Rectangle(20, 10); ChartEntity entity = new ChartEntity(shape); StandardEntityCollection coll = new StandardEntityCollection(); coll.add(entity); int width = 500; int height = 300; ChartRenderingInfo info = new ChartRenderingInfo(coll); PrintWriter pw = response.getWriter(); //写入到输出流生成图像文件,同时把图片的具体信息放入ChartRenderingInfo的一个实例为以后生成Map提供信息 // ChartUtilities.saveChartAsPNG(pw, chart, width, height, info); String filename = ServletUtilities.saveChartAsPNG(chart, width , height, info, session); ChartUtilities.writeImageMap(pw, filename, info, false); String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename; String strimg= ChartUtilities.getImageMap("map0", info); request.setAttribute("strimg", strimg); System.out.println(request.getAttribute("strimg")); request.setAttribute("graphURL", graphURL); RequestDispatcher dispatcher = request.getRequestDispatcher("/mobile2.jsp"); dispatcher .forward(request, response);
当然这里你需要有个xml配置 也就是上面设计的 graphURL 部分
配置如下
<servlet> <servlet-name>DisplayChart</servlet-name> <servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class> </servlet> <servlet-mapping> <servlet-name>DisplayChart</servlet-name> <url-pattern>/servlet/DisplayChart</url-pattern> </servlet-mapping>
JSP页面需
<%=request.getAttribute("strimg") %>// 页面必须要有这个才能实现当//你鼠标放到图上显示信息,也就是所谓的热点提示 <p><img src="${graphURL }" width="500" height="300" border="0" usemap="#map0"> </p>
发表评论
-
httpclient4 网页抓取
2013-04-25 18:29 1276最近在做全文检索。所以数据很纠结。没办法 抓一些行业新闻。于是 ... -
日期累加
2012-03-27 22:23 1186和所有的新人一起分享: public static voi ... -
文件下载
2012-03-26 12:48 937public void publicDownFileCo ... -
JXL取日期时yy-mm-dd 转成yyyy-mm-dd
2012-03-20 20:40 1277private static String getCellT ... -
commons-fileupload 小结
2012-01-04 11:38 1162最近写上传文件,用到了这个东西,我想很多人对这个并不陌生。 下 ... -
java 小方法积累
2011-08-15 16:04 1172public static void main(String ... -
jxl导入excel
2011-08-02 11:29 1225昨天做一个 excel 导入。由于此部分用的是JXL 所以 记 ... -
chart图之open flash chart2
2011-06-28 17:37 4213刚在前一个文章里写了 ... -
map 转 二维数组
2011-06-20 17:22 5507在一个国外的站点无意间发现的 觉得挺有用 留着了 Map< ... -
jxl读excel模板
2011-05-11 10:53 2449os = response.getOutputStream( ... -
jxl例子2--转
2011-05-05 23:06 920package com.jxl; import java ... -
jxl例子
2011-05-05 23:05 1049public class ExcelReport { pu ... -
DOM4J--转
2011-04-08 17:50 968Loading XML Data ... -
参考1
2011-04-08 16:20 0http://blog.transnal.com/blog-b ... -
SAX 解析XML
2011-04-08 16:19 987学习时的练习代码贴出来给初学者一起分享下:具体不解释 pack ... -
基于DOM XML学习笔记
2011-04-07 14:35 929关于XML我就不多介绍了。这里只是介绍下小弟学习DOM解析XM ... -
【转】Java与XML联合编程之DOM篇
2011-04-07 14:12 868DOM初步 DOM是Document ... -
【转】java反射
2011-03-28 11:33 716Java Reflection (JAVA反射) 作者 ... -
java固定流水号生成
2010-09-28 23:09 8177发一个流水号的想DEMO。大家可以学习下。有好的东西当然要分享 ... -
【转帖】java权限。。。
2010-03-28 23:53 1700这里笔者介绍一种很常用,也比较专业的权限控制思路。这里用jav ...
相关推荐
jfreechart and open flash chart整理jfreechart and open flash chart整理
Chart of JFreeChart
public JFreeChart createChart(String Ytitle, String title, CategoryDataset lineData, CategoryDataset barData) { //参考附件 return chart; } //struts 部分 <!--begin 维优特例 --> ...
将数据库中的数据以柱形图的形式显示出来,该例子中显示的是3D形式的柱形图,可以根据需要自行更改柱形图的样式。同时柱形图不是生成图片,而是直接显示在页面上。
该程序为main 函数,定义了三个方法,分别是jfreechart三种实现折线图的类型,返回的是一个chart 本程序是把图片保存到本地,当然实际应用中,只要在程序和页面中做相关配置即可以使用。 因为图片带点透明,所以...
通过JFreeChart插件,既可以生成普通效果的折线图,也可以生成3D效果的折线图。如果想生成普通效果的折线图,需要通过工厂类ChartFactory的createLineChart()方法获得JFreeChart类的实例;如果想生成3D效果的折线图...
java JXL导出Excel源码及jfreechart 生成折线图,饼图 java JXL导出Excel源码及jfreechart 生成折线图,饼图 java JXL导出Excel源码及jfreechart 生成折线图,饼图
JFreeChart jfreechart = ChartFactory.createPieChart("Pie Chart Demo 2", piedataset, true, true, false); PiePlot pieplot = (PiePlot)jfreechart.getPlot(); pieplot.setSectionPaint("One", new Color(160...
<TITLE>JFreeChart 简单的例子 <H2>JFreeChart: 简单的例子 下面有两个简单的例子,调用servlet,生成统计图. 条形统计图 href="servlet/ServletDemo1">条形统计图; <!--跳转到ServletDemo1生成条形统计图--> 可以...
JFreeChart在eclipse的配置(eclipse+JFreeChart)
JFreeChart chart=ChartFactory.createPieChart("某公司人员组织数据图",dpd,true,true,false); //可以查具体的API文档,第一个参数是标题,第二个参数是一个数据集,第三个参数表示是否显示Legend,第四个参数...
JFreeChart 混合图表 Example for mutiple jfreechart plot. Demonstration for the chart!
JFreeChart是JAVA平台上的一个开放的图表绘制类库,它是目前比较流行的Java Chart API,而且是一个开源项目。它完全使用JAVA语言编写,是为applications, applets, servlets 以及JSP等使用所设计。JFreeChart可生成...
JFreeChart chart=ChartFactory.createPieChart("饼型图",dataset,true,true,true); chart.setTitle("统计图");//设置图片标题 ChartRenderingInfo info=new ChartRenderingInfo(new StandardEntityCollection())...
这只是一个例子,由于里面的数据联系到了数据库,因而单独运行是不成功的。...该方法不仅适用于线性图,areachart,piechart,stackchart等的实时图该方法同样适用。主要运用了createCategoryDataset方法
JFreeChart GUI example
介绍Eclipse下JfreeChart的应用
org.jfree.chart.imagemap HTML图片映像工具类 org.jfree.chart.labels 图表标签和信息提示类 org.jfree.chart.needle Needle classes for the compass plot org.jfree.chart.plot Plot类和接口 org.jfree.chart....
jfreechart jsp jsp显示图片 折线图 myeclipse工程;
JFreeChart可生成饼图(pie charts)、柱状图(bar charts)、散点图(scatter plots)、时序图(time series)、甘特图(Gantt charts)等等多种图表,并且可以产生PNG和JPEG格式的输出,还可以与PDF和EXCEL关联。