用JfreeChart画散点图
首先,看画图的API,参数有:
ChartFactory.createScatterPlot(),其中,有一个xydataset,那么,我们先要知道这个xydataset是什么结构的,再看所需xydataset,散点图,也就是单独画出点,也就是一个二维数据了,x ,y坐标嘛!
那么,先做好准备工作,第一步,拿数据,这就不用啰嗦了,就是得到一个List也好,Set也行。
第二步,加载到数据集:
-
-
-
-
-
-
- public static XYDataset createxydataset(List<PressureBean> xydatalist,
- String bloods) {
- DefaultXYDataset xydataset = new DefaultXYDataset();
-
- int size = xydatalist.size();
- double[][] datas = new double[2][size];
- for (int i = 0; i < size; i++) {
- PressureBean pres = xydatalist.get(i);
- int sys = pres.getSyspress();
- int dia = pres.getDiapress();
-
- datas[0][i] = sys;
- datas[1][i] = dia;
- }
-
- xydataset.addSeries(bloods, datas);
-
- return xydataset;
-
- }
下一步,另外一个准备工作,画图方法:
- public static JFreeChart createChart(XYDataset xydataset,
- String bloodcattile, String shou, String shu, String nobloodData,
- String bloods, String nomal, String fore, String one, String two,
- List<PressureBean> list, Log log) {
-
-
-
- int maxpress = 160;
- int addmax = 20;
-
- if (list != null && list.size() > 0) {
-
- Iterator<PressureBean> it = list.iterator();
- while (it.hasNext()) {
- PressureBean pres = it.next();
-
- if (maxpress < pres.getDiapress()) {
- maxpress = pres.getDiapress();
- }
-
- if (maxpress < pres.getSyspress()) {
- maxpress = pres.getSyspress();
- }
- }
-
- maxpress += addmax;
-
-
- log.info("high press value is =" + maxpress);
-
- }
-
- JFreeChart jfreechart = ChartFactory.createScatterPlot(bloodcattile,
- shou, shu, xydataset, PlotOrientation.VERTICAL, true, false,
- false);
- jfreechart.setBackgroundPaint(Color.white);
- jfreechart.setBorderPaint(Color.GREEN);
- jfreechart.setBorderStroke(new BasicStroke(1.5f));
- XYPlot xyplot = (XYPlot) jfreechart.getPlot();
- xyplot.setNoDataMessage(nobloodData);
- xyplot.setNoDataMessageFont(new Font("", Font.BOLD, 14));
- xyplot.setNoDataMessagePaint(new Color(87, 149, 117));
-
- xyplot.setBackgroundPaint(new Color(255, 253, 246));
- ValueAxis vaaxis = xyplot.getDomainAxis();
- vaaxis.setAxisLineStroke(new BasicStroke(1.5f));
-
- ValueAxis va = xyplot.getDomainAxis(0);
- va.setAxisLineStroke(new BasicStroke(1.5f));
-
- va.setAxisLineStroke(new BasicStroke(1.5f));
- va.setAxisLinePaint(new Color(215, 215, 215));
- xyplot.setOutlineStroke(new BasicStroke(1.5f));
- va.setLabelPaint(new Color(10, 10, 10));
- va.setTickLabelPaint(new Color(102, 102, 102));
- ValueAxis axis = xyplot.getRangeAxis();
- axis.setAxisLineStroke(new BasicStroke(1.5f));
-
- XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot
- .getRenderer();
- xylineandshaperenderer.setSeriesOutlinePaint(0, Color.WHITE);
- xylineandshaperenderer.setUseOutlinePaint(true);
- NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
- numberaxis.setAutoRangeIncludesZero(false);
- numberaxis.setTickMarkInsideLength(2.0F);
- numberaxis.setTickMarkOutsideLength(0.0F);
- numberaxis.setAxisLineStroke(new BasicStroke(1.5f));
- numberaxis.setUpperBound(maxpress);
- numberaxis.setLowerBound(60);
- NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
- numberaxis1.setTickMarkInsideLength(2.0F);
- numberaxis1.setTickMarkOutsideLength(0.0F);
- numberaxis1.setUpperBound(105d);
- numberaxis1.setLowerBound(35);
- numberaxis1.setAxisLineStroke(new BasicStroke(1.5f));
-
-
- XYBoxAnnotation box = new XYBoxAnnotation(0, 0, 89, 59);
- XYBoxAnnotation box1 = new XYBoxAnnotation(0, 0, 119, 79);
- XYBoxAnnotation box2 = new XYBoxAnnotation(0, 0, 139, 89);
- XYBoxAnnotation box3 = new XYBoxAnnotation(0, 0, 159, 99);
- XYTextAnnotation text1 = new XYTextAnnotation(nomal, 70, 62.5);
- XYTextAnnotation text = new XYTextAnnotation(fore, 70, 82.5);
- XYTextAnnotation text2 = new XYTextAnnotation(one, 70, 91.5);
- XYTextAnnotation text3 = new XYTextAnnotation(two, 70, 101.5);
-
-
-
- xyplot.addAnnotation(box);
- xyplot.addAnnotation(box1);
- xyplot.addAnnotation(box2);
- xyplot.addAnnotation(box3);
-
- xyplot.addAnnotation(text);
- xyplot.addAnnotation(text1);
- xyplot.addAnnotation(text2);
- xyplot.addAnnotation(text3);
-
- return jfreechart;
- }
最后一步,返回图片URL
- public static void drawScatterChart(IrisIoInterface io, Log log,
- XYDataset xydataSet, String title, String shou, String shu,
- String nodata, String boolds, String nomal, String fore,
- String one, String two, List<PressureBean> list) {
-
- JFreeChart chart = createChart(xydataSet, title, shou, shu, nodata,
- boolds, nomal, fore, one, two, list, log);
-
- HttpServletRequest request = io.getRequest();
- String filename = "";
- String graphURL = "";
- try {
- filename = ServletUtilities.saveChartAsPNG(chart, 400, 300, null,
- io.getSession());
- graphURL = request.getContextPath() + "/displayChart?filename="
- + filename;
- } catch (IOException e) {
-
- e.printStackTrace();
- log.error(e);
- }
-
- io.setData("filename", filename, BeanShare.BEAN_SHARE_REQUEST);
- io.setData("scatterurl", graphURL, BeanShare.BEAN_SHARE_REQUEST);
-
- }
效果图:
Copy:
分享到:
相关推荐
一份非常简单的jfreechart折线图demo!!!!!!!!
jfreechart折线图读取数据库数据的显示
该程序为main 函数,定义了三个方法,分别是jfreechart三种实现折线图的类型,返回的是一个chart 本程序是把图片保存到本地,当然实际应用中,只要在程序和页面中做相关配置即可以使用。 因为图片带点透明,所以...
NULL 博文链接:https://leequer.iteye.com/blog/509321
ValueStack vs=(ValueStack)request.getAttribute("struts.valueStack"); List list=(List)vs.findValue("list"); Iterator itor=list.iterator(); while(itor.hasNext()) { ... <%} %>
jfreechart 堆栈柱状图跟折线图结合拼接 jar包请戳http://download.csdn.net/detail/a156435646/7424707
利用jfreechart绘制的漂亮的折线图,实现双纵坐标,折线点标签还带箭头指示,非常直观,需要提前下载jfreechart.jar文件,否则我的类会报错,也即是要配置运行环境
public JFreeChart createChart(String Ytitle, String title, CategoryDataset lineData, CategoryDataset barData) { //参考附件 return chart; } //struts 部分 <!--begin 维优特例 --> ...
JSP利用JFreeChart生成折线图,文档中包含所需jar包,共有四个例子,导入即可运行,内附有说明
jfreechart 折线图、饼状图、柱状图在web页面上的应用,自己在网上找到点资料,然后写了个示例。 导入的myeclipse中部署即可。
JFreeChart双Y轴折线图实例,可以直接运行,实例类为LineChartDemo1.JAVA,有注释。 若想在web工程使用只需如下。 String filename = ServletUtilities.saveChartAsPNG(jfreechart, 600, 400, null, session); ...
JFreeChart饼图、折线图等资料学习,jar包,示例,api。全有非常好用
主要为大家详细介绍了JFreeChart折线图的生成方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
jfreechart的简单使用,jfreechart根据24小时数据画折线图。自定义x轴y轴刻度,时间间隔为1小时且以整点为折点画折线图。
flex案例\flex图形\玫瑰图\jfreechart小记(雷达图+折线图).doc
jfreechart绘制折线图(平面和3D)绝对经典
JFreeChart 饼状图 柱状图 柱状图 堆积柱状图 折线图 这个是我特地开发的一个用JFreeChart开发的用来画图的项目,已经开发成形了各种项目的各种需求的项目,并且自己可以拓展,根据需求修改代码,完成项目的需要。 ...
java JXL导出Excel源码及jfreechart 生成折线图,饼图 java JXL导出Excel源码及jfreechart 生成折线图,饼图 java JXL导出Excel源码及jfreechart 生成折线图,饼图
java里用JFreeChart画柱状图、折线图、雷达图,三个封装好的方法,可以直接调用。
JFreeChart实时折线图 利用Jfreechart实现applet的动态折线图 实时显示随机数