List of usage examples for org.jfree.data.time TimeSeries TimeSeries
public TimeSeries(Comparable name, Class timePeriodClass)
From source file:org.jfree.chart.demo.MarkerDemo1.java
/** * Returns a sample data series (for supplier 2). * * @return A sample data series./*ww w. j av a 2s.c o m*/ */ private TimeSeries createSupplier2Bids() { final Hour hour1 = new Hour(1, new Day(22, 5, 2003)); final Hour hour2 = (Hour) hour1.next(); final TimeSeries series2 = new TimeSeries("Supplier 2", Minute.class); series2.add(new Minute(25, hour1), 185.0); series2.add(new Minute(0, hour2), 175.0); series2.add(new Minute(5, hour2), 170.0); series2.add(new Minute(6, hour2), 168.0); series2.add(new Minute(9, hour2), 165.0); series2.add(new Minute(10, hour2), 163.0); return series2; }
From source file:OverlaidXYPlotDemo2.java
/** * Creates a sample dataset.//from ww w. j av a2 s . c o m * * @return The dataset. */ private XYDataset createDataset2B() { // create dataset 2... final TimeSeries series2 = new TimeSeries("Series 2B", Day.class); series2.add(new Day(3, SerialDate.MARCH, 2002), 43.9); series2.add(new Day(4, SerialDate.MARCH, 2002), 72.6); series2.add(new Day(5, SerialDate.MARCH, 2002), 89.4); series2.add(new Day(6, SerialDate.MARCH, 2002), 23.8); series2.add(new Day(7, SerialDate.MARCH, 2002), 45.0); series2.add(new Day(8, SerialDate.MARCH, 2002), 65.8); series2.add(new Day(9, SerialDate.MARCH, 2002), 92.1); series2.add(new Day(10, SerialDate.MARCH, 2002), 84.7); series2.add(new Day(11, SerialDate.MARCH, 2002), 77.2); series2.add(new Day(12, SerialDate.MARCH, 2002), 65.1); series2.add(new Day(13, SerialDate.MARCH, 2002), 78.5); series2.add(new Day(14, SerialDate.MARCH, 2002), 75.3); series2.add(new Day(15, SerialDate.MARCH, 2002), 69.9); series2.add(new Day(20, SerialDate.MARCH, 2002), 56.6); final TimeSeriesCollection result = new TimeSeriesCollection(series2); result.setXPosition(TimePeriodAnchor.MIDDLE); return result; }
From source file:oscar.form.study.hsfo2.pageUtil.ManageHSFOAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { logger.info("ContextPath: " + request.getContextPath()); logger.info("pathInfo: " + request.getPathInfo()); Map<String, String[]> params = request.getParameterMap(); Hsfo2Visit latestHsfo2Visit = new Hsfo2Visit(); PatientList historyList = new PatientList(); // RecordList record = new RecordList(); List recordList = new LinkedList(); String patientId = (String) request.getAttribute("demographic_no"); if (patientId == null) { patientId = request.getParameter("demographic_no"); }/*from ww w . j a v a 2s. co m*/ String isfirstrecord = ""; boolean isFirstRecord = false; String user = (String) request.getSession().getAttribute("user"); HSFODAO hsfoDAO = new HSFODAO(); isFirstRecord = hsfoDAO.isFirstRecord(patientId); DemographicData demoData = new DemographicData(); //DemographicData.Demographic de = demoData.getDemographic( patientId ); Demographic de = demoData.getDemographic(patientId); boolean isDisplayGraphs = "displayGraphs".equalsIgnoreCase(request.getParameter("operation")); boolean isFromRegistrationForm = false; if ("true".equalsIgnoreCase(request.getParameter("isFromRegistrationForm"))) { //true means the request is from registration form, should goto followup form isFromRegistrationForm = true; } FORM forwardToForm = null; int patientHistorySize = 0; boolean isFirstVisitRecordForThePatient = false; // boolean isFromRegistrationForm = false; Integer formId = getFormIdFromRequest(request); Hsfo2Visit formHsfo2Visit = null; if (formId != null) formHsfo2Visit = hsfoDAO.retrieveSelectedRecord(formId); boolean isHistoryForm = !isFromRegistrationForm && (formId != null && formHsfo2Visit != null); if (formId != null) isFirstVisitRecordForThePatient = hsfoDAO.isFirstVisitRecordForThePatient(patientId, formId); boolean isRegistForm = !isDisplayGraphs && !isFromRegistrationForm && (isFirstRecord || isFirstVisitRecordForThePatient); //prepare data Hsfo2Patient hsfo2Patient = hsfoDAO.retrievePatientRecord(patientId); if (hsfo2Patient == null) hsfo2Patient = new Hsfo2Patient(); List patientHistory = hsfoDAO.retrieveVisitRecord(patientId); //save only or submit, it's for registration form and stay in that form boolean isSaveOnly = "Save".equalsIgnoreCase(request.getParameter("Save")); if (!isSaveOnly && !isFirstRecord) { isSaveOnly = !hsfo2Patient.isSubmitted(); } if (isSaveOnly) { //stay in regist form and treat as history isRegistForm = true; isHistoryForm = true; if (patientHistory.size() > 0) formHsfo2Visit = (Hsfo2Visit) patientHistory.get(patientHistory.size() - 1); } if (isHistoryForm) { latestHsfo2Visit = formHsfo2Visit; } else // create new form { patientHistorySize = patientHistory.size(); if (patientHistorySize >= 1) { latestHsfo2Visit = (Hsfo2Visit) patientHistory.get(patientHistorySize - 1); latestHsfo2Visit.setVisitDateIdToday(); latestHsfo2Visit.setId(hsfoDAO.getMaxVisitId() + 1); cleanNonePrefilledData(latestHsfo2Visit); getLabWork(latestHsfo2Visit, hsfo2Patient, ConvertUtil.toInt(patientId)); //If it's followup form, BP should not be prepopulated. Clean again. latestHsfo2Visit.setSBP(0); latestHsfo2Visit.setDBP(0); } else { latestHsfo2Visit = new Hsfo2Visit(); latestHsfo2Visit.setVisitDateIdToday(); getLabWork(latestHsfo2Visit, hsfo2Patient, ConvertUtil.toInt(patientId)); } } if (isRegistForm) { // registration, get data from DemographicData; isfirstrecord = "true"; hsfo2Patient.setPatient_Id(patientId); if (!isHistoryForm) { hsfo2Patient.setFName(de.getFirstName()); hsfo2Patient.setLName(de.getLastName()); hsfo2Patient.setBirthDate(oscar.util.DateUtils.toDate(de.getFormattedDob())); hsfo2Patient.setSex(de.getSex()); hsfo2Patient.setPostalCode(de.getPostal()); hsfo2Patient.setRegistrationId(HsfoUtil.getRegistrationId()); latestHsfo2Visit.setVisitDateIdToday(); } request.setAttribute("EmrHCPId1", user); request.setAttribute("EmrHCPId2", de.getProviderNo()); // TODO: may need to convert to provider name forwardToForm = FORM.registration; } else { //populate graphy data for followup form. the latestHsfo2Visit already keep the information of last visit. isfirstrecord = "false"; if (!isDisplayGraphs) forwardToForm = FORM.flowsheet; else { // If patientHistory is greater than 1 than fill the graphing arrays TimeSeries sbpSeries = new TimeSeries("Systolic Blood Pressure", Day.class); TimeSeries dbpSeries = new TimeSeries("Diastolic Blood Pressure", Day.class); TimeSeries bmiSeries = new TimeSeries("BMI", Day.class); TimeSeries waistSeries = new TimeSeries("Waist", Day.class); TimeSeries ldlSeries = new TimeSeries("LDL", Day.class); TimeSeries tcHdlSeries = new TimeSeries("TC/HDL", Day.class); TimeSeries importanceSeries = new TimeSeries("Importance", Day.class); TimeSeries confidenceSeries = new TimeSeries("Confidence", Day.class); Map<GraphDesc, TimeSeries> graphDescSeriesMap = new HashMap<GraphDesc, TimeSeries>(); graphDescSeriesMap.put(new GraphDesc("Systolic Blood Pressure", "Dates", "SBP(mmHg)"), sbpSeries); graphDescSeriesMap.put(new GraphDesc("Diastolic Blood Pressure", "Dates", "DBP(mmHg)"), dbpSeries); graphDescSeriesMap.put(new GraphDesc("BMI", "Dates", "BMI(kg/m2)"), bmiSeries); graphDescSeriesMap.put(new GraphDesc("Waist", "Dates", "Waist(cm)"), waistSeries); graphDescSeriesMap.put(new GraphDesc("LDL", "Dates", "LDL(mmol/L)"), ldlSeries); { GraphDesc tcHdlDesc = new GraphDesc("TC/HDL", "Dates", "TC/HDL(ratio)"); tcHdlDesc.setFileName("TC_HDL"); graphDescSeriesMap.put(tcHdlDesc, tcHdlSeries); } graphDescSeriesMap.put(new GraphDesc("Importance", "Dates", "Importance(1-10)"), importanceSeries); graphDescSeriesMap.put(new GraphDesc("Confidence", "Dates", "Confidence(1-10)"), confidenceSeries); if (patientHistorySize >= 1) { ListIterator patientHistoryIt = patientHistory.listIterator(); // int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0; while (patientHistoryIt.hasNext()) { Hsfo2Visit Hsfo2Visit = (Hsfo2Visit) patientHistoryIt.next(); // visitDateArray.add( setDateFull( Hsfo2Visit.getVisitDate_Id() ) ); // visitIdArray.add( "" + Hsfo2Visit.getID() ); // //////// final Date visitDate = Hsfo2Visit.getVisitDate_Id(); if (visitDate != null) { final Day visitDay = new Day(visitDate); if (Hsfo2Visit.getSBP() != 0) { sbpSeries.addOrUpdate(visitDay, Hsfo2Visit.getSBP()); } if (Hsfo2Visit.getDBP() != 0) { dbpSeries.addOrUpdate(visitDay, Hsfo2Visit.getDBP()); } if (Hsfo2Visit.getWeight() != 0) { Double bmi = getBmi(Hsfo2Visit, hsfo2Patient); if (bmi > 0) bmiSeries.addOrUpdate(visitDay, bmi); } // modified by victor for waist_unit null bug,2007 // if (Hsfo2Visit.getWaist() != 0{ if (Hsfo2Visit.getWaist() != 0 && Hsfo2Visit.getWaist_unit() != null) { double waistv = Hsfo2Visit.getWaist(); String waistunit = Hsfo2Visit.getWaist_unit(); double waist = 0.0; if (waistunit.equals("cm")) { waist = waistv; } else { // 1 inch = 2.54 cm waist = waistv * 2.54; } waistSeries.addOrUpdate(visitDay, waist); } if (Hsfo2Visit.getChange_importance() != 0) { importanceSeries.addOrUpdate(visitDay, Hsfo2Visit.getChange_importance()); } if (Hsfo2Visit.getChange_confidence() != 0) { confidenceSeries.addOrUpdate(visitDay, Hsfo2Visit.getChange_confidence()); } } final Date labResultDate = Hsfo2Visit.getTC_HDL_LabresultsDate(); if (labResultDate != null) { final Day labResultDay = new Day(labResultDate); if (Hsfo2Visit.getTC_HDL() != 0) { tcHdlSeries.addOrUpdate(labResultDay, Hsfo2Visit.getTC_HDL()); } if (Hsfo2Visit.getLDL() != 0) { ldlSeries.addOrUpdate(labResultDay, Hsfo2Visit.getLDL()); } } } } //generate the graph and export as picture. generateGraphs(request, response, graphDescSeriesMap); forwardToForm = FORM.graphs; ; } } historyList.setPatientHistory(patientHistory); // set request attributes to forward to jsp request.setAttribute("siteId", OscarProperties.getInstance().getProperty("hsfo2.loginSiteCode", "xxx")); request.setAttribute("Hsfo2Patient", hsfo2Patient); request.setAttribute("historyList", historyList); request.setAttribute("Hsfo2Visit", latestHsfo2Visit); //getDay() is date of week request.setAttribute("isFirstRecord", isfirstrecord); return mapping.findForward(forwardToForm.name()); }
From source file:edu.fullerton.viewerplugin.TsPlot.java
private TimeSeries LinFit(TimeSeries ts) { TimeSeries ret = new TimeSeries("lin fit", Millisecond.class); SimpleTimeZone utctz = new SimpleTimeZone(0, "UTC"); int n = ts.getItemCount(); double[] x = new double[n]; double[] y = new double[n]; TimeSeriesDataItem it;//from w ww. java 2 s . co m for (int i = 0; i < n; i++) { it = ts.getDataItem(i); x[i] = it.getPeriod().getFirstMillisecond() + 0.; y[i] = it.getValue().doubleValue(); } LinearRegression lr = new LinearRegression(x, y); double b = lr.getIntercept(); double m = lr.getSlope(); double fit, t; for (int i = 0; i < n; i++) { it = ts.getDataItem(i); t = it.getPeriod().getFirstMillisecond() + 0.; fit = m * t + b; ret.addOrUpdate(it.getPeriod(), fit); } return ret; }
From source file:org.orbeon.oxf.processor.serializer.legacy.JFreeChartSerializer.java
protected TimeSeriesCollection createTimeSeriesDataset(ChartConfig chartConfig, Document data) { TimeSeriesCollection ds = new TimeSeriesCollection(); for (Iterator i = chartConfig.getValueIterator(); i.hasNext();) { Value value = (Value) i.next();//from www .ja v a 2 s. c om String title = value.getTitle(); Iterator x = XPathUtils.selectIterator(data, value.getCategories()); Iterator y = XPathUtils.selectIterator(data, value.getSeries()); TimeSeries timeSeries = new TimeSeries(title, FixedMillisecond.class); while (x.hasNext() && y.hasNext()) { Node s = (Node) y.next(); Node c = (Node) x.next(); SimpleDateFormat sdf = new SimpleDateFormat(chartConfig.getDateFormat()); FixedMillisecond fm; try { fm = new FixedMillisecond(sdf.parse(c.getStringValue()).getTime()); } catch (java.text.ParseException pe) { throw new OXFException( "Date Format " + chartConfig.getDateFormat() + " does not match with the date data", pe); } Double ordinate = new Double(s.getStringValue()); timeSeries.add(fm, ordinate); } ds.addSeries(timeSeries); } return ds; }
From source file:at.ac.tuwien.ibk.biqini.pep.gui.PEPGUI.java
/** * sets up all charts for later usage/*from w w w. j a va2s . co m*/ */ public void insertAllCharts() { for (int i = 0; i < MAXCHARTS; i++) { tsc[i] = new TimeSeriesCollection(new TimeSeries("unused", Millisecond.class)); charts[i] = ChartFactory.createTimeSeriesChart("unused", null, "bitrate kbit/sec", tsc[i], false, true, false); XYPlot plot = charts[i].getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(DISPLAYEDTIME); axis = plot.getRangeAxis(); axis.setRange(0.0, 128); ChartPanel chartPanel = new ChartPanel(charts[i]); // do the layout stuff GridBagConstraints c = new GridBagConstraints(); c.weighty = 3; c.weightx = 10.0; c.fill = GridBagConstraints.BOTH; c.insets = new Insets(0, 0, 0, 0); c.gridx = 1; c.gridy = i; c.gridwidth = 1; c.gridheight = 1; gridBagLayout.setConstraints(chartPanel, c); // paste it content.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(1000, 270)); } }
From source file:edu.unibonn.kmeans.mapreduce.plotting.TimeSeriesPlotter_KMeans.java
private XYDataset createDataset(ArrayList<Cluster_KMeans> clusters, LocalDateTime from) { final TimeSeriesCollection dataset = new TimeSeriesCollection(); // for (int i = 0; i < clusters.size(); i++) // {/* www .java 2 s. co m*/ // Cluster_KMeans current_cluster = clusters.get(i); // double[] center_of_mass = current_cluster.getCenter_of_mass(); // // final TimeSeries s1 = new TimeSeries("Cluster_"+current_cluster.getCluster_id(), Hour.class); // // for (int j = 0; j < 24; j++) // { // s1.add(new Hour( j, from.getDayOfMonth(), from.getMonthValue(), from.getYear() ), center_of_mass[j]); // } // // dataset.addSeries(s1); // } for (int i = 0; i < clusters.size(); i++) { Cluster_KMeans current_cluster = clusters.get(i); ArrayList<Day_24d> member_time_series = current_cluster.getMembership(); for (Iterator iterator = member_time_series.iterator(); iterator.hasNext();) { final TimeSeries s1 = new TimeSeries("Cluster_" + current_cluster.getCluster_id(), Hour.class); Day_24d current_series = (Day_24d) iterator.next(); for (int j = 0; j < 24; j++) { s1.add(new Hour(j, from.getDayOfMonth(), from.getMonthValue(), from.getYear()), current_series.getMeasurement(j)); } dataset.addSeries(s1); } } dataset.setDomainIsPointsInTime(true); return dataset; }
From source file:AtomPanel.java
private void initJFreeChart() { this.numOfStream = numOfStream; datasets = new TimeSeriesCollection(); trend = new TimeSeriesCollection(); projpcs = new TimeSeriesCollection(); spe = new TimeSeriesCollection(); for (int i = 0; i < MaxNumOfStream; i++) { //add streams TimeSeries timeseries = new TimeSeries("Stream " + i, Millisecond.class); datasets.addSeries(timeseries);//from w ww .jav a 2 s . c om timeseries.setHistoryCount(historyRange); //add trend variables TimeSeries trendSeries = new TimeSeries("Trend " + i, Millisecond.class); trend.addSeries(trendSeries); trendSeries.setHistoryCount(historyRange); //add proj onto PCs variables TimeSeries PC = new TimeSeries("Projpcs " + i, Millisecond.class); projpcs.addSeries(PC); PC.setHistoryCount(historyRange); //add spe streams TimeSeries speSeries = new TimeSeries("Spe " + i, Millisecond.class); spe.addSeries(speSeries); speSeries.setHistoryCount(historyRange); } combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Time")); //data stream plot DateAxis domain = new DateAxis("Time"); NumberAxis range = new NumberAxis("Streams"); domain.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); range.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); domain.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); range.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); XYItemRenderer renderer = new DefaultXYItemRenderer(); renderer.setItemLabelsVisible(false); renderer.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); XYPlot plot = new XYPlot(datasets, domain, range, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); domain.setAutoRange(true); domain.setLowerMargin(0.0); domain.setUpperMargin(0.0); domain.setTickLabelsVisible(true); range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); combineddomainxyplot.add(plot); //Trend captured by pca DateAxis domain0 = new DateAxis("Time"); NumberAxis range0 = new NumberAxis("PCA Trend"); domain0.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); range0.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); domain0.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); range0.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); XYItemRenderer renderer0 = new DefaultXYItemRenderer(); renderer0.setItemLabelsVisible(false); renderer0.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); renderer0.setSeriesPaint(0, Color.blue); renderer0.setSeriesPaint(1, Color.red); renderer0.setSeriesPaint(2, Color.magenta); XYPlot plot0 = new XYPlot(trend, domain0, range0, renderer0); plot0.setBackgroundPaint(Color.lightGray); plot0.setDomainGridlinePaint(Color.white); plot0.setRangeGridlinePaint(Color.white); plot0.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); domain0.setAutoRange(true); domain0.setLowerMargin(0.0); domain0.setUpperMargin(0.0); domain0.setTickLabelsVisible(false); range0.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); combineddomainxyplot.add(plot0); //proj on PCs plot DateAxis domain1 = new DateAxis("Time"); NumberAxis range1 = new NumberAxis("Proj on PCs"); domain1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); range1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); domain1.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); range1.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); XYItemRenderer renderer1 = new DefaultXYItemRenderer(); renderer1.setItemLabelsVisible(false); renderer1.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesPaint(0, Color.blue); renderer1.setSeriesPaint(1, Color.red); renderer1.setSeriesPaint(2, Color.magenta); plot1 = new XYPlot(projpcs, domain1, range1, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); plot1.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); domain1.setAutoRange(true); domain1.setLowerMargin(0.0); domain1.setUpperMargin(0.0); domain1.setTickLabelsVisible(false); range1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); combineddomainxyplot.add(plot1); //spe plot DateAxis domain2 = new DateAxis("Time"); NumberAxis range2 = new NumberAxis("SPE"); domain2.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); range2.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); domain2.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); range2.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); XYItemRenderer renderer2 = new DefaultXYItemRenderer(); renderer2.setItemLabelsVisible(false); renderer2.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); XYPlot plot2 = new XYPlot(spe, domain2, range2, renderer); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); plot2.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); domain2.setAutoRange(true); domain2.setLowerMargin(0.0); domain2.setUpperMargin(0.0); domain2.setTickLabelsVisible(true); range2.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); combineddomainxyplot.add(plot2); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(historyRange); // 60 seconds JFreeChart chart; if (this.pcaType == AtomUtils.PCAType.pca) chart = new JFreeChart("CloudWatch-ATOM with Exact Data", new Font("SansSerif", Font.BOLD, 18), combineddomainxyplot, false); else if (this.pcaType == AtomUtils.PCAType.pcaTrack) chart = new JFreeChart("CloudWatch-ATOM with Fixed Tracking Threshold", new Font("SansSerif", Font.BOLD, 18), combineddomainxyplot, false); else chart = new JFreeChart("CloudWatch-ATOM with Dynamic Tracking Threshold", new Font("SansSerif", Font.BOLD, 18), combineddomainxyplot, false); chart.setBackgroundPaint(Color.white); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black))); AtomPanel.this.add(chartPanel, BorderLayout.CENTER); }
From source file:dbseer.gui.panel.DBSeerLiveMonitorPanel.java
public synchronized void setCurrentTPS(long time, int index, double tps) { synchronized (LiveMonitorInfo.LOCK) { DefaultTableModel model = (DefaultTableModel) monitorTable.getModel(); if (model.getRowCount() <= 2 + (index * ROW_PER_TX_TYPE)) { model.addRow(new Object[] { "", "" }); }//from www . j ava2 s . c o m model.setValueAt(String.format("%.1f", tps), 2 + (index * ROW_PER_TX_TYPE), 1); if (numTransactionType < index + 1) { String newName = "Type " + (index + 1); transactionNames.add(newName); numTransactionType = index + 1; JLabel newLabel = new JLabel(newName); JButton renameButton = new JButton("Rename"); JButton viewSampleButton = new JButton("View Examples"); // JButton enableDisableButton; // if (DBSeerGUI.liveDataset.isTransactionEnabled(index)) // { // enableDisableButton = new JButton("Disable"); // } // else // { // enableDisableButton = new JButton("Enable"); // } renameButton.addActionListener(this); viewSampleButton.addActionListener(this); // enableDisableButton.addActionListener(this); transactionTypesPanel.add(newLabel); transactionTypesPanel.add(renameButton); transactionTypesPanel.add(viewSampleButton); // transactionTypesPanel.add(enableDisableButton); transactionLabels.add(newLabel); transactionRenameButtons.add(renameButton); transactionViewSampleButtons.add(viewSampleButton); // transactionEnableDisableButtons.add(enableDisableButton); for (DBSeerDataSet dataset : DBSeerGUI.liveDatasets) { dataset.addTransactionType("Type " + numTransactionType); } // TimeSeriesCollection newThroughputCollection = new TimeSeriesCollection(new TimeSeries(newName, Millisecond.class)); // TimeSeriesCollection collection = (TimeSeriesCollection) throughputChartPanel.getChart().getXYPlot().getDataset(); throughputCollection.addSeries(new TimeSeries(newName, Millisecond.class)); latencyCollection.addSeries(new TimeSeries(newName, Millisecond.class)); // throughputChartPanel.getChart().getXYPlot().setDataset(index, newThroughputCollection); this.revalidate(); this.repaint(); } model.setValueAt(String.format("Current TPS of '%s' transactions", transactionNames.get(index)), 2 + (index * ROW_PER_TX_TYPE), 0); // TimeSeriesCollection collection = (TimeSeriesCollection) throughputChartPanel.getChart().getXYPlot().getDataset(); if (index < throughputCollection.getSeriesCount()) { TimeSeries series = throughputCollection.getSeries(index); // series.add(new Millisecond(), tps); series.addOrUpdate(new Millisecond(new Date(time * 1000)), tps); } } }
From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java
JFreeChart referenceRangeChart(String demographicNo, String typeIdName, String typeIdName2, String patientName, String chartTitle) {/* w w w. j av a 2 s . c o m*/ org.jfree.data.time.TimeSeriesCollection dataset = new org.jfree.data.time.TimeSeriesCollection(); ArrayList<EctMeasurementsDataBean> list = getList(demographicNo, typeIdName); ArrayList<OHLCDataItem> dataItems = new ArrayList<OHLCDataItem>(); String typeYAxisName = ""; if (typeIdName.equals("BP")) { log.debug("Using BP LOGIC FOR type 1 "); EctMeasurementsDataBean sampleLine = list.get(0); typeYAxisName = sampleLine.getTypeDescription(); TimeSeries systolic = new TimeSeries("Systolic", Day.class); TimeSeries diastolic = new TimeSeries("Diastolic", Day.class); for (EctMeasurementsDataBean mdb : list) { // dataVector) { String[] str = mdb.getDataField().split("/"); systolic.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(str[0])); diastolic.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(str[1])); } dataset.addSeries(diastolic); dataset.addSeries(systolic); } else { log.debug("Not Using BP LOGIC FOR type 1 "); // get the name from the TimeSeries EctMeasurementsDataBean sampleLine = list.get(0); String typeLegendName = sampleLine.getTypeDisplayName(); typeYAxisName = sampleLine.getTypeDescription(); // this should be the type of measurement TimeSeries newSeries = new TimeSeries(typeLegendName, Day.class); for (EctMeasurementsDataBean mdb : list) { //dataVector) { newSeries.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(mdb.getDataField())); try { Hashtable h = getMeasurementsExt(mdb.getId()); if (h != null && h.containsKey("minimum")) { String min = (String) h.get("minimum"); String max = (String) h.get("maximum"); double open = Double.parseDouble(min.trim()); double high = Double.parseDouble(max.trim()); double low = Double.parseDouble(min.trim()); double close = Double.parseDouble(max.trim()); double volume = 1045; dataItems .add(new OHLCDataItem(mdb.getDateObservedAsDate(), open, high, low, close, volume)); } } catch (Exception et) { MiscUtils.getLogger().error("Error", et); } } dataset.addSeries(newSeries); } OHLCDataItem[] ohlc = dataItems.toArray(new OHLCDataItem[dataItems.size()]); JFreeChart chart = ChartFactory.createHighLowChart("HighLowChartDemo2", "Time", "Value", new DefaultOHLCDataset("DREFERENCE RANGE", ohlc), true); XYPlot plot = (XYPlot) chart.getPlot(); // HighLowRenderer renderer = (HighLowRenderer) plot.getRenderer(); // renderer. // renderer.setOpenTickPaint(Color.green); // renderer.setCloseTickPaint(Color.black); plot.setDataset(1, dataset); plot.getDomainAxis().setAutoRange(true); log.debug("LEN " + plot.getDomainAxis().getLowerBound() + " ddd " + plot.getDomainAxis().getUpperMargin() + " eee " + plot.getDomainAxis().getLowerMargin()); //plot.getDomainAxis().setUpperMargin(plot.getDomainAxis().getUpperMargin()*6); //plot.getDomainAxis().setLowerMargin(plot.getDomainAxis().getLowerMargin()*6); // plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin()*1.7); plot.getDomainAxis().setUpperMargin(0.9); plot.getDomainAxis().setLowerMargin(0.9); plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 4); ValueAxis va = plot.getRangeAxis(); va.setAutoRange(true); XYItemRenderer renderer = plot.getRenderer(); //DateFormat.getInstance() XYItemLabelGenerator generator = new StandardXYItemLabelGenerator("{1} \n {2}", new SimpleDateFormat("yyyy.MM.dd"), new DecimalFormat("0.00")); renderer.setSeriesItemLabelGenerator(0, generator);//setLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); plot.setBackgroundPaint(Color.WHITE); plot.setDomainCrosshairPaint(Color.GRAY); if (renderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer rend = (XYLineAndShapeRenderer) renderer; rend.setBaseShapesVisible(true); rend.setBaseShapesFilled(true); } plot.setRenderer(renderer); chart.setBackgroundPaint(Color.white); return chart; }