Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use JFreeChart to realize Line Chart

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use JFreeChart to achieve line chart, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Broken-line graphs can be divided into two types.

(1) the type of X-axis value is String.

2) it is common for X-axis values to be dated, and sometimes such requirements need to be met:

1. Time should be continuous.

2. Time can be set with a fixed span, for example, 2009-02-01 2009-02-04 2009-02-07.

3. Because of the large time span, we want to achieve different precision charts, such as yyyy-MM-dd format when the time is 10 days, 2 months when the time span is 2 months, weeks (such as the third week of 2009), and months (August 2009) when the span is 6 months.

Next, let's explain the more complex (2):

1. Get the data needed by the business logic: (the specific process is not verbose, that is, query the database, get the values of the desired fields, and load them into List) return List

The included properties of PressureBean:

Int userId; String bpDate; String bpTime; int syspress; / / systolic blood pressure (mmHg) int diapress; / diastolic blood pressure (mmHg)

2. Load the dataset

Public static TimeSeriesCollection createTimeSeries (List 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 / / display if by day (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 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) {/ / display TimeSeries timeseries = new TimeSeries (shou, org.jfree.data.time.Week.class) weekly 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 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 {/ / monthly display 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 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. Draw a line chart, two data sets, systolic blood pressure and diastolic blood pressure, and each of these two curves contains a regional range, not just a baseline, but a benchmark range.

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) {/ / users may deliberately enter abnormal values in later versions, but in order to ensure the integrity of the picture drawing Here we first calculate / / the * * value of the user's blood pressure value. Double maxpress = 0; double addmax = 50; double min = 40; if (list! = null & & list.size () > 0) {Iterator 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 >

On a monthly scale:

The above is all the content of the article "how to use JFreeChart to achieve line chart". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report