成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

如何使用JFreeChart實(shí)現(xiàn)折線圖

小編給大家分享一下如何使用JFreeChart實(shí)現(xiàn)折線圖,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

創(chuàng)新互聯(lián)企業(yè)建站,十多年網(wǎng)站建設(shè)經(jīng)驗(yàn),專注于網(wǎng)站建設(shè)技術(shù),精于網(wǎng)頁(yè)設(shè)計(jì),有多年建站和網(wǎng)站代運(yùn)營(yíng)經(jīng)驗(yàn),設(shè)計(jì)師為客戶打造網(wǎng)絡(luò)企業(yè)風(fēng)格,提供周到的建站售前咨詢和貼心的售后服務(wù)。對(duì)于網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站中不同領(lǐng)域進(jìn)行深入了解和探索,創(chuàng)新互聯(lián)在網(wǎng)站建設(shè)中充分了解客戶行業(yè)的需求,以靈動(dòng)的思維在網(wǎng)頁(yè)中充分展現(xiàn),通過對(duì)客戶行業(yè)精準(zhǔn)市場(chǎng)調(diào)研,為客戶提供的解決方案。

折線圖,大可分為兩種,

(1)X軸值類型為String的。

2)常用的是X軸值是日期的,并且,有時(shí)需要滿足這樣的需求:

1、時(shí)間要連續(xù)。

2、時(shí)間可以設(shè)置固定的跨度,比如,2009-02-01,2009-02-04,2009-02-07……

3、由于時(shí)間跨度較大,想要做到不同精度的圖表,如時(shí)間為10天時(shí),以日(yyyy-MM-dd)格式為精度,時(shí)間跨度為2個(gè)月時(shí),以周(如2009年第3周)為精度,跨度為6個(gè)月時(shí),以月(2009年8月)為精度。

下面,針對(duì)比較復(fù)雜的(2)來講解:

1、取到業(yè)務(wù)邏輯需要的數(shù)據(jù):(具體過程就不啰嗦了,就是查詢數(shù)據(jù)庫(kù),得到想要的字段的值,加載到List里面) 返回List<PressureBean>

PressureBean的包含的屬性:

int userId;      String bpDate;      String bpTime;      int syspress;  //收縮壓(mmHg)      int diapress; //舒張壓(mmHg)

2、加載數(shù)據(jù)集

public static TimeSeriesCollection createTimeSeries(              List<PressureBean> list, int dayOrweekOrmonth, Log log, String shou,String shu              ) {           TimeSeriesCollection timesers = new TimeSeriesCollection();           int mon = 1;          int day = 1;          int ye = 2000;          int week = 1;           // 按天顯示          if (dayOrweekOrmonth == 0) {               TimeSeries timeseries = new TimeSeries(shou,                      org.jfree.data.time.Day.class);              TimeSeries timeseries1 = new TimeSeries("c1",                      org.jfree.data.time.Day.class);               TimeSeries timeseriedia = new TimeSeries(shu,                      org.jfree.data.time.Day.class);              TimeSeries timeseriedia1 = new TimeSeries("d1",                      org.jfree.data.time.Day.class);               Iterator<PressureBean> it = list.iterator();              while (it.hasNext()) {                  PressureBean pres = it.next();                  String date = pres.getBpDate();                   ye = Integer.parseInt(date.substring(0, 4));                  mon = Integer.parseInt(date.substring(5, 7));                  day = Integer.parseInt(date.substring(8, date.length()));                  Day days = new Day(day, mon, ye);                   double sys = pres.getSyspress();                  double dia = pres.getDiapress();                  if (sys != -1 && sys > 0) {                      timeseries.add(days, sys);                  } else {                      timeseries1.add(days, null);                  }                  if (sys != -1 && sys > 0) {                      timeseriedia.add(days, dia);                  } else {                      timeseriedia1.add(days, null);                  }               }               timesers.addSeries(timeseries);              timesers.addSeries(timeseriedia);              timesers.addSeries(timeseries1);              timesers.addSeries(timeseriedia1);           } else if (dayOrweekOrmonth == 1) {//按周顯示              TimeSeries timeseries = new TimeSeries(shou,                      org.jfree.data.time.Week.class);              TimeSeries timeseries1 = new TimeSeries("c1",                      org.jfree.data.time.Week.class);               TimeSeries timeseriedia = new TimeSeries(shu,                      org.jfree.data.time.Week.class);              TimeSeries timeseriedia1 = new TimeSeries("d1",                      org.jfree.data.time.Week.class);               Iterator<PressureBean> it = list.iterator();              while (it.hasNext()) {                  PressureBean pres = it.next();                  String date = pres.getBpDate();                   String[] spls = date.split("-");                  if (spls.length == 2) {                      ye = Integer.parseInt(spls[0]);                      mon = Integer.parseInt(spls[1]);                  } else {                      log.error("the date of weeks is wrong");                  }                   Week days = new Week(mon, ye);                  double sys = pres.getSyspress();                  double dia = pres.getDiapress();                   if (sys != -1 && sys > 0) {                      timeseries.add(days, sys);                  } else {                      timeseries1.add(days, null);                  }                  if (sys != -1 && sys > 0) {                      timeseriedia.add(days, dia);                  } else {                      timeseriedia1.add(days, null);                  }               }               timesers.addSeries(timeseries);              timesers.addSeries(timeseriedia);              timesers.addSeries(timeseries1);                            timesers.addSeries(timeseriedia1);           } else {//按月顯示              TimeSeries timeseries = new TimeSeries(shou,                      org.jfree.data.time.Month.class);              TimeSeries timeseries1 = new TimeSeries("c1",                      org.jfree.data.time.Month.class);               TimeSeries timeseriedia = new TimeSeries(shu,                      org.jfree.data.time.Month.class);              TimeSeries timeseriedia1 = new TimeSeries("s",                      org.jfree.data.time.Month.class);               Iterator<PressureBean> it = list.iterator();              while (it.hasNext()) {                  PressureBean pres = it.next();                  String date = pres.getBpDate();                   String[] spls = date.split("-");                  if (spls.length == 2) {                      ye = Integer.parseInt(spls[0]);                      mon = Integer.parseInt(spls[1]);                  } else {                      log.error("the date of weeks is wrong");                  }                   Month days = new Month(mon, ye);                   double sys = pres.getSyspress();                  double dia = pres.getDiapress();                   if (sys != -1 && sys > 0) {                      timeseries.add(days, sys);                  } else {                      timeseries1.add(days, null);                  }                  if (sys != -1 && sys > 0) {                      timeseriedia.add(days, dia);                  } else {                      timeseriedia1.add(days, null);                  }               }              timesers.addSeries(timeseries);              timesers.addSeries(timeseriedia);              timesers.addSeries(timeseries1);                            timesers.addSeries(timeseriedia1);           }           return timesers;      }

3、畫折線圖,兩個(gè)數(shù)據(jù)集,收縮壓和舒張壓,并且,這兩條曲線還各自包含一個(gè)區(qū)域范圍,并不單單是一條基準(zhǔn)線,而是一個(gè)基準(zhǔn)范圍。

private static JFreeChart createChartPress(XYDataset xydataset,              int weekOrmonth, String title, String y, String index, String week,              String year, int searchby, String month, String nodatamess,              List list, Log log, String bp_shou, String bp_shuzhang) {           // 有可能用戶在后面的版本中故意輸入不正常數(shù)值,但是為了保證圖片畫圖的完整,這里先計(jì)算          // 用戶血壓值的***值。            double maxpress = 0;          double addmax = 50;          double min = 40;           if (list != null && list.size() > 0) {              Iterator<PressureBean> it = list.iterator();              while (it.hasNext()) {                  PressureBean pres = it.next();                  double sys = pres.getSyspress();                  double dia = pres.getDiapress();                   if (maxpress < sys) {                      maxpress = sys;                   }                   if (maxpress < dia)                      maxpress = dia;                   if (min > sys) {                      min = sys;                  }                   if (min > dia)                      min = dia;               }               maxpress += addmax;              min -= 10;                log.info("high press value is =" + maxpress);           }                    if (xydataset != null) {              int counts = xydataset.getItemCount(0);              if (counts == 0) {                  xydataset = null;              }          }           JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "",                  y, xydataset, true, true, false);          jfreechart.setBackgroundPaint(Color.white);                     // 設(shè)置標(biāo)題的顏色          TextTitle text = new TextTitle(title);          text.setPaint(new Color(102, 102, 102));          jfreechart.setTitle(text);          XYPlot xyplot = jfreechart.getXYPlot();          xyplot.setBackgroundPaint(new Color(255, 253, 246));          xyplot.setOutlineStroke(new BasicStroke(1.5f)); // 邊框粗細(xì)          ValueAxis vaxis = xyplot.getDomainAxis();          vaxis.setAxisLineStroke(new BasicStroke(1.5f)); // 坐標(biāo)軸粗細(xì)          vaxis.setAxisLinePaint(new Color(215, 215, 215)); // 坐標(biāo)軸顏色          xyplot.setOutlineStroke(new BasicStroke(1.5f)); // 邊框粗細(xì)          vaxis.setLabelPaint(new Color(10, 10, 10)); // 坐標(biāo)軸標(biāo)題顏色          vaxis.setTickLabelPaint(new Color(102, 102, 102)); // 坐標(biāo)軸標(biāo)尺值顏色          vaxis.setLowerMargin(0.06d);// 分類軸下(左)邊距          vaxis.setUpperMargin(0.14d);// 分類軸下(右)邊距,防止***邊的一個(gè)數(shù)據(jù)靠近了坐標(biāo)軸。                    //X軸為日期格式,這里是專門的處理日期的類,          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");          DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();          if (weekOrmonth == 0) {//以天為刻度,時(shí)間格式為yyyy-MM-dd,如2008-02-06              dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1, format));          } else if (weekOrmonth == 1) {//以周為刻度,時(shí)間顯示為 2009年第4周((這里是SimpleDateFormat的用法,              //這里為了作繁體版,英文版和簡(jiǎn)體版,用了國(guó)際化處理,將這些可變的資源在文字資源里面,注意一下,這里的y,M、w是SimpleDateFormat的關(guān)鍵字,              //如英文表示09年第3周就是09W3,那么,這里的W需要用&lsquo;&rsquo;引起來)              format = new SimpleDateFormat("yyyy" + year + index + "w" + week);              dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7, format));          } else if (weekOrmonth == 2) {//以月為刻度,時(shí)間顯示為09-02 (09年2月)              format = new SimpleDateFormat("yy-MM");              dateaxis                      .setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1, format));           }          dateaxis.setVerticalTickLabels(false); // 設(shè)為true表示橫坐標(biāo)旋轉(zhuǎn)到垂直。          if (searchby == 6 || searchby == 3) {              dateaxis.setAutoTickUnitSelection(true); // 由于橫軸標(biāo)簽過多,這里設(shè)置為自動(dòng)格式 。              dateaxis.setDateFormatOverride(format);          }          dateaxis.setTickMarkPosition(DateTickMarkPosition.START);           ValueAxis valueAxis = xyplot.getRangeAxis();          valueAxis.setUpperBound(maxpress);          valueAxis.setAutoRangeMinimumSize(1);          valueAxis.setLowerBound(min);          valueAxis.setAutoRange(false);           valueAxis.setAxisLineStroke(new BasicStroke(1.5f)); // 坐標(biāo)軸粗細(xì)          valueAxis.setAxisLinePaint(new Color(215, 215, 215)); // 坐標(biāo)軸顏色          valueAxis.setLabelPaint(new Color(10, 10, 10)); // 坐標(biāo)軸標(biāo)題顏色          valueAxis.setTickLabelPaint(new Color(102, 102, 102)); // 坐標(biāo)軸標(biāo)尺值顏色                    xyplot.setRangeGridlinesVisible(true);          xyplot.setDomainGridlinesVisible(true);          xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);          xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);          xyplot.setBackgroundPaint(new Color(255, 253, 246));          xyplot.setNoDataMessage(nodatamess);//沒有數(shù)據(jù)時(shí)顯示的文字說明。          xyplot.setNoDataMessageFont(new Font("", Font.BOLD, 14));//字體的大小,粗體。          xyplot.setNoDataMessagePaint(new Color(87, 149, 117));//字體顏色          xyplot.setAxisOffset(new RectangleInsets(0d, 0d, 0d, 5d)); //           // add range marker(舒張壓的區(qū)域marker,范圍是從62到81)           double lowpress = 62;          double uperpress = 81;          IntervalMarker intermarker = new IntervalMarker(lowpress, uperpress);          intermarker.setPaint(Color.decode("#66FFCC"));// 域顏色                    intermarker.setLabelFont(new Font("SansSerif", 41, 14));          intermarker.setLabelPaint(Color.RED);          intermarker.setLabel(bp_shuzhang);           if (xydataset != null) {              xyplot.addRangeMarker(intermarker, Layer.BACKGROUND);          }      //(收縮壓的區(qū)域marker,范圍是從102到120)          double lowpress1 = 102;          double uperpress1 = 120;          IntervalMarker inter = new IntervalMarker(lowpress1, uperpress1);          inter.setLabelOffsetType(LengthAdjustmentType.EXPAND);          inter.setPaint(Color.decode("#66FFCC"));// 域顏色            inter.setLabelFont(new Font("SansSerif", 41, 14));          inter.setLabelPaint(Color.RED);          inter.setLabel(bp_shou);                    if (xydataset != null) {              xyplot.addRangeMarker(inter, Layer.BACKGROUND); // 加上Layer.BACKGROUND,將maker調(diào)到折線下面。          }           XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot                  .getRenderer();          //***條折線的顏色          xylineandshaperenderer.setBaseItemLabelsVisible(true);          xylineandshaperenderer.setSeriesFillPaint(0, new Color(127, 128, 0));          xylineandshaperenderer.setSeriesPaint(0, new Color(127, 128, 0));           xylineandshaperenderer.setSeriesShapesVisible(0, true);          xylineandshaperenderer.setSeriesShapesVisible(1, true);           //第二條折線的顏色          xylineandshaperenderer.setSeriesFillPaint(1, new Color(254, 103, 0));          xylineandshaperenderer.setSeriesPaint(1, new Color(254, 103, 0));          xylineandshaperenderer.setSeriesShapesVisible(1, true);          xylineandshaperenderer.setSeriesVisible(2, false);//          xylineandshaperenderer.setSeriesVisible(3, false);//不顯示下面標(biāo)題           //折線的粗細(xì)調(diào)          StandardXYToolTipGenerator xytool = new StandardXYToolTipGenerator();          xylineandshaperenderer.setToolTipGenerator(xytool);          xylineandshaperenderer.setStroke(new BasicStroke(1.5f));           // 顯示節(jié)點(diǎn)的值          xylineandshaperenderer.setBaseItemLabelsVisible(true);          xylineandshaperenderer                  .setBasePositiveItemLabelPosition(new ItemLabelPosition(                          ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));          xylineandshaperenderer                  .setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());          xylineandshaperenderer.setBaseItemLabelPaint(new Color(102, 102, 102));// 顯示折點(diǎn)數(shù)值字體的顏色           return jfreechart;      }

4、將圖片URL返回到頁(yè)面

public static void drawPressLineChart(IrisIoInterface io, Log log,              TimeSeriesCollection timesers, int weekormonth, String title,              String y, String index, String week, String year, int searchby,              String month, String nodatamess, List list, String bp_shou,              String bp_shuzhang) {           JFreeChart chart = createChartPress(timesers, weekormonth, title, y,                  index, week, year, searchby, month, nodatamess, list, log,                  bp_shou, bp_shuzhang);           HttpServletRequest request = io.getRequest();          String filename = "";          String graphURL = "";          try {              filename = ServletUtilities.saveChartAsPNG(chart, 650, 280, null,                      io.getSession());              graphURL = request.getContextPath() + "/displayChart?filename="                     + filename;          } catch (IOException e) {              // TODO Auto-generated catch block              e.printStackTrace();              log.error(e);          }           io.setData("filename1", filename, BeanShare.BEAN_SHARE_REQUEST);          io.setData("presslineurl", graphURL, BeanShare.BEAN_SHARE_REQUEST);       }

效果圖如下:

以天為刻度:

如何使用JFreeChart實(shí)現(xiàn)折線圖

以周為刻度:

如何使用JFreeChart實(shí)現(xiàn)折線圖

以月為刻度:

如何使用JFreeChart實(shí)現(xiàn)折線圖

以上是“如何使用JFreeChart實(shí)現(xiàn)折線圖”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

本文名稱:如何使用JFreeChart實(shí)現(xiàn)折線圖
URL網(wǎng)址:http://jinyejixie.com/article48/ggssep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站建站公司、網(wǎng)站排名、品牌網(wǎng)站制作品牌網(wǎng)站建設(shè)、搜索引擎優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)
固安县| 嫩江县| 苗栗县| 吉林市| 临西县| 保亭| 东丰县| 句容市| 邯郸县| 东丰县| 华坪县| 霍林郭勒市| 遂宁市| 冕宁县| 凌海市| 施秉县| 平潭县| 临邑县| 浏阳市| 尉犁县| 溧水县| 海阳市| 紫金县| 永德县| 麻江县| 马尔康县| 本溪| 榆社县| 连云港市| 南乐县| 平原县| 蓬莱市| 常熟市| 新密市| 金湖县| 石家庄市| 通榆县| 南康市| 濉溪县| 湾仔区| 贵港市|