List of usage examples for org.jfree.chart.axis NumberAxis setRange
public void setRange(Range range)
From source file:org.jax.pubarray.server.restful.GraphingResource.java
/** * Create a graph for the given configuration * @param graphConfiguration/* w ww . ja v a 2 s. c o m*/ * the key * @return * the graph */ @SuppressWarnings("unchecked") private JFreeChart createProbeIntensityGraph(ProbeIntensityGraphConfiguration graphConfiguration) { try { Connection connection = this.getConnection(); String[] probeIds = graphConfiguration.getProbeIds(); double[][] probeDataRows = new double[probeIds.length][]; for (int i = 0; i < probeIds.length; i++) { probeDataRows[i] = this.persistenceManager.getDataRowForProbeID(connection, probeIds[i]); } TableColumnMetadata orderBy = graphConfiguration.getOrderProbesBy(); final List<Comparable> orderByItems; if (orderBy != null) { LOG.info("We are ordering by: " + orderBy); orderByItems = this.persistenceManager.getDesignDataColumn(connection, orderBy); } else { orderByItems = null; } TableMetadata metadata = this.persistenceManager.getDataTableMetadata(connection); final CategoryDataset categoryDataset; if (graphConfiguration.getGroupReplicates()) { switch (graphConfiguration.getGroupedGraphType()) { case BOX_PLOT: { categoryDataset = new DefaultBoxAndWhiskerCategoryDataset(); } break; case SCATTER_PLOT: { categoryDataset = new DefaultMultiValueCategoryDataset(); } break; default: throw new IllegalArgumentException( "don't know how to deal with plot type: " + graphConfiguration.getGroupedGraphType()); } } else { categoryDataset = new DefaultCategoryDataset(); } // iterate through all of the selected probesets List<QualifiedColumnMetadata> termsOfInterest = Arrays.asList(graphConfiguration.getTermsOfInterest()); for (int rowIndex = 0; rowIndex < probeDataRows.length; rowIndex++) { double[] currRow = probeDataRows[rowIndex]; assert currRow.length == metadata.getColumnMetadata().length - 1; // should we log2 transform the data? if (graphConfiguration.getLog2TransformData()) { for (int i = 0; i < currRow.length; i++) { currRow[i] = Math.log(currRow[i]) / LOG2_FACTOR; } } // iterate through the columns in the data table (each column // represents a different array) List<ComparableContainer<Double, Comparable>> rowElemList = new ArrayList<ComparableContainer<Double, Comparable>>(); for (int colIndex = 0; colIndex < currRow.length; colIndex++) { // we use +1 indexing here because we want to skip over // the probesetId metadata and get right to the // array intensity metadata TableColumnMetadata colMeta = metadata.getColumnMetadata()[colIndex + 1]; // check to see if we need to skip this data if (!graphConfiguration.getIncludeDataFromAllArrays()) { // if it's one of the "terms of interest" we will keep // it. we're using a brute force search here boolean keepThisOne = false; for (QualifiedColumnMetadata termOfInterest : termsOfInterest) { if (termOfInterest.getTableName().equals(metadata.getTableName()) && termOfInterest.getName().equals(colMeta.getName())) { keepThisOne = true; break; } } if (!keepThisOne) { continue; } } final String columnName = colMeta.getName(); final Comparable columnKey; if (orderByItems == null) { columnKey = columnName; } else { // the ordering will be done on the selected // "order by" design criteria columnKey = new ComparableContainer<String, Comparable>(columnName, orderByItems.get(colIndex), !graphConfiguration.getGroupReplicates()); // TODO remove me!!!! System.out.println("For array " + columnName + " the order by " + "value is: " + orderByItems.get(colIndex)); // end of remove me } rowElemList .add(new ComparableContainer<Double, Comparable>(currRow[colIndex], columnKey, false)); } Collections.sort(rowElemList); if (graphConfiguration.getGroupReplicates()) { switch (graphConfiguration.getGroupedGraphType()) { case BOX_PLOT: { DefaultBoxAndWhiskerCategoryDataset dataset = (DefaultBoxAndWhiskerCategoryDataset) categoryDataset; for (int i = 0; i < rowElemList.size(); i++) { List<Double> groupList = new ArrayList<Double>(); groupList.add(rowElemList.get(i).getElement()); Comparable colKey = rowElemList.get(i).getComparable(); i++; for (; i < rowElemList.size() && rowElemList.get(i).getComparable().equals(colKey); i++) { groupList.add(rowElemList.get(i).getElement()); } i--; dataset.add(groupList, probeIds[rowIndex], colKey); } } break; case SCATTER_PLOT: { DefaultMultiValueCategoryDataset dataset = (DefaultMultiValueCategoryDataset) categoryDataset; for (int i = 0; i < rowElemList.size(); i++) { List<Double> groupList = new ArrayList<Double>(); groupList.add(rowElemList.get(i).getElement()); Comparable colKey = rowElemList.get(i).getComparable(); i++; for (; i < rowElemList.size() && rowElemList.get(i).getComparable().equals(colKey); i++) { groupList.add(rowElemList.get(i).getElement()); } i--; dataset.add(groupList, probeIds[rowIndex], colKey); } } break; } } else { DefaultCategoryDataset dataset = (DefaultCategoryDataset) categoryDataset; for (ComparableContainer<Double, Comparable> rowElem : rowElemList) { dataset.addValue(rowElem.getElement(), probeIds[rowIndex], rowElem.getComparable()); } } } CategoryAxis xAxis = new CategoryAxis(); if (graphConfiguration.getGroupReplicates() && orderBy != null) { xAxis.setLabel(orderBy.getName()); } else { if (orderBy != null) { xAxis.setLabel("Arrays (Ordered By " + orderBy.getName() + ")"); } else { xAxis.setLabel("Arrays"); } } xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); final NumberAxis yAxis; if (graphConfiguration.getLog2TransformData()) { yAxis = new NumberAxis("log2(Intensity)"); } else { yAxis = new NumberAxis("Intensity"); } yAxis.setAutoRange(true); yAxis.setAutoRangeIncludesZero(false); // TODO: this is a HACK to deal with auto-range bug in JFreeChart // which occurs when doing the grouped scatter plot if (graphConfiguration.getGroupReplicates() && graphConfiguration.getGroupedGraphType() == GroupedGraphType.SCATTER_PLOT) { double minVal = Double.POSITIVE_INFINITY; double maxVal = Double.NEGATIVE_INFINITY; for (double[] dataRow : probeDataRows) { for (double datum : dataRow) { if (datum > maxVal) { maxVal = datum; } if (datum < minVal) { minVal = datum; } } if (minVal != Double.POSITIVE_INFINITY && maxVal != Double.NEGATIVE_INFINITY && minVal != maxVal) { yAxis.setAutoRange(false); double margin = (maxVal - minVal) * 0.02; Range yRange = new Range(minVal - margin, maxVal + margin); yAxis.setRange(yRange); } } } // END HACK final CategoryItemRenderer renderer; if (graphConfiguration.getGroupReplicates()) { switch (graphConfiguration.getGroupedGraphType()) { case BOX_PLOT: { BoxAndWhiskerRenderer boxRenderer = new BoxAndWhiskerRenderer(); boxRenderer.setMaximumBarWidth(0.03); renderer = boxRenderer; } break; case SCATTER_PLOT: { renderer = new ScatterRenderer(); } break; default: throw new IllegalArgumentException( "don't know how to deal with plot type: " + graphConfiguration.getGroupedGraphType()); } } else { renderer = new LineAndShapeRenderer(); } Plot plot = new CategoryPlot(categoryDataset, xAxis, yAxis, renderer); return new JFreeChart("Intensity Values", plot); } catch (SQLException ex) { LOG.log(Level.SEVERE, "failed to generate image", ex); return null; } }
From source file:de.bund.bfr.knime.nls.chart.ChartCreator.java
public JFreeChart createChart() throws ParseException { if (varX == null || varY == null) { return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), showLegend); }/*from w w w. j av a2 s .c om*/ List<String> idsToPaint; if (selectAll) { idsToPaint = new ArrayList<>(plotables.keySet()); } else { idsToPaint = selectedIds; } NumberAxis xAxis = new NumberAxis(transformX.getName(varX)); NumberAxis yAxis = new NumberAxis(transformY.getName(varY)); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); double usedMinX = Double.POSITIVE_INFINITY; double usedMaxX = Double.NEGATIVE_INFINITY; int index = 0; List<Color> defaultColors = ChartUtils.createColorList(idsToPaint.size()); List<NamedShape> defaultShapes = ChartUtils.createShapeList(idsToPaint.size()); for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable == null) { continue; } if (plotable.isDataType()) { double[][] points = plotable.getDataPoints(varX, varY, transformX, transformY); if (points != null) { for (int i = 0; i < points[0].length; i++) { usedMinX = Math.min(usedMinX, points[0][i]); usedMaxX = Math.max(usedMaxX, points[0][i]); } } } if (plotable.isParamType()) { double minArg = transformX.to(MathUtils.nullToNan(plotable.getMinValues().get(varX))); double maxArg = transformX.to(MathUtils.nullToNan(plotable.getMaxValues().get(varX))); if (Double.isFinite(minArg)) { usedMinX = Math.min(usedMinX, minArg); } if (Double.isFinite(maxArg)) { usedMaxX = Math.max(usedMaxX, maxArg); } } } if (!Double.isFinite(usedMinX)) { usedMinX = 0.0; } if (!Double.isFinite(usedMaxX)) { usedMaxX = 100.0; } xAxis.setAutoRangeIncludesZero(false); yAxis.setAutoRangeIncludesZero(false); if (usedMinX == usedMaxX) { usedMinX -= 1.0; usedMaxX += 1.0; } if (useManualRange && minX < maxX && minY < maxY) { usedMinX = minX; usedMaxX = maxX; xAxis.setRange(new Range(minX, maxX)); yAxis.setRange(new Range(minY, maxY)); } for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable == null) { continue; } plotable.setFunctionSteps(resolution); plotable.setInterpolator(interpolator); switch (plotable.getType()) { case DATA: plotData(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index)); break; case FUNCTION: plotFunction(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX, usedMaxX); break; case DATA_FUNCTION: plotDataFunction(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX, usedMaxX); break; case DIFF: plotDiff(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX, usedMaxX); break; case DATA_DIFF: plotDataDiff(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX, usedMaxX); break; default: throw new RuntimeException("Unknown type of plotable: " + plotable.getType()); } index++; } if (minToZero && !useManualRange) { Range xRange = xAxis.getRange(); Range yRange = yAxis.getRange(); if (xRange.getUpperBound() <= 0.0 || yRange.getUpperBound() <= 0.0) { return null; } xAxis.setRange(new Range(0.0, xRange.getUpperBound())); yAxis.setRange(new Range(0.0, yRange.getUpperBound())); } return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend); }
From source file:de.bund.bfr.knime.pmmlite.views.chart.ChartCreator.java
public JFreeChart getChart(List<String> idsToPaint) throws ParseException, UnitException { if (varX == null || varY == null || varX.getName() == null || varY.getName() == null) { return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), showLegend); }//w w w . j a v a2s.com NumberAxis xAxis = new NumberAxis(varX.getDisplayString()); NumberAxis yAxis = new NumberAxis(varY.getDisplayString()); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); double usedMinX = Double.POSITIVE_INFINITY; double usedMaxX = Double.NEGATIVE_INFINITY; int index = 0; List<Color> defaultColors = ChartUtils.createColorList(idsToPaint.size()); List<NamedShape> defaultShapes = ChartUtils.createShapeList(idsToPaint.size()); for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable == null) { continue; } if (plotable.getType() == Plotable.Type.BOTH || plotable.getType() == Plotable.Type.BOTH_MANY || plotable.getType() == Plotable.Type.FUNCTION || plotable.getType() == Plotable.Type.FUNCTION_SAMPLE) { double minArg = varX.to(MathUtils.nullToNan(plotable.getMinValues().get(varX.getName())), plotable.getUnits().get(varX.getName())); double maxArg = varX.to(MathUtils.nullToNan(plotable.getMaxValues().get(varX.getName())), plotable.getUnits().get(varX.getName())); if (Double.isFinite(minArg)) { usedMinX = Math.min(usedMinX, minArg); } if (Double.isFinite(maxArg)) { usedMaxX = Math.max(usedMaxX, maxArg); } } if (plotable.getType() == Plotable.Type.BOTH || plotable.getType() == Plotable.Type.BOTH_MANY) { for (Map<String, Integer> choice : plotable.getAllChoices(varX.getName())) { double[][] points = plotable.getPoints(varX, varY, choice); if (points != null) { for (int i = 0; i < points[0].length; i++) { usedMinX = Math.min(usedMinX, points[0][i]); usedMaxX = Math.max(usedMaxX, points[0][i]); } } } } if (plotable.getType() == Plotable.Type.DATASET || plotable.getType() == Plotable.Type.DATASET_MANY) { double[][] points = plotable.getPoints(varX, varY); if (points != null) { for (int i = 0; i < points[0].length; i++) { usedMinX = Math.min(usedMinX, points[0][i]); usedMaxX = Math.max(usedMaxX, points[0][i]); } } } if (plotable.getType() == Plotable.Type.FUNCTION_SAMPLE) { for (Double x : plotable.getSamples()) { if (x != null && Double.isFinite(x)) { usedMinX = Math.min(usedMinX, x); usedMaxX = Math.max(usedMaxX, x); } } } } if (Double.isInfinite(usedMinX)) { usedMinX = 0.0; } if (Double.isInfinite(usedMaxX)) { usedMaxX = 100.0; } if (varX.getName().equals(PmmUtils.TIME) || varX.getName().equals(PmmUtils.CONCENTRATION)) { usedMinX = Math.min(usedMinX, 0.0); xAxis.setAutoRangeIncludesZero(true); } else { xAxis.setAutoRangeIncludesZero(false); } if (varY.getName().equals(PmmUtils.TIME) || varY.getName().equals(PmmUtils.CONCENTRATION)) { yAxis.setAutoRangeIncludesZero(true); } else { yAxis.setAutoRangeIncludesZero(false); } if (usedMinX == usedMaxX) { usedMinX -= 1.0; usedMaxX += 1.0; } if (useManualRange && minX < maxX && minY < maxY) { usedMinX = minX; usedMaxX = maxX; xAxis.setRange(new Range(minX, maxX)); yAxis.setRange(new Range(minY, maxY)); } for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable == null) { continue; } plotable.setFunctionSteps(resolution); switch (plotable.getType()) { case DATASET: plotDataSet(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index)); break; case DATASET_MANY: plotDataSetStrict(plot, plotable, id); break; case FUNCTION: plotFunction(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX, usedMaxX); break; case FUNCTION_SAMPLE: plotFunctionSample(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX, usedMaxX); break; case BOTH: plotBoth(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX, usedMaxX); break; case BOTH_MANY: plotBothStrict(plot, plotable, id, usedMinX, usedMaxX); break; default: throw new RuntimeException("Unknown type of plotable: " + plotable.getType()); } index++; } return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend); }
From source file:interfaces.InterfazPrincipal.java
private void botonGenerarReporteClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGenerarReporteClienteActionPerformed // TODO add your handling code here: try {//from www . ja va 2 s . c o m if (clienteReporteClienteFechaFinal.getSelectedDate().getTime() .compareTo(clienteReporteClienteFechaInicial.getSelectedDate().getTime()) < 0) { JOptionPane.showMessageDialog(this, "La fecha final debe ser posterior al dia de inicio"); } else { final ArrayList<Integer> listaIDFlujos = new ArrayList<>(); final JDialog dialogoEditar = new JDialog(); dialogoEditar.setTitle("Reporte cliente"); dialogoEditar.setSize(350, 610); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); //c.fill = GridBagConstraints.HORIZONTAL; JLabel ediitarTextoPrincipalDialogo = new JLabel("Informe cliente"); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.insets = new Insets(10, 45, 10, 10); Font textoGrande = new Font("Arial", 1, 18); ediitarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(ediitarTextoPrincipalDialogo, c); final JTable tablaDialogo = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Factura"); modeloTabla.addColumn("Tipo Flujo"); modeloTabla.addColumn("Fecha"); modeloTabla.addColumn("Valor"); //Llenar tabla ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura(); ArrayList<String[]> flujosCliente = controladorFlujoFactura.getTodosFlujo_Factura( " where factura_id in (select factura_id from Factura where cliente_id = " + String.valueOf(jTextFieldIdentificacionClienteReporte.getText()) + ") order by factura_id"); // {"flujo_id","factura_id","tipo_flujo","fecha","valor"}; ArrayList<Calendar> fechasFlujos = new ArrayList<>(); for (int i = 0; i < flujosCliente.size(); i++) { String fila[] = new String[4]; String[] objeto = flujosCliente.get(i); fila[0] = objeto[1]; fila[1] = objeto[2]; fila[2] = objeto[3]; fila[3] = objeto[4]; //Filtrar, mirar las fechas String[] partirEspacios = objeto[3].split("\\s"); //El primer string es la fecha sin hora //Ahora esparamos por - String[] tomarAgeMesDia = partirEspacios[0].split("-"); //Realizar filtro int ageConsulta = Integer.parseInt(tomarAgeMesDia[0]); int mesConsulta = Integer.parseInt(tomarAgeMesDia[1]); int diaConsulta = Integer.parseInt(tomarAgeMesDia[2]); //Obtenemos dias, mes y ao de la consulta //Inicial int anioInicial = clienteReporteClienteFechaFinal.getSelectedDate().get(Calendar.YEAR); int mesInicial = clienteReporteClienteFechaFinal.getSelectedDate().get(Calendar.MONTH) + 1; int diaInicial = clienteReporteClienteFechaFinal.getSelectedDate().get(Calendar.DAY_OF_MONTH); //Final int anioFinal = clienteReporteClienteFechaInicial.getSelectedDate().get(Calendar.YEAR); int mesFinal = clienteReporteClienteFechaInicial.getSelectedDate().get(Calendar.MONTH) + 1; int diaFinal = clienteReporteClienteFechaInicial.getSelectedDate().get(Calendar.DAY_OF_MONTH); //Construir fechas Calendar fechaDeLaBD = new GregorianCalendar(ageConsulta, mesConsulta, diaConsulta); //Set year, month, day) Calendar fechaInicialRango = new GregorianCalendar(anioInicial, mesInicial, diaInicial); Calendar fechaFinalRango = new GregorianCalendar(anioFinal, mesFinal, diaFinal); if (fechaDeLaBD.compareTo(fechaInicialRango) <= 0 && fechaDeLaBD.compareTo(fechaFinalRango) >= 0) { fechasFlujos.add(fechaDeLaBD); modeloTabla.addRow(fila); } } if (modeloTabla.getRowCount() > 0) { tablaDialogo.setModel(modeloTabla); tablaDialogo.getColumn("Factura").setMinWidth(80); tablaDialogo.getColumn("Tipo Flujo").setMinWidth(80); tablaDialogo.getColumn("Fecha").setMinWidth(90); tablaDialogo.getColumn("Valor").setMinWidth(80); tablaDialogo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(tablaDialogo); scroll.setPreferredSize(new Dimension(330, 150)); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.insets = new Insets(0, 0, 0, 0); panelDialogo.add(scroll, c); TimeSeries localTimeSeries = new TimeSeries("Compras del cliente en el periodo"); Map listaAbonos = new HashMap(); for (int i = 0; i < modeloTabla.getRowCount(); i++) { listaIDFlujos.add(Integer.parseInt(flujosCliente.get(i)[0])); if (modeloTabla.getValueAt(i, 1).equals("abono")) { Calendar fechaFlujo = fechasFlujos.get(i); double valor = Double.parseDouble(String.valueOf(modeloTabla.getValueAt(i, 3))); int anoDato = fechaFlujo.get(Calendar.YEAR); int mesDato = fechaFlujo.get(Calendar.MONTH) + 1; int diaDato = fechaFlujo.get(Calendar.DAY_OF_MONTH); Day FechaDato = new Day(diaDato, mesDato, anoDato); if (listaAbonos.get(FechaDato) != null) { double valorAbono = (double) listaAbonos.get(FechaDato); listaAbonos.remove(FechaDato); listaAbonos.put(FechaDato, valorAbono + valor); } else { listaAbonos.put(FechaDato, valor); } } } Double maximo = 0.0; Iterator iterator = listaAbonos.keySet().iterator(); while (iterator.hasNext()) { Day key = (Day) iterator.next(); Double value = (double) listaAbonos.get(key); maximo = Math.max(maximo, value); localTimeSeries.add(key, value); } //localTimeSeries.add(); TimeSeriesCollection datos = new TimeSeriesCollection(localTimeSeries); JFreeChart chart = ChartFactory.createTimeSeriesChart("Compras del cliente en el periodo", // Title "Tiempo", // x-axis Label "Total ($)", // y-axis Label datos, // Dataset true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); /*Altering the graph */ XYPlot plot = (XYPlot) chart.getPlot(); plot.setAxisOffset(new RectangleInsets(5.0, 10.0, 10.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); numberAxis.setRange(new Range(0, maximo * 1.2)); Font font = new Font("Dialog", Font.PLAIN, 9); numberAxis.setTickLabelFont(font); numberAxis.setLabelFont(font); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy")); axis.setAutoTickUnitSelection(false); axis.setVerticalTickLabels(true); axis.setTickLabelFont(font); axis.setLabelFont(font); LegendTitle leyendaChart = chart.getLegend(); leyendaChart.setItemFont(font); Font fontTitulo = new Font("Dialog", Font.BOLD, 12); TextTitle tituloChart = chart.getTitle(); tituloChart.setFont(fontTitulo); ChartPanel CP = new ChartPanel(chart); Dimension D = new Dimension(330, 300); CP.setPreferredSize(D); CP.setVisible(true); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.insets = new Insets(10, 0, 0, 0); panelDialogo.add(CP, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 1; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(10, 30, 0, 0); JButton botonCerrar = new JButton("Cerrar"); botonCerrar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); panelDialogo.add(botonCerrar, c); JButton botonGenerarPDF = new JButton("Guardar archivo"); botonGenerarPDF.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ReporteFlujosCliente reporteFlujosCliente = new ReporteFlujosCliente(); reporteFlujosCliente.guardarDocumentoDialogo(dialogoEditar, listaIDFlujos, Integer.parseInt(jTextFieldIdentificacionClienteReporte.getText()), clienteReporteClienteFechaInicial.getSelectedDate(), clienteReporteClienteFechaFinal.getSelectedDate()); } }); c.insets = new Insets(10, 100, 0, 0); panelDialogo.add(botonGenerarPDF, c); JButton botonImprimir = new JButton("Imprimir"); botonImprimir.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ReporteFlujosCliente reporteFlujosCliente = new ReporteFlujosCliente(); reporteFlujosCliente.imprimirFlujo(listaIDFlujos, Integer.parseInt(jTextFieldIdentificacionClienteReporte.getText()), clienteReporteClienteFechaInicial.getSelectedDate(), clienteReporteClienteFechaFinal.getSelectedDate()); } }); c.insets = new Insets(10, 230, 0, 0); panelDialogo.add(botonImprimir, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); } else { JOptionPane.showMessageDialog(this, "El cliente no registra movimientos en el rango de fechas seleccionado"); } } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Debe seleccionar un da inicial y final de fechas"); } }
From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java
public JFreeChart getChart(List<String> idsToPaint) { if (paramX == null || paramY == null) { return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), showLegend); }// w w w. j a va 2s . c om NumberAxis xAxis = new NumberAxis(AttributeUtilities.getNameWithUnit(paramX, unitX, transformX)); NumberAxis yAxis = new NumberAxis(AttributeUtilities.getNameWithUnit(paramY, unitY, transformY)); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); double usedMinX = Double.POSITIVE_INFINITY; double usedMaxX = Double.NEGATIVE_INFINITY; int index = 0; ColorAndShapeCreator colorAndShapeCreator = new ColorAndShapeCreator(idsToPaint.size()); for (String id : idsToPaint) { Plotable plotable = plotables.get(id); try { if (plotable != null) { if (plotable.getType() == Plotable.BOTH || plotable.getType() == Plotable.BOTH_STRICT) { Double minArg = Plotable.transform( plotable.convertToUnit(paramX, plotable.getMinArguments().get(paramX), unitX), transformX); Double maxArg = Plotable.transform( plotable.convertToUnit(paramX, plotable.getMaxArguments().get(paramX), unitX), transformX); if (isValid(minArg)) { usedMinX = Math.min(usedMinX, minArg); } if (isValid(maxArg)) { usedMaxX = Math.max(usedMaxX, maxArg); } for (Map<String, Integer> choice : plotable.getAllChoices()) { double[][] points = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY, choice); if (points != null) { for (int i = 0; i < points[0].length; i++) { if (isValid(points[0][i])) { usedMinX = Math.min(usedMinX, points[0][i]); usedMaxX = Math.max(usedMaxX, points[0][i]); } } } } } else if (plotable.getType() == Plotable.DATASET || plotable.getType() == Plotable.DATASET_STRICT) { double[][] points = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY); if (points != null) { for (int i = 0; i < points[0].length; i++) { if (isValid(points[0][i])) { usedMinX = Math.min(usedMinX, points[0][i]); usedMaxX = Math.max(usedMaxX, points[0][i]); } } } } else if (plotable.getType() == Plotable.FUNCTION) { Double minArg = Plotable.transform( plotable.convertToUnit(paramX, plotable.getMinArguments().get(paramX), unitX), transformX); Double maxArg = Plotable.transform( plotable.convertToUnit(paramX, plotable.getMaxArguments().get(paramX), unitX), transformX); if (isValid(minArg)) { usedMinX = Math.min(usedMinX, minArg); } if (isValid(maxArg)) { usedMaxX = Math.max(usedMaxX, maxArg); } } else if (plotable.getType() == Plotable.FUNCTION_SAMPLE) { Double minArg = Plotable.transform( plotable.convertToUnit(paramX, plotable.getMinArguments().get(paramX), unitX), transformX); Double maxArg = Plotable.transform( plotable.convertToUnit(paramX, plotable.getMaxArguments().get(paramX), unitX), transformX); if (isValid(minArg)) { usedMinX = Math.min(usedMinX, minArg); } if (isValid(maxArg)) { usedMaxX = Math.max(usedMaxX, maxArg); } for (Double x : plotable.getSamples()) { Double xx = Plotable.transform(plotable.convertToUnit(paramX, x, unitX), transformX); if (isValid(xx)) { usedMinX = Math.min(usedMinX, xx); usedMaxX = Math.max(usedMaxX, xx); } } } } } catch (ConvertException e) { } } if (Double.isInfinite(usedMinX)) { usedMinX = 0.0; } if (Double.isInfinite(usedMaxX)) { usedMaxX = 100.0; } if (paramX.equals(AttributeUtilities.TIME) || paramX.equals(AttributeUtilities.CONCENTRATION)) { usedMinX = Math.min(usedMinX, 0.0); xAxis.setAutoRangeIncludesZero(true); } else { xAxis.setAutoRangeIncludesZero(false); } if (paramY.equals(AttributeUtilities.TIME) || paramY.equals(AttributeUtilities.CONCENTRATION)) { yAxis.setAutoRangeIncludesZero(true); } else { yAxis.setAutoRangeIncludesZero(false); } if (usedMinX == usedMaxX) { usedMinX -= 1.0; usedMaxX += 1.0; } if (useManualRange && minX < maxX && minY < maxY) { usedMinX = minX; usedMaxX = maxX; xAxis.setRange(new Range(minX, maxX)); yAxis.setRange(new Range(minY, maxY)); } Set<ConvertException> convertExceptions = new LinkedHashSet<>(); for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable != null && plotable.getType() == Plotable.DATASET) { try { plotDataSet(plot, plotable, id, colorAndShapeCreator.getColorList().get(index), colorAndShapeCreator.getShapeList().get(index)); index++; } catch (ConvertException e) { convertExceptions.add(e); } } } for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable != null && plotable.getType() == Plotable.DATASET_STRICT) { try { plotDataSetStrict(plot, plotable, id); index++; } catch (ConvertException e) { convertExceptions.add(e); } } } for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable != null && plotable.getType() == Plotable.FUNCTION) { try { plotFunction(plot, plotable, id, colorAndShapeCreator.getColorList().get(index), colorAndShapeCreator.getShapeList().get(index), usedMinX, usedMaxX); index++; } catch (ConvertException e) { convertExceptions.add(e); } } } warnings = new ArrayList<>(); for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable != null && plotable.getType() == Plotable.FUNCTION_SAMPLE) { try { plotFunctionSample(plot, plotable, id, colorAndShapeCreator.getColorList().get(index), colorAndShapeCreator.getShapeList().get(index), usedMinX, usedMaxX, warnings); index++; } catch (ConvertException e) { convertExceptions.add(e); } } } for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable != null && plotable.getType() == Plotable.BOTH) { try { plotBoth(plot, plotable, id, colorAndShapeCreator.getColorList().get(index), colorAndShapeCreator.getShapeList().get(index), usedMinX, usedMaxX); index++; } catch (ConvertException e) { convertExceptions.add(e); } } } for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable != null && plotable.getType() == Plotable.BOTH_STRICT) { try { plotBothStrict(plot, plotable, id, usedMinX, usedMaxX); index++; } catch (ConvertException e) { convertExceptions.add(e); } } } if (!convertExceptions.isEmpty()) { String warning = "Some datasets/functions cannot be converted to the desired unit\n"; warning += "Uncovertable units: "; for (ConvertException e : convertExceptions) { warning += e.getFromUnit() + "->" + e.getToUnit() + ", "; } warning = warning.substring(0, warning.length() - 2); JOptionPane.showMessageDialog(this, warning, "Warning", JOptionPane.WARNING_MESSAGE); } return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend); }