List of usage examples for org.jfree.chart ChartFrame ChartFrame
public ChartFrame(String title, JFreeChart chart)
From source file:com.babynamesUI.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed String name = nameentered.getText(); String y = yearentered.getText(); String sex = null;/* w w w . ja v a 2 s . c o m*/ if (male2.isSelected()) sex = "male"; else if (female2.isSelected()) sex = "female"; int[] Lvalue = new int[100]; int[] Lyear = new int[100]; int j = 0; try { int year = Integer.parseInt(y); int i = year; while (i <= 2013) { String filename = sex + "_cy" + i + "_top.csv"; InputStream is = babynamesUI.class.getResourceAsStream("/resourse/" + filename); BufferedReader br = null; String line = ""; String cvsSplitBy = ","; br = new BufferedReader(new InputStreamReader(is)); line = br.readLine(); while ((line = br.readLine()) != null) { int val; // use comma as separator String[] names = line.split(cvsSplitBy); String s1 = names[1].trim(); String s2 = names[0].trim(); //System.out.println("name:-"+s1); if (s1.charAt(0) == '"') { val = Integer.parseInt(s1.substring(1, s1.length() - 1)); } else { val = Integer.parseInt(s1); } if (s2.charAt(0) == '"') { s2 = s2.substring(1, s2.length() - 1); } //System.out.println("name:-"+s2); if (s2.equalsIgnoreCase(name)) { Lvalue[j] = val; Lyear[j] = i; j++; } } i++; } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { JOptionPane.showMessageDialog(null, "invalid entry"); e.printStackTrace(); } //graph grp =new graph(this,Lvalue,Lyear,j); //grp.setVisible(true); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String val = ""; //textArea1.setText("Year | Number of Birth"); for (int p = 0; p < j; p++) { val = Integer.toString(Lyear[p]); dataset.addValue(Lvalue[p], val, val); // textArea1.setText( textArea1.getText()+" \n"+year[i] +" | "+ value[i]); } JFreeChart chart = ChartFactory.createAreaChart("Name Trend", "year", "Number of Birth", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("Chart for Name Trend", chart); frame.setVisible(true); frame.setSize(1200, 700); frame.setLocationRelativeTo(null); setVisible(false); dispose(); }
From source file:graph.plotter.LineGraph.java
/** * This is the main working button for this class... It creates Line Graph analyZing whole data set * // ww w . j a v a 2 s. c om * @param evt */ private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: try { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int i; i = 0; String genre = " "; if (button1 == 2) { if (button2 == 1) while (i < cnt) { double aa = Double.parseDouble(Table.getModel().getValueAt(i, 1).toString()); String str = Table.getModel().getValueAt(i, 0).toString(); dataset.setValue(new Double(aa), genre, str); i++; //genre+=" "; } else { try { BufferedReader br = new BufferedReader(new FileReader(jTextField4.getText())); String Line; while ((Line = br.readLine()) != null) { String[] value = Line.split(","); double val = Double.parseDouble(value[1]); dataset.setValue(new Double(val), genre, value[0]); // genre+=" "; ////System.out.println(value[0]); } } catch (FileNotFoundException ex) { Logger.getLogger(LineGraph.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(LineGraph.class.getName()).log(Level.SEVERE, null, ex); } } } else if (button1 == 1) { String input = jTextField1.getText(); input = input.replaceAll("sin", "@"); input = input.replaceAll("cos", "#"); input = input.replaceAll("tan", "Q"); input = input.replaceAll("log", "~"); input = input.replaceAll("e", "&"); input = input.replaceAll("cosec", "r"); input = input.replaceAll("cot", "w"); input = input.replaceAll("sec", "y"); //System.out.println(input); int len; len = input.length(); String so = "."; for (ind = 0; ind < 360; ind++) { String gini = input; String sa = Integer.toString(ind); gini = gini.replaceAll("X", sa); Polish polish = new Polish(gini); double Calculate = Polish.Calculate(); dataset.setValue(new Double(Calculate), ".", sa); so += "."; } } JFreeChart chart = ChartFactory.createLineChart("Line Graph", "X - Axis", "Y - Axis", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.YELLOW); p.setBackgroundPaint(Color.BLACK); ChartFrame frame = new ChartFrame("Line Chart", chart); jButto1 = new JButton("Save"); frame.setLayout(new BorderLayout()); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); gc.gridx = 1; gc.gridy = 0; panel.add(jButto1, gc); frame.add(panel, BorderLayout.SOUTH); jButto1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("Line_Chart.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (Exception ex) { } } }); frame.setVisible(true); frame.setSize(858, 513); } catch (Exception e) { } }
From source file:UserInterfaces.HAdministration.SurgeryJPanel.java
private void chartjButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chartjButton1ActionPerformed // TODO add your handling code here: int timeofadmin = 0; int timeofnurse = 0; int timeofpathology = 0; int timeofphar = 0; int timeofphysician = 0; int timeofsurgeon = 0; for (WorkRequest workRequest : enterprise.getWorkQueue().getWorkRequestList()) { if (workRequest.getLevel2().equals(ErrorUtil.SURGERY_OR_ANESTHESIA)) { for (ErrorPerson ep : workRequest.getEpd().getErrorpersonlist()) { if (ep instanceof AdminstrationErrorPerson) { // if (ep.getEpt().getValue().equals(ErrorPerson.ErrorPersonType.ADMINSTRATION.getValue())) { timeofadmin = timeofadmin + 1; }// w ww. j a va2 s. co m if (ep instanceof NurseErrorPerson) { timeofnurse = timeofnurse + 1; } if (ep instanceof PathologistriceErrorPerson) { timeofpathology = timeofpathology + 1; } if (ep instanceof PharmacistErrorPerson) { timeofphar = timeofphar + 1; } if (ep instanceof PhysicianErrorPerson) { timeofphysician = timeofphysician + 1; } if (ep instanceof SurgeonErrorPerson) { timeofsurgeon = timeofsurgeon + 1; } } } } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(timeofadmin, "Adminstration", "Adminstration"); dataset.addValue(timeofnurse, "Nurse", "Nurse"); dataset.addValue(timeofpathology, "Pathologist", "Pathologist"); dataset.addValue(timeofphar, "Pharmacist", "Pharmacist"); dataset.addValue(timeofphysician, "Physician", "Physician"); dataset.addValue(timeofsurgeon, "Surgeon", "Surgeon"); //dataset.setValue(80, "masd", "sss"); JFreeChart chart = ChartFactory.createBarChart("Personnel", "Position", "Times", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.WHITE); ChartFrame frame = new ChartFrame("Chart for ERROR", chart); frame.setVisible(true); frame.setSize(900, 700); }
From source file:userinterface.HealthAnalystRole.ViewReportJPanel.java
private void createChart() { DefaultCategoryDataset healthDataset = new DefaultCategoryDataset(); int selectedRow = tblHealthTable.getSelectedRow(); Device effects = (Device) tblHealthTable.getValueAt(selectedRow, 0); //Device device= device.getEffectsOnBodyList().getEffectsOnBodyList().; for (Device d : organization.getDeviceDirectory().getDeviceList()) { if (d.getEffectsOnBodyList().getEffectsOnBodyList().isEmpty() || d.getEffectsOnBodyList().getEffectsOnBodyList().size() == 1) { JOptionPane.showMessageDialog(this, "No body organs or only one body organ affected found. At least 2 organs effected records needed to show chart!", "Warning", JOptionPane.INFORMATION_MESSAGE); return; } else {/*w w w . j a v a 2s . com*/ Double organ = Double.parseDouble(txtOrgan.getText()); Double value = d.getMaxSAR(); } } //ArrayList<EffectsOnBody> effectsOnBodyList = device.getEffectsOnBodyList().getEffectsOnBodyList(); /*if (effectsOnBodyList.isEmpty() || effectsOnBodyList.size() == 1) { JOptionPane.showMessageDialog(this, "No body organs or only one body organ affected found. At least 2 organs effected records needed to show chart!", "Warning", JOptionPane.INFORMATION_MESSAGE); return; }*/ Double organ = Double.parseDouble(txtOrgan.getText()); for (Device device : organization.getDeviceDirectory().getDeviceList()) { for (EffectsOnBody b1 : device.getEffectsOnBodyList().getEffectsOnBodyList()) { Double value = device.getMaxSAR(); //healthDataset.addValue(vitalSign.getHeartRate(),"Most Likely Diseases", device.getMaxSAR()); //vitalSignDataset.addValue(vitalSign.getBloodPressure(),"BP", vitalSign.getTimestamp()); //vitalSignDataset.addValue(vitalSign.getWeight(),"WT", vitalSign.getTimestamp()); } } JFreeChart healthSignChart = ChartFactory.createBarChart3D("Effects On Health Chart", "Time Stamp", "Rate", healthDataset, PlotOrientation.VERTICAL, true, false, false); healthSignChart.setBackgroundPaint(Color.white); CategoryPlot vitalSignChartPlot = healthSignChart.getCategoryPlot(); vitalSignChartPlot.setBackgroundPaint(Color.lightGray); CategoryAxis vitalSignDomainAxis = vitalSignChartPlot.getDomainAxis(); vitalSignDomainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); NumberAxis vitalSignRangeAxis = (NumberAxis) vitalSignChartPlot.getRangeAxis(); vitalSignRangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ChartFrame chartFrame = new ChartFrame("Chart", healthSignChart); chartFrame.setVisible(true); chartFrame.setSize(500, 500); }
From source file:StoreAdmin.ManageStoreJPanel.java
private void btntopfiveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btntopfiveActionPerformed DefaultTableModel dtm = (DefaultTableModel) tblsearchedproduct.getModel(); dtm.getRowCount();/*from www . j a v a 2s . c o m*/ System.out.println(dtm.getRowCount()); if (dtm.getRowCount() < 4) { JOptionPane.showMessageDialog(null, "Inventory must have more than 4 products to plot the graph"); } else { JFreeChart plotGraphInventory = ChartFactory.createBarChart("Top 5 products in Store", "Products", "Profit", plotGrapghInventory(), PlotOrientation.VERTICAL, true, true, false); ChartPanel chartPanel = new ChartPanel(plotGraphInventory); chartPanel.setPreferredSize(new java.awt.Dimension(560, 367)); ChartFrame frame = new ChartFrame("Market Report", plotGraphInventory); frame.setVisible(true); frame.setSize(500, 270); } //GEN-LAST:event_btntopfiveActionPerformed }
From source file:tema11.GUI.java
private void PlotButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PlotButton2MouseClicked //TxRes.setText(" "); String p1, p2 = new String(); p1 = TxPol2.getText();// www . j a v a 2 s . c o m //p2 = TxPol2.getText(); int g1; int[] coef1; // g2 = Integer.parseInt(TxGrad2.getText()); try { g1 = Integer.parseInt(TxGrad2.getText()); coef1 = PolinomOperations.parseString(p1, g1); //coef2 = PolinomOperations.parseString(p1, g1); String chartTitle = "Object Movement Chart"; String xAxisLabel = "X"; String yAxisLabel = "Y"; XYDataset dataset = createDataset(coef1); JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset); BarRenderer renderer = null; CategoryPlot plot = null; renderer = new BarRenderer(); ChartFrame myFrame = new ChartFrame("Polinom chart", chart); myFrame.setLocation(200, 200); myFrame.setSize(400, 400); myFrame.setVisible(true); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Wrong polinom format", "Polinom Error", JOptionPane.ERROR_MESSAGE); } }
From source file:UserInterface.TMAnalystRole.TMAnaylstWorkAreaJPanel.java
private void btnRouteAnalysisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRouteAnalysisActionPerformed // TODO add your handling code here: Line selectedLine = (Line) cboActiveLines.getSelectedItem(); ArrayList<Route> routeList = new ArrayList<>(); for (Segment s : selectedLine.getSegments()) { routeList.add(s.getRoutes().get(0)); }/* w w w. j a v a 2 s. c o m*/ ArrayList<Segment> segmentList = selectedLine.getSegments(); for (int i = segmentList.size() - 1; i >= 0; i--) { routeList.add(segmentList.get(i).getRoutes().get(1)); } int days = (int) spnrRecord.getValue(); Date today = new Date(); Date olderThanToday = new Date(); olderThanToday.setTime(today.getTime() + (long) (-days) * 1000 * 60 * 60 * 24); long todayDate = (today.getTime()) / (1000 * 60 * 60 * 24); long olderDate = (olderThanToday.getTime()) / (1000 * 60 * 60 * 24); Map<Route, Integer> routesWithCapacityList = new LinkedHashMap<>(); for (Route r : routeList) { int routeCount = 0; for (TimeSlot.TimeSlotRange ts : TimeSlot.TimeSlotRange.values()) { Train selectedTrain = r.fetchRouteSchedule(ts).getTrainOffered(); int intermediateCount = 0; int trainsFound = 0; for (TrainOffered selectedTrainOffered : enterprise.getTrainsOfferedHistory().getTrainsOffered()) { if (selectedTrainOffered.getTrain().equals(selectedTrain)) { long selectedDate = (selectedTrainOffered.getDayOffered().getTime()) / (1000 * 60 * 60 * 24); if (selectedDate >= olderDate && selectedDate <= todayDate) { intermediateCount += selectedTrainOffered.fetchRunningTrainByTimeSlot(ts) .getRunningCapacity(); trainsFound++; } } } if (trainsFound != 0) { intermediateCount = intermediateCount / trainsFound; routeCount += intermediateCount; } } routeCount = Math.round(routeCount / 15); routesWithCapacityList.putIfAbsent(r, routeCount); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Map.Entry<Route, Integer> entry : routesWithCapacityList.entrySet()) { dataset.setValue(entry.getValue(), "Routes", entry.getKey().getRouteName()); } JFreeChart chart = ChartFactory.createBarChart( "Congestion Levels of Line : " + selectedLine.getLineName() + " for " + days + " days", "Routes", "Average Congestion Levels", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.BLUE); ChartFrame frame = new ChartFrame("Bar Chart for Congestion Analysis", chart); frame.setVisible(true); frame.setSize(this.getWidth(), this.getHeight() + 200); }
From source file:UserInterfaces.HAdministration.FallReportJPanel.java
private void chartjButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chartjButton1ActionPerformed // TODO add your handling code here: int timeofadmin = 0; int timeofnurse = 0; int timeofpathology = 0; int timeofphar = 0; int timeofphysician = 0; int timeofsurgeon = 0; for (WorkRequest workRequest : enterprise.getWorkQueue().getWorkRequestList()) { if (workRequest.getLevel2().equals(ErrorUtil.FALL)) { for (ErrorPerson ep : workRequest.getEpd().getErrorpersonlist()) { if (ep instanceof AdminstrationErrorPerson) { // if (ep.getEpt().getValue().equals(ErrorPerson.ErrorPersonType.ADMINSTRATION.getValue())) { timeofadmin = timeofadmin + 1; }//from ww w . ja va2 s .com if (ep instanceof NurseErrorPerson) { timeofnurse = timeofnurse + 1; } if (ep instanceof PathologistriceErrorPerson) { timeofpathology = timeofpathology + 1; } if (ep instanceof PharmacistErrorPerson) { timeofphar = timeofphar + 1; } if (ep instanceof PhysicianErrorPerson) { timeofphysician = timeofphysician + 1; } if (ep instanceof SurgeonErrorPerson) { timeofsurgeon = timeofsurgeon + 1; } } } } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(timeofadmin, "Adminstration", "Adminstration"); dataset.addValue(timeofnurse, "Nurse", "Nurse"); dataset.addValue(timeofpathology, "Pathologist", "Pathologist"); dataset.addValue(timeofphar, "Pharmacist", "Pharmacist"); dataset.addValue(timeofphysician, "Physician", "Physician"); dataset.addValue(timeofsurgeon, "Surgeon", "Surgeon"); //dataset.setValue(80, "masd", "sss"); JFreeChart chart = ChartFactory.createBarChart("Personnel", "Position", "Times", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.WHITE); ChartFrame frame = new ChartFrame("Chart for ERROR", chart); frame.setVisible(true); frame.setSize(900, 700); }
From source file:UserInterfaces.HAdministration.BloodReportJPanel.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: int timeofem = 0; int timeofpha = 0; int timeofward = 0; int timeofor = 0; int timeoflab = 0; int timeofoutpatient = 0; int i;// w w w . j ava 2s . c om int max = 0; for (WorkRequest workRequest : enterprise.getWorkQueue().getWorkRequestList()) { if (workRequest.getLevel2().equals(ErrorUtil.BLOOD_OR_BLOOD_PRODUCT)) { if (workRequest.getLocation().equals(Location.EMERGENCY)) { timeofem = timeofem + 1; } if (workRequest.getLocation().equals(Location.LABORATORY)) { timeoflab = timeoflab + 1; } if (workRequest.getLocation().equals(Location.OR)) { timeofor = timeofor + 1; } if (workRequest.getLocation().equals(Location.OUTPATIEN)) { timeofoutpatient = timeofoutpatient + 1; } if (workRequest.getLocation().equals(Location.PHARMACY)) { timeofpha = timeofpha + 1; } if (workRequest.getLocation().equals(Location.WARD)) { timeofward = timeofward + 1; } } } int[] numbs; numbs = new int[6]; numbs[0] = timeofem; numbs[1] = timeoflab; numbs[2] = timeofor; numbs[3] = timeofoutpatient; numbs[4] = timeofpha; numbs[5] = timeofward; DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue(Location.EMERGENCY, timeofem); dataset.setValue(Location.LABORATORY, timeoflab); dataset.setValue(Location.OR, timeofor); dataset.setValue(Location.OUTPATIEN, timeofoutpatient); dataset.setValue(Location.PHARMACY, timeofpha); dataset.setValue(Location.WARD, timeofward); JFreeChart chart = ChartFactory.createPieChart(" Chart", dataset, true, true, true); PiePlot p = (PiePlot) chart.getPlot(); ChartFrame chartFrame = new ChartFrame("Location of events", chart); chartFrame.setSize(450, 550); chartFrame.setVisible(true); }
From source file:tema11.GUI.java
private void PlotResultButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PlotResultButtonMouseClicked // TxRes.setText(" "); String p1, p2 = new String(); p1 = TxRes.getText();/*from w w w .j av a2s . c o m*/ //p2 = TxPol2.getText(); int g1, g2; int[] coef1; // g2 = Integer.parseInt(TxGrad2.getText()); try { g1 = Integer.parseInt(TxGrad1.getText()); g2 = Integer.parseInt(TxGrad2.getText()); coef1 = PolinomOperations.parseString(p1, g1 + g2); //coef2 = PolinomOperations.parseString(p1, g1); String chartTitle = "Object Movement Chart"; String xAxisLabel = "X"; String yAxisLabel = "Y"; XYDataset dataset = createDataset(coef1); JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset); BarRenderer renderer = null; CategoryPlot plot = null; renderer = new BarRenderer(); ChartFrame myFrame = new ChartFrame("Result Polinom chart", chart); myFrame.setLocation(200, 200); myFrame.setSize(400, 400); myFrame.setVisible(true); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Wrong polinom format! Va rog sa editati rezultatul si in locul coeficientului liber adaugati astfel coef_liberx^0 (exemplu in loc de 5 scrieti 5x^0)", "Polinom Error", JOptionPane.ERROR_MESSAGE); } }