自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

JFreeChart最佳實(shí)踐:散點(diǎn)圖

開發(fā) 后端
本文將介紹作者通過Java最佳圖形解決方案JFreeChart實(shí)現(xiàn)散點(diǎn)圖的詳細(xì)過程。

用JfreeChart畫散點(diǎn)圖,查看JfreeChart的Demo,寫的都挺復(fù)雜的,關(guān)鍵是Demo中把簡(jiǎn)單的事情復(fù)雜化了,比如展示的例子是一個(gè)正弦曲線什么的,讓初次畫散點(diǎn)圖的我們摸不著頭腦。關(guān)鍵是他們得到數(shù)據(jù)集搞得太過復(fù)雜,后來想明白了,不就是二維數(shù)組嘛。想通了這一點(diǎn),一切問題都解決了,不過,對(duì)于我們項(xiàng)目的特殊要求,并不是只畫幾個(gè)點(diǎn)那么簡(jiǎn)單,還要加上區(qū)域范圍與文字說明,在查看文檔及自己摸索下,2天時(shí)間,終于搞定。下面分享一下成果,呵,還是有點(diǎn)成就感的。

首先,看畫圖的API,參數(shù)有:

ChartFactory.createScatterPlot(),其中,有一個(gè)xydataset,那么,我們先要知道這個(gè)xydataset是什么結(jié)構(gòu)的,再看所需xydataset,散點(diǎn)圖,也就是單獨(dú)畫出點(diǎn),也就是一個(gè)二維數(shù)據(jù)了,x ,y坐標(biāo)嘛!

那么,先做好準(zhǔn)備工作,***步,拿數(shù)據(jù),這就不用啰嗦了,就是得到一個(gè)List也好,Set也行。

第二步,加載到數(shù)據(jù)集:

  1. /**  
  2.  *   
  3.  * @param xydatalist  
  4.  * @param bloods  
  5.  * @return  
  6.  */ 
  7.     public static XYDataset createxydataset(List<PressureBean> xydatalist,  
  8.             String bloods) {  
  9.         DefaultXYDataset xydataset = new DefaultXYDataset();  
  10.  
  11.         int size = xydatalist.size();  
  12.         double[][] datas = new double[2][size];  
  13.         for (int i = 0; i < size; i++) {  
  14.             PressureBean pres = xydatalist.get(i);  
  15.             int sys = pres.getSyspress();//收縮壓  
  16.             int dia = pres.getDiapress();//舒張壓  
  17.  
  18.             datas[0][i] = sys;  
  19.             datas[1][i] = dia;  
  20.         }  
  21.  
  22.         xydataset.addSeries(bloods, datas);  
  23.  
  24.         return xydataset;  
  25.  
  26.     } 

下一步,另外一個(gè)準(zhǔn)備工作,畫圖方法:

  1. public static JFreeChart createChart(XYDataset xydataset,  
  2.             String bloodcattile, String shou, String shu, String nobloodData,  
  3.             String bloods, String nomal, String fore, String one, String two,  
  4.             List<PressureBean> list, Log log) {  
  5.  
  6.         // 有可能用戶在后面的版本中故意輸入不正常數(shù)值,但是為了保證圖片畫圖的完整,這里先計(jì)算  
  7.         // 用戶血壓值的***值。  
  8.         int maxpress = 160;  
  9.         int addmax = 20;  
  10.  
  11.         if (list != null && list.size() > 0) {  
  12.  
  13.             Iterator<PressureBean> it = list.iterator();  
  14.             while (it.hasNext()) {  
  15.                 PressureBean pres = it.next();  
  16.                   
  17.                 if (maxpress < pres.getDiapress()) {  
  18.                     maxpress = pres.getDiapress();  
  19.                 }  
  20.  
  21.                 if (maxpress < pres.getSyspress()) {  
  22.                     maxpress = pres.getSyspress();  
  23.                 }  
  24.             }  
  25.  
  26.             maxpress += addmax;  
  27.  
  28.  
  29.             log.info("high press value is =" + maxpress);  
  30.  
  31.         }  
  32.  
  33.         JFreeChart jfreechart = ChartFactory.createScatterPlot(bloodcattile,  
  34.                 shou, shu, xydataset, PlotOrientation.VERTICAL, truefalse,  
  35.                 false);  
  36.         jfreechart.setBackgroundPaint(Color.white);  
  37.         jfreechart.setBorderPaint(Color.GREEN);  
  38.         jfreechart.setBorderStroke(new BasicStroke(1.5f));  
  39.         XYPlot xyplot = (XYPlot) jfreechart.getPlot();  
  40.         xyplot.setNoDataMessage(nobloodData);  
  41.         xyplot.setNoDataMessageFont(new Font("", Font.BOLD, 14));  
  42.         xyplot.setNoDataMessagePaint(new Color(87149117));  
  43.  
  44.         xyplot.setBackgroundPaint(new Color(255253246));  
  45.         ValueAxis vaaxis = xyplot.getDomainAxis();  
  46.         vaaxis.setAxisLineStroke(new BasicStroke(1.5f));  
  47.  
  48.         ValueAxis va = xyplot.getDomainAxis(0);  
  49.         va.setAxisLineStroke(new BasicStroke(1.5f));  
  50.  
  51.         va.setAxisLineStroke(new BasicStroke(1.5f)); // 坐標(biāo)軸粗細(xì)  
  52.         va.setAxisLinePaint(new Color(215215215)); // 坐標(biāo)軸顏色  
  53.         xyplot.setOutlineStroke(new BasicStroke(1.5f)); // 邊框粗細(xì)  
  54.         va.setLabelPaint(new Color(101010)); // 坐標(biāo)軸標(biāo)題顏色  
  55.         va.setTickLabelPaint(new Color(102102102)); // 坐標(biāo)軸標(biāo)尺值顏色  
  56.         ValueAxis axis = xyplot.getRangeAxis();  
  57.         axis.setAxisLineStroke(new BasicStroke(1.5f));  
  58.  
  59.         XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot  
  60.                 .getRenderer();  
  61.         xylineandshaperenderer.setSeriesOutlinePaint(0, Color.WHITE);  
  62.         xylineandshaperenderer.setUseOutlinePaint(true);  
  63.         NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();  
  64.         numberaxis.setAutoRangeIncludesZero(false);  
  65.         numberaxis.setTickMarkInsideLength(2.0F);  
  66.         numberaxis.setTickMarkOutsideLength(0.0F);  
  67.         numberaxis.setAxisLineStroke(new BasicStroke(1.5f));  
  68.         numberaxis.setUpperBound(maxpress);  
  69.         numberaxis.setLowerBound(60);//最小值設(shè)置為60  
  70.         NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();  
  71.         numberaxis1.setTickMarkInsideLength(2.0F);  
  72.         numberaxis1.setTickMarkOutsideLength(0.0F);  
  73.         numberaxis1.setUpperBound(105d);  
  74.         numberaxis1.setLowerBound(35);  
  75.         numberaxis1.setAxisLineStroke(new BasicStroke(1.5f));  
  76.  
  77.         // if (xydataset != null) {  
  78.         XYBoxAnnotation box = new XYBoxAnnotation(008959); //正常血壓所在區(qū)域內(nèi)邊界  
  79.         XYBoxAnnotation box1 = new XYBoxAnnotation(0011979);//高血壓前期所在區(qū)域內(nèi)邊界  
  80.         XYBoxAnnotation box2 = new XYBoxAnnotation(0013989);//高血壓一期所在區(qū)域內(nèi)邊界  
  81.         XYBoxAnnotation box3 = new XYBoxAnnotation(0015999);//高血壓二期所在區(qū)域內(nèi)邊界  
  82.         XYTextAnnotation text1 = new XYTextAnnotation(nomal, 7062.5);//標(biāo)識(shí)“正常”  
  83.         XYTextAnnotation text = new XYTextAnnotation(fore, 7082.5);//“高血壓前期”  
  84.         XYTextAnnotation text2 = new XYTextAnnotation(one, 7091.5);//“高血壓一期”  
  85.         XYTextAnnotation text3 = new XYTextAnnotation(two, 70101.5);//“高血壓二期”  
  86.  
  87.           
  88.         //將上面的邊界線條,說明文字加入到xyplot中。  
  89.         xyplot.addAnnotation(box);  
  90.         xyplot.addAnnotation(box1);  
  91.         xyplot.addAnnotation(box2);  
  92.         xyplot.addAnnotation(box3);  
  93.  
  94.         xyplot.addAnnotation(text);  
  95.         xyplot.addAnnotation(text1);  
  96.         xyplot.addAnnotation(text2);  
  97.         xyplot.addAnnotation(text3);  
  98.         // }  
  99.         return jfreechart;  
  100.     } 

***一步,返回圖片URL

  1. public static void drawScatterChart(IrisIoInterface io, Log log,  
  2.             XYDataset xydataSet, String title, String shou, String shu,  
  3.             String nodata, String boolds, String nomal, String fore,  
  4.             String one, String two, List<PressureBean> list) {  
  5.  
  6.         JFreeChart chart = createChart(xydataSet, title, shou, shu, nodata,  
  7.                 boolds, nomal, fore, one, two, list, log);  
  8.  
  9.         HttpServletRequest request = io.getRequest();  
  10.         String filename = "";  
  11.         String graphURL = "";  
  12.         try {  
  13.             filename = ServletUtilities.saveChartAsPNG(chart, 400300null,  
  14.                     io.getSession());  
  15.             graphURL = request.getContextPath() + "/displayChart?filename=" 
  16.                     + filename;  
  17.         } catch (IOException e) {  
  18.             // TODO Auto-generated catch block  
  19.             e.printStackTrace();  
  20.             log.error(e);  
  21.         }  
  22.  
  23.         io.setData("filename", filename, BeanShare.BEAN_SHARE_REQUEST);  
  24.         io.setData("scatterurl", graphURL, BeanShare.BEAN_SHARE_REQUEST);  
  25.  
  26.     } 

效果圖:

原文鏈接:http://juliana-only.iteye.com/blog/544104

【編輯推薦】

  1. JFreeChart***實(shí)踐:折線圖
  2. JFreeChart***實(shí)踐:柱狀圖
  3. JFreeChart***實(shí)踐:3D餅圖
  4. JFreeChart***實(shí)踐:時(shí)序圖
  5. JFreeChart***實(shí)踐:甘特圖
責(zé)任編輯:林師授 來源: 遠(yuǎn)去的渡口博客
相關(guān)推薦

2011-12-21 13:52:27

JavaJFreeChart

2011-12-21 13:44:33

JavaJFreeChart

2011-12-21 14:15:08

JavaJFreeChart

2011-12-21 13:25:33

JavaJFreeChart

2011-12-21 12:58:41

JavaJFreeChart

2011-12-21 14:34:33

JavaJFreeChart

2011-12-21 12:46:43

2011-12-20 12:53:43

JavaJFreeChart

2023-07-21 01:12:30

Reactfalse?變量

2011-08-18 11:05:21

jQuery

2014-08-19 10:06:53

IAP

2024-08-21 08:02:47

2012-08-09 09:10:56

代碼審查代碼

2014-06-09 15:50:08

2015-09-23 09:08:38

java反射

2023-09-11 08:50:03

Maven工具關(guān)系管理

2023-09-13 08:00:00

JavaScript循環(huán)語句

2010-02-04 11:55:27

ibmdwDB2

2010-07-06 09:07:09

2023-05-15 08:24:46

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)