List of usage examples for org.jfree.chart ChartFactory createLineChart
public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:UserInterface.WaterSupplyAdmin.UsagePatternJPanel.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed int selectedRow = customerTable.getSelectedRow(); if (selectedRow < 0) { JOptionPane.showMessageDialog(null, "Select a customer first"); return;/* ww w . j av a 2s . c o m*/ } Customer customer = (Customer) customerTable.getValueAt(selectedRow, 1); if (customer.getSourceSensor() == null) { JOptionPane.showMessageDialog(null, "Water Supply not available yet for this customer"); return; } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (SensorValue sensorValue : customer.getTargetSensor().getSensorValueList()) { dataset.addValue(sensorValue.getFlowrate(), "Date", sensorValue.getDate()); } if (customer.getTargetSensor().getSensorValueList().size() == 1) { JFreeChart chart = ChartFactory.createBarChart( "Customer's water flowrate variation over a period of time", "Time of Usage", "FlowRate(gallons/sec)", dataset, PlotOrientation.VERTICAL, true, true, true); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.cyan); ChartFrame frame = new ChartFrame("Bar Char for Weight", chart); frame.setVisible(true); frame.setSize(450, 350); } else { JFreeChart chart = ChartFactory.createLineChart( "Customer's water flowrate variation over a period of time", "Time of Usage", "FlowRate(gallons/sec)", dataset, PlotOrientation.VERTICAL, true, true, true); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.cyan); ChartFrame frame = new ChartFrame("Bar Char for Weight", chart); RefineryUtilities.centerFrameOnScreen(frame); frame.setVisible(true); frame.setSize(450, 350); } }
From source file:org.jfree.chart.demo.ThumbnailDemo1.java
private static JFreeChart createChart6(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createLineChart("Java Standard Class Library", "Release", "Class Count", categorydataset, PlotOrientation.VERTICAL, false, true, false); jfreechart.addSubtitle(new TextTitle("Number of Classes By Release")); TextTitle texttitle = new TextTitle( "Source: Java In A Nutshell (4th Edition) by David Flanagan (O'Reilly)"); texttitle.setFont(new Font("SansSerif", 0, 10)); texttitle.setPosition(RectangleEdge.BOTTOM); texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT); jfreechart.addSubtitle(texttitle);//from ww w . j av a 2s. c o m jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setUpperMargin(0.14999999999999999D); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer(); lineandshaperenderer.setBaseShapesVisible(true); lineandshaperenderer.setDrawOutlines(true); lineandshaperenderer.setUseFillPaint(true); lineandshaperenderer.setBaseFillPaint(Color.white); lineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); lineandshaperenderer.setBaseItemLabelsVisible(true); return jfreechart; }
From source file:com.cch.aj.entryrecorder.frame.MainJFrame.java
private void UpdateEntryForm() { List<Record> records = this.recordService.GetAllEntitiesByKeyAndRecord(RecordKey.ALL, this.currentEntry.getId()); //load images if (currentEntry.getMouldId().getImageBoreA() != null) { AppHelper.DisplayImage(currentEntry.getMouldId().getImageBoreA(), this.pnlBoreImage1, 75); } else {// ww w .ja v a 2s . c om AppHelper.DisplayImageFromResource("/b1.png", this.pnlBoreImage1, 75); } if (currentEntry.getMouldId().getImageBoreB() != null) { AppHelper.DisplayImage(currentEntry.getMouldId().getImageBoreB(), this.pnlBoreImage2, 75); } else { AppHelper.DisplayImageFromResource("/b2.png", this.pnlBoreImage2, 75); } if (currentEntry.getMouldId().getImageNeck() != null) { AppHelper.DisplayImage(currentEntry.getMouldId().getImageNeck(), this.pnlNeckImage, 75); } else { AppHelper.DisplayImageFromResource("/b3.png", this.pnlNeckImage, 75); } if (currentEntry.getMouldId().getImageTap() != null) { AppHelper.DisplayImage(currentEntry.getMouldId().getImageTap(), this.pnlTapImage, 75); } else { AppHelper.DisplayImageFromResource("/no_photo_small.png", this.pnlTapImage, 75); } if (currentEntry.getProductId().getDgnondg() != null && currentEntry.getProductId().getDgnondg() == 0) { if (currentEntry.getMouldId().getImageDg() != null) { AppHelper.DisplayImage(currentEntry.getMouldId().getImageDg(), this.pnlWallImage, 75); } else { AppHelper.DisplayImageFromResource("/no_photo_small.png", this.pnlWallImage, 75); } } else { if (currentEntry.getMouldId().getImageNonDg() != null) { AppHelper.DisplayImage(currentEntry.getMouldId().getImageNonDg(), this.pnlWallImage, 75); } else { AppHelper.DisplayImageFromResource("/no_photo_small.png", this.pnlWallImage, 75); } } //info UpdateProductInfo(this.currentEntry); //weight this.labWeightStaff.setVisible(false); this.txtWeightStaff.setVisible(false); datasetWeight = new DefaultCategoryDataset(); List<Record> recordsWeight = records.stream().filter(x -> x.getRecordKey().equals("PRODUCT_WEIGHT")) .collect(Collectors.toList()); DefaultTableModel modelWeight = (DefaultTableModel) this.tblWeight.getModel(); modelWeight.setRowCount(0); for (Record record : recordsWeight) { String time = new SimpleDateFormat("HH:mm").format(record.getCreatedTime()); String staff = record.getStaff() == null ? "" : record.getStaff(); String pass = record.getIsPass() == null ? "" : record.getIsPass(); datasetWeight.addValue(record.getNumberValue(), "Weight", time); modelWeight.addRow(new Object[] { time, record.getNumberValue(), pass, staff }); } ((AbstractTableModel) this.tblWeight.getModel()).fireTableDataChanged(); JFreeChart chartWeight = ChartFactory.createLineChart("Product Weight (grams)", "", "", datasetWeight, PlotOrientation.VERTICAL, false, true, false); ChartPanel cpWeight = new ChartPanel(chartWeight); this.pnlChartWeight.removeAll(); this.pnlChartWeight.add(cpWeight, gridBagConstraints); //wall List<Record> recordsWall = records.stream().filter(x -> x.getRecordKey().startsWith("WALL_")) .collect(Collectors.toList()); DefaultTableModel modelWall = (DefaultTableModel) this.tblWall.getModel(); modelWall.setRowCount(0); for (Record record : recordsWall) { String time = new SimpleDateFormat("HH:mm").format(record.getCreatedTime()); String staff = record.getStaff() == null ? "" : record.getStaff(); String pass = record.getIsPass() == null ? "" : record.getIsPass(); String name = record.getRecordKey(); modelWall.addRow(new Object[] { time, name, record.getNumberValue(), pass, staff }); } ((AbstractTableModel) this.tblWall.getModel()).fireTableDataChanged(); //Tap datasetTap = new DefaultCategoryDataset(); List<Record> recordsTap = records.stream().filter(x -> x.getRecordKey().equals("TAP_POSITION")) .collect(Collectors.toList()); DefaultTableModel modelTap = (DefaultTableModel) this.tblTap.getModel(); modelTap.setRowCount(0); for (Record record : recordsTap) { String time = new SimpleDateFormat("HH:mm").format(record.getCreatedTime()); String staff = record.getStaff() == null ? "" : record.getStaff(); String pass = record.getIsPass() == null ? "" : record.getIsPass(); datasetTap.addValue(record.getNumberValue(), "Tap", time); modelTap.addRow(new Object[] { time, record.getStringValue(), pass, staff }); } ((AbstractTableModel) this.tblTap.getModel()).fireTableDataChanged(); JFreeChart chartTap = ChartFactory.createLineChart("Tap Positio", "", "", datasetTap, PlotOrientation.VERTICAL, false, true, false); ChartPanel cpTap = new ChartPanel(chartTap); this.pnlChartTap.removeAll(); this.pnlChartTap.add(cpTap, gridBagConstraints); //Bore List<Record> recordsBore = records.stream().filter(x -> x.getRecordKey().startsWith("THREAD_")) .collect(Collectors.toList()); DefaultTableModel modelBore = (DefaultTableModel) this.tblBore.getModel(); modelBore.setRowCount(0); for (Record record : recordsBore) { String time = new SimpleDateFormat("HH:mm").format(record.getCreatedTime()); String staff = record.getStaff() == null ? "" : record.getStaff(); String pass = record.getIsPass() == null ? "" : record.getIsPass(); String name = record.getRecordKey(); modelBore.addRow(new Object[] { time, name, record.getNumberValue(), pass, staff }); } ((AbstractTableModel) this.tblBore.getModel()).fireTableDataChanged(); if (this.currentEntry.getProductId() != null && this.currentEntry.getProductId().getClosureType().equals("TWIN")) { this.txtBore11.setVisible(true); this.txtBore21.setVisible(true); this.txtNeck1.setVisible(true); this.txtBoreStaff1.setVisible(true); this.btnBore1.setVisible(true); } else { this.txtBore11.setVisible(false); this.txtBore21.setVisible(false); this.txtNeck1.setVisible(false); this.txtBoreStaff1.setVisible(false); this.btnBore1.setVisible(false); } //Check List<Record> recordsCheck = records.stream().filter(x -> x.getRecordKey().startsWith("CHECK_")) .collect(Collectors.toList()); DefaultTableModel modelCheck = (DefaultTableModel) this.tblCheck.getModel(); modelCheck.setRowCount(0); for (Record record : recordsCheck) { String time = new SimpleDateFormat("HH:mm").format(record.getCreatedTime()); String staff = record.getStaff() == null ? "" : record.getStaff(); String pass = record.getIsPass() == null ? "" : record.getIsPass(); String name = record.getRecordKey(); modelCheck.addRow(new Object[] { time, name, record.getStringValue(), pass, staff }); } ((AbstractTableModel) this.tblCheck.getModel()).fireTableDataChanged(); //Drop List<Record> recordsDrop = records.stream().filter(x -> x.getRecordKey().startsWith("DROP_")) .collect(Collectors.toList()); DefaultTableModel modelDrop = (DefaultTableModel) this.tblDrop.getModel(); modelDrop.setRowCount(0); for (Record record : recordsDrop) { String time = new SimpleDateFormat("HH:mm").format(record.getCreatedTime()); String staff = record.getStaff() == null ? "" : record.getStaff(); String name = record.getRecordKey(); String pass = record.getIsPass() == null ? "" : record.getIsPass(); modelDrop.addRow(new Object[] { time, name, record.getStringValue(), pass, staff }); } ((AbstractTableModel) this.tblDrop.getModel()).fireTableDataChanged(); //Bung List<Record> recordsBung = records.stream().filter(x -> x.getRecordKey().equals("BUNG")) .collect(Collectors.toList()); DefaultTableModel modelBung = (DefaultTableModel) this.tblBung.getModel(); modelBung.setRowCount(0); for (Record record : recordsBung) { String time = new SimpleDateFormat("HH:mm").format(record.getCreatedTime()); String staff = record.getStaff() == null ? "" : record.getStaff(); String pass = record.getIsPass() == null ? "" : record.getIsPass(); modelBung.addRow(new Object[] { time, record.getStringValue(), pass, staff }); } //Cycle List<Record> recordsCycle = records.stream().filter(x -> x.getRecordKey().equals("CYCLE")) .collect(Collectors.toList()); DefaultTableModel modelCycle = (DefaultTableModel) this.tblCycle.getModel(); modelCycle.setRowCount(0); for (Record record : recordsCycle) { String time = new SimpleDateFormat("HH:mm").format(record.getCreatedTime()); String staff = record.getStaff() == null ? "" : record.getStaff(); modelCycle.addRow(new Object[] { time, record.getStringValue(), staff }); } //Seconds float totalSeconds = 0f; List<Record> recordsSeconds = records.stream().filter(x -> x.getRecordKey().equals("SECONDS")) .collect(Collectors.toList()); DefaultTableModel modelSeconds = (DefaultTableModel) this.tblSeconds.getModel(); modelSeconds.setRowCount(0); for (Record record : recordsSeconds) { String time = new SimpleDateFormat("HH:mm").format(record.getCreatedTime()); modelSeconds.addRow(new Object[] { time, record.getNumberValue() }); totalSeconds += record.getNumberValue(); } this.labSecondsTotal.setText(Float.toString(totalSeconds)); //Rejects float totalRejects = 0f; List<Record> recordsRejects = records.stream().filter(x -> x.getRecordKey().equals("REJECTS")) .collect(Collectors.toList()); DefaultTableModel modelRejects = (DefaultTableModel) this.tblRejects.getModel(); modelRejects.setRowCount(0); for (Record record : recordsRejects) { String time = new SimpleDateFormat("HH:mm").format(record.getCreatedTime()); modelRejects.addRow(new Object[] { time, record.getNumberValue() }); totalRejects += record.getNumberValue(); } this.labRejectsTotal.setText(Float.toString(totalRejects)); //material this.FillPolymerComboBox(this.cbProductPolymer, 0); this.FillAdditiveComboBox(this.cbProductAdditive1, 0); this.FillAdditiveComboBox(this.cbProductAdditive2, 0); this.FillAdditiveComboBox(this.cbProductAdditive3, 0); DefaultTableModel modelMaterial = (DefaultTableModel) this.tblMaterial.getModel(); modelMaterial.setRowCount(0); if (currentEntry.getMaterial() != null && !currentEntry.getMaterial().equals("")) { FillMaterialTable(currentEntry.getMaterial()); } txtPolymerBatchA.setText(""); txtPolymerBatchB.setText(""); txtAdditiveABatchA.setText(""); txtAdditiveBBatchA.setText(""); txtAdditiveCBatchA.setText(""); txtAdditiveABatchB.setText(""); txtAdditiveBBatchB.setText(""); txtAdditiveCBatchB.setText(""); //staff this.FillStaffComboBox(this.cbSupervisor1, currentEntry.getSupervisor1() != null ? currentEntry.getSupervisor1().getId() : 0, "SUPERVISOR"); this.FillStaffComboBox(this.cbSupervisor2, currentEntry.getSupervisor2() != null ? currentEntry.getSupervisor2().getId() : 0, "SUPERVISOR"); this.FillStaffComboBox(this.cbSupervisor3, currentEntry.getSupervisor3() != null ? currentEntry.getSupervisor3().getId() : 0, "SUPERVISOR"); this.FillStaffComboBox(this.cbTechnician1, currentEntry.getTechnician1() != null ? currentEntry.getTechnician1().getId() : 0, "TECHNICIAN"); this.FillStaffComboBox(this.cbTechnician2, currentEntry.getTechnician2() != null ? currentEntry.getTechnician2().getId() : 0, "TECHNICIAN"); this.FillStaffComboBox(this.cbTechnician3, currentEntry.getTechnician3() != null ? currentEntry.getTechnician3().getId() : 0, "TECHNICIAN"); this.FillStaffComboBox(this.cbWorker1, currentEntry.getWorker1() != null ? currentEntry.getWorker1().getId() : 0, "PROCESS WORKER"); this.FillStaffComboBox(this.cbWorker2, currentEntry.getWorker2() != null ? currentEntry.getWorker2().getId() : 0, "PROCESS WORKER"); this.FillStaffComboBox(this.cbWorker3, currentEntry.getWorker3() != null ? currentEntry.getWorker3().getId() : 0, "PROCESS WORKER"); //Leak List<Record> recordsLeak = records.stream() .filter(x -> x.getRecordKey().startsWith("DROP_") || x.getRecordKey().equals("ANY_LEAK")) .collect(Collectors.toList()); DefaultTableModel modelLeak = (DefaultTableModel) this.tblLeak.getModel(); modelLeak.setRowCount(0); for (Record record : recordsLeak) { String time = new SimpleDateFormat("HH:mm").format(record.getCreatedTime()); String name = record.getRecordKey(); modelLeak.addRow(new Object[] { time, name, record.getStringValue() }); } ((AbstractTableModel) this.tblLeak.getModel()).fireTableDataChanged(); this.txtLeakNotes.setVisible(false); //quantity this.txtPalletQuantity.setText( currentEntry.getPalletQuantity() == null ? "0" : currentEntry.getPalletQuantity().toString()); this.txtOtherQuantity.setText( currentEntry.getOtherQuantity() == null ? "0" : currentEntry.getOtherQuantity().toString()); this.txtPalletProducedA.setText( currentEntry.getPalletProducedA() == null ? "0" : currentEntry.getPalletProducedA().toString()); this.txtPalletProducedB.setText( currentEntry.getPalletProducedB() == null ? "0" : currentEntry.getPalletProducedB().toString()); int a1 = 0; int a2 = 0; int b1 = 0; int b2 = 0; a1 = Integer.parseInt(this.txtPalletProducedA.getText()); b1 = Integer.parseInt(this.txtPalletProducedB.getText()); a2 = Integer.parseInt(this.txtPalletQuantity.getText()); b2 = Integer.parseInt(this.txtOtherQuantity.getText()); this.labQuantityTotal.setText(Integer.toString((a1 * a2) + (b1 * b2))); }
From source file:javaapplication1.AlgoritmoGenetico.java
public void graficarErrorIteracion(double[] errorPatron) { //Fuentes de datos DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset(); for (int i = 0; i < errorPatron.length; i++) { if (errorPatron[i] != 0) { line_chart_dataset.setValue(errorPatron[i], "Error", String.valueOf(i + 1)); line_chart_dataset.setValue(Double.valueOf(errorDeConvergencia.getText()), "Error de convergencia", String.valueOf(i + 1)); }/*from w ww .ja va2 s . co m*/ } // Creando el Grafico JFreeChart chart = ChartFactory.createLineChart("Errores por Iteracion", "Iteracion", "Error Iteracion", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false); // Mostrar Grafico ChartPanel chartPanel = new ChartPanel(chart); panel2.removeAll(); panel2.add(chartPanel, BorderLayout.CENTER); panel2.validate(); }
From source file:org.pau.assetmanager.viewmodel.MonthlyReportViewModel.java
/** * This method generates an image of a chart of the evolution of the total * amount of money a general book selection for a year in a monthly bases * /*from w ww . j a v a2s .c om*/ * @return the relative random URL generated */ @DependsOn({ "selectedBook", "clientType", "monthlyReportYear" }) public String getBalanceOwnChartURL() { if (bookSelection.getSelectedBook() == null) { return ""; } if (!getIsAllBooks()) { return ""; } List<Annotation> anotations = getAnnotationsInAscendingDateOrder(Optional.<Integer>absent()); Collection<Annotation> annotationsFromGeneralBooks = Collections2.filter(anotations, new Predicate<Annotation>() { @Override public boolean apply(Annotation annotation) { return annotation.getBook() instanceof GeneralBook; } }); Multimap<Integer, Annotation> yearToGeneralBooksMultimap = getYearToAnnotationMultimapFromAnnotations( annotationsFromGeneralBooks); CategoryDataset categoryModel = ChartDataModel.getBalance(monthlyReportYear, yearToGeneralBooksMultimap, bookSelection, false, Optional.<String>absent()); JFreeChart jfchart = ChartFactory.createLineChart("Saldo de gastos e ingresos generales", "Fecha", "Euros", categoryModel, PlotOrientation.VERTICAL, true, true, false); PrepareChart.prepareBalanceChart(jfchart); return ResourceImageGenerator.getFunction().apply(jfchart); }
From source file:az.kanan.batterystat.frame.MainFrame.java
private void drawStat() { jPanel2.removeAll();// w w w . j a va 2 s. c om jPanel2.setLayout(new GridLayout(0, 1)); JFreeChart lineChart = ChartFactory.createLineChart("Statistic of power", "date", "percent of life", createDataset(), PlotOrientation.VERTICAL, true, true, false); lineChart.setBackgroundPaint(Color.white); ChartPanel chartPanel = new ChartPanel(lineChart); chartPanel.setBackground(Color.white); chartPanel.setPreferredSize(new java.awt.Dimension(640, 400)); jPanel2.add(chartPanel); jPanel2.revalidate(); jPanel2.repaint(); }
From source file:org.angnysa.yaba.swing.BudgetFrame.java
private void buildSimulationPanel() { simulationPanel = new JPanel(); SpringLayout springLayout = new SpringLayout(); simulationPanel.setLayout(springLayout); // chart data simulationDataset = new SimulationDataset(service); simulationDataset.setInitial(0D);/*from www . ja va2s . c o m*/ simulationDataset.setStart(new LocalDate()); simulationDataset.setEnd(new LocalDate().plus(Years.ONE)); simulationDataset.setPeriod(Period.months(1)); simulationDataset.updateDataset(); transactionModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { simulationDataset.updateDataset(); } }); reconciliationModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { simulationDataset.updateDataset(); } }); // initial amount label JLabel amountLbl = new JLabel(Messages.getString("simulation.field.initial-amount")); //$NON-NLS-1$ springLayout.putConstraint(SpringLayout.WEST, amountLbl, 10, SpringLayout.WEST, simulationPanel); simulationPanel.add(amountLbl); // initial amount field amountFld = new JFormattedTextField( new DefaultFormatterFactory(new NumberFormatter(NumberFormat.getNumberInstance()), new NumberFormatter(NumberFormat.getCurrencyInstance()))); amountFld.setColumns(8); amountFld.setValue(simulationDataset.getInitial()); amountFld.addPropertyChangeListener("value", new PropertyChangeListener() { //$NON-NLS-1$ @Override public void propertyChange(PropertyChangeEvent e) { simulationDataset.setInitial(((Number) amountFld.getValue()).doubleValue()); simulationDataset.updateDataset(); } }); springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, amountLbl, 0, SpringLayout.VERTICAL_CENTER, amountFld); springLayout.putConstraint(SpringLayout.WEST, amountFld, 0, SpringLayout.EAST, amountLbl); springLayout.putConstraint(SpringLayout.NORTH, amountFld, 10, SpringLayout.NORTH, simulationPanel); simulationPanel.add(amountFld); // start date label JLabel fromLbl = new JLabel(Messages.getString("simulation.field.start-date")); //$NON-NLS-1$ springLayout.putConstraint(SpringLayout.WEST, fromLbl, 10, SpringLayout.EAST, amountFld); simulationPanel.add(fromLbl); // start date field fromFld = new JFormattedTextField(new JodaLocalDateFormat()); fromFld.setColumns(8); fromFld.setValue(simulationDataset.getStart()); fromFld.addPropertyChangeListener("value", new PropertyChangeListener() { //$NON-NLS-1$ @Override public void propertyChange(PropertyChangeEvent e) { simulationDataset.setStart((LocalDate) fromFld.getValue()); simulationDataset.updateDataset(); } }); springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, fromLbl, 0, SpringLayout.VERTICAL_CENTER, fromFld); springLayout.putConstraint(SpringLayout.WEST, fromFld, 0, SpringLayout.EAST, fromLbl); springLayout.putConstraint(SpringLayout.NORTH, fromFld, 10, SpringLayout.NORTH, simulationPanel); simulationPanel.add(fromFld); // end date label JLabel toLbl = new JLabel(Messages.getString("simulation.field.end-date")); //$NON-NLS-1$ springLayout.putConstraint(SpringLayout.WEST, toLbl, 10, SpringLayout.EAST, fromFld); simulationPanel.add(toLbl); // end date field toFld = new JFormattedTextField(new JodaLocalDateFormat()); toFld.setColumns(8); toFld.setValue(simulationDataset.getEnd()); toFld.addPropertyChangeListener("value", new PropertyChangeListener() { //$NON-NLS-1$ @Override public void propertyChange(PropertyChangeEvent e) { simulationDataset.setEnd((LocalDate) toFld.getValue()); simulationDataset.updateDataset(); } }); springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, toLbl, 0, SpringLayout.VERTICAL_CENTER, toFld); springLayout.putConstraint(SpringLayout.WEST, toFld, 0, SpringLayout.EAST, toLbl); springLayout.putConstraint(SpringLayout.NORTH, toFld, 10, SpringLayout.NORTH, simulationPanel); simulationPanel.add(toFld); // period label JLabel periodLbl = new JLabel(Messages.getString("simulation.field.period")); //$NON-NLS-1$ springLayout.putConstraint(SpringLayout.WEST, periodLbl, 10, SpringLayout.EAST, toFld); simulationPanel.add(periodLbl); // period field periodFld = new JFormattedTextField(new JodaPeriodFormat()); periodFld.setColumns(5); periodFld.setValue(simulationDataset.getPeriod()); periodFld.addPropertyChangeListener("value", new PropertyChangeListener() { //$NON-NLS-1$ @Override public void propertyChange(PropertyChangeEvent e) { simulationDataset.setPeriod((ReadablePeriod) periodFld.getValue()); simulationDataset.updateDataset(); } }); springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, periodLbl, 0, SpringLayout.VERTICAL_CENTER, periodFld); springLayout.putConstraint(SpringLayout.WEST, periodFld, 0, SpringLayout.EAST, periodLbl); springLayout.putConstraint(SpringLayout.NORTH, periodFld, 10, SpringLayout.NORTH, simulationPanel); simulationPanel.add(periodFld); // chart panel JFreeChart chart = ChartFactory.createLineChart("", Messages.getString("simulation.chart.date-axis-label"), //$NON-NLS-1$//$NON-NLS-2$ Messages.getString("simulation.chart.amount-axis-label"), simulationDataset, //$NON-NLS-1$ PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesFilled(true); renderer.setBaseShapesVisible(true); renderer.setBaseToolTipGenerator(new SimulationTooltipGenerator(service)); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setDismissDelay(3600000); chartPanel.setInitialDelay(0); springLayout.putConstraint(SpringLayout.NORTH, chartPanel, 15, SpringLayout.SOUTH, periodFld); springLayout.putConstraint(SpringLayout.WEST, chartPanel, 10, SpringLayout.WEST, simulationPanel); springLayout.putConstraint(SpringLayout.SOUTH, chartPanel, -10, SpringLayout.SOUTH, simulationPanel); springLayout.putConstraint(SpringLayout.EAST, chartPanel, -10, SpringLayout.EAST, simulationPanel); simulationPanel.add(chartPanel); }
From source file:com.sun.japex.ChartGenerator.java
private JFreeChart generateDriverLineChart() { try {/*from ww w.jav a2 s.co m*/ String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Generate charts for (DriverImpl di : _testSuite.getDriverInfoList()) { dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN), "Arithmetic Mean", di.getName()); dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN), "Geometric Mean", di.getName()); dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN), "Harmonic Mean", di.getName()); } JFreeChart chart = ChartFactory.createLineChart("Result Summary (" + resultUnit + ")", "", resultUnit, dataset, PlotOrientation.VERTICAL, true, true, false); configureLineChart(chart); return chart; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.pentaho.di.ui.spoon.trans.StepPerformanceSnapShotDialog.java
private void updateCanvas() { Rectangle bounds = canvas.getBounds(); if (bounds.width <= 0 || bounds.height <= 0) { return;//ww w . j ava 2s. c o m } // The list of snapshots : convert to JFreeChart dataset // DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String[] selectedSteps = stepsList.getSelection(); if (selectedSteps == null || selectedSteps.length == 0) { selectedSteps = new String[] { steps[0], }; // first step stepsList.select(0); } int[] dataIndices = dataList.getSelectionIndices(); if (dataIndices == null || dataIndices.length == 0) { dataIndices = new int[] { DATA_CHOICE_WRITTEN, }; dataList.select(0); } boolean multiStep = stepsList.getSelectionCount() > 1; boolean multiData = dataList.getSelectionCount() > 1; boolean calcMoving = !multiStep && !multiData; // A single metric shown for a single step List<Double> movingList = new ArrayList<Double>(); int movingSize = 10; double movingTotal = 0; int totalTimeInSeconds = 0; for (int t = 0; t < selectedSteps.length; t++) { String stepNameCopy = selectedSteps[t]; List<StepPerformanceSnapShot> snapShotList = stepPerformanceSnapShots.get(stepNameCopy); if (snapShotList != null && snapShotList.size() > 1) { totalTimeInSeconds = (int) Math .round(((double) (snapShotList.get(snapShotList.size() - 1).getDate().getTime() - snapShotList.get(0).getDate().getTime())) / 1000); for (int i = 0; i < snapShotList.size(); i++) { StepPerformanceSnapShot snapShot = snapShotList.get(i); if (snapShot.getTimeDifference() != 0) { double factor = (double) 1000 / (double) snapShot.getTimeDifference(); for (int d = 0; d < dataIndices.length; d++) { String dataType; if (multiStep) { dataType = stepNameCopy; } else { dataType = dataChoices[dataIndices[d]]; } String xLabel = Integer.toString(Math.round(i * timeDifference / 1000)); Double metric = null; switch (dataIndices[d]) { case DATA_CHOICE_INPUT: metric = snapShot.getLinesInput() * factor; break; case DATA_CHOICE_OUTPUT: metric = snapShot.getLinesOutput() * factor; break; case DATA_CHOICE_READ: metric = snapShot.getLinesRead() * factor; break; case DATA_CHOICE_WRITTEN: metric = snapShot.getLinesWritten() * factor; break; case DATA_CHOICE_UPDATED: metric = snapShot.getLinesUpdated() * factor; break; case DATA_CHOICE_REJECTED: metric = snapShot.getLinesRejected() * factor; break; case DATA_CHOICE_INPUT_BUFFER_SIZE: metric = (double) snapShot.getInputBufferSize(); break; case DATA_CHOICE_OUTPUT_BUFFER_SIZE: metric = (double) snapShot.getOutputBufferSize(); break; default: break; } if (metric != null) { dataset.addValue(metric, dataType, xLabel); if (calcMoving) { movingTotal += metric; movingList.add(metric); if (movingList.size() > movingSize) { movingTotal -= movingList.get(0); movingList.remove(0); } double movingAverage = movingTotal / movingList.size(); dataset.addValue(movingAverage, dataType + "(Avg)", xLabel); // System.out.println("moving average = "+movingAverage+", movingTotal="+movingTotal+", m"); } } } } } } } String chartTitle = title; if (multiStep) { chartTitle += " (" + dataChoices[dataIndices[0]] + ")"; } else { chartTitle += " (" + selectedSteps[0] + ")"; } final JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.TimeInSeconds.Label", Integer.toString(totalTimeInSeconds), Long.toString(timeDifference)), // domain axis label BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.RowsPerSecond.Label"), // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false); // urls chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setForegroundAlpha(0.5f); plot.setRangeGridlinesVisible(true); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelsVisible(false); // Customize the renderer... // LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.white); renderer.setSeriesStroke(0, new BasicStroke(1.5f)); renderer.setSeriesOutlineStroke(0, new BasicStroke(1.5f)); renderer.setSeriesStroke(1, new BasicStroke(2.5f)); renderer.setSeriesOutlineStroke(1, new BasicStroke(2.5f)); renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); BufferedImage bufferedImage = chart.createBufferedImage(bounds.width, bounds.height); ImageData imageData = ImageUtil.convertToSWT(bufferedImage); // dispose previous image... // if (image != null) { image.dispose(); } image = new Image(display, imageData); // Draw the image on the canvas... // canvas.redraw(); }
From source file:hr.restart.util.chart.ChartXYZ.java
/** * Creates a LINE CHART./*from w w w . ja v a2 s .co m*/ * * @param dataset The org.jfree.data.CategoryDataset * @param title The title * @return org.jfree.chart.JFreeChart */ final private JFreeChart createLineChart(final CategoryDataset dataset, String title) { // create the chart... final JFreeChart chart = ChartFactory.createLineChart(title, // chart title "", // domain axis label "", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); //print the subtitles java.util.List subs = getSubtitles(); if (subs != null) for (int i = 0; i < subs.size(); i++) { chart.addSubtitle(new TextTitle(subs.get(i).toString())); } // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... final StandardLegend legend = (StandardLegend) chart.getLegend(); legend.setDisplaySeriesShapes(true); legend.setShapeScaleX(1.5); legend.setShapeScaleY(1.5); legend.setDisplaySeriesLines(true); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); //plot.setBackgroundPaint(Color.lightGray); //plot.setRangeGridlinePaint(Color.white); // customise the range axis... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); // customise the renderer... final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setDrawShapes(true); adjustLineRenderer(renderer); // renderer.setSeriesStroke( // 0, new BasicStroke( // 2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, // 1.0f, new float[] {10.0f, 6.0f}, 0.0f // ) // ); // renderer.setSeriesStroke( // 1, new BasicStroke( // 2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, // 1.0f, new float[] {6.0f, 6.0f}, 0.0f // ) // ); // renderer.setSeriesStroke( // 2, new BasicStroke( // 2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, // 1.0f, new float[] {2.0f, 6.0f}, 0.0f // ) // ); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }