List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setBaseShapesVisible
public void setBaseShapesVisible(boolean flag)
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
protected JFreeChart createScatterChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createScatterPlot( evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRScatterPlot) getPlot()).getXAxisLabelExpression()), evaluateTextExpression(((JRScatterPlot) getPlot()).getYAxisLabelExpression()), (XYDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(), true, false);// w w w .ja v a2 s . c o m configureChart(jfreeChart, getPlot()); XYLineAndShapeRenderer plotRenderer = (XYLineAndShapeRenderer) ((XYPlot) jfreeChart.getPlot()) .getRenderer(); JRScatterPlot scatterPlot = (JRScatterPlot) getPlot(); boolean isShowLines = scatterPlot.getShowLines() == null ? true : scatterPlot.getShowLines(); boolean isShowShapes = scatterPlot.getShowShapes() == null ? true : scatterPlot.getShowShapes(); plotRenderer.setBaseLinesVisible(isShowLines); plotRenderer.setBaseShapesVisible(isShowShapes); // Handle the axis formating for the category axis configureAxis(jfreeChart.getXYPlot().getDomainAxis(), scatterPlot.getXAxisLabelFont(), scatterPlot.getXAxisLabelColor(), scatterPlot.getXAxisTickLabelFont(), scatterPlot.getXAxisTickLabelColor(), scatterPlot.getXAxisTickLabelMask(), scatterPlot.getXAxisVerticalTickLabels(), scatterPlot.getOwnXAxisLineColor(), false, (Comparable<?>) evaluateExpression(scatterPlot.getDomainAxisMinValueExpression()), (Comparable<?>) evaluateExpression(scatterPlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(jfreeChart.getXYPlot().getRangeAxis(), scatterPlot.getYAxisLabelFont(), scatterPlot.getYAxisLabelColor(), scatterPlot.getYAxisTickLabelFont(), scatterPlot.getYAxisTickLabelColor(), scatterPlot.getYAxisTickLabelMask(), scatterPlot.getYAxisVerticalTickLabels(), scatterPlot.getOwnYAxisLineColor(), true, (Comparable<?>) evaluateExpression(scatterPlot.getRangeAxisMinValueExpression()), (Comparable<?>) evaluateExpression(scatterPlot.getRangeAxisMaxValueExpression())); return jfreeChart; }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
protected JFreeChart createScatterChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createScatterPlot( evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRScatterPlot) getPlot()).getXAxisLabelExpression()), evaluateTextExpression(((JRScatterPlot) getPlot()).getYAxisLabelExpression()), (XYDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(), true, false);/*from w ww .jav a 2 s .c om*/ configureChart(jfreeChart, getPlot()); XYLineAndShapeRenderer plotRenderer = (XYLineAndShapeRenderer) ((XYPlot) jfreeChart.getPlot()) .getRenderer(); JRScatterPlot scatterPlot = (JRScatterPlot) getPlot(); boolean isShowLines = scatterPlot.getShowLines() == null ? true : scatterPlot.getShowLines(); boolean isShowShapes = scatterPlot.getShowShapes() == null ? true : scatterPlot.getShowShapes(); plotRenderer.setBaseLinesVisible(isShowLines); plotRenderer.setBaseShapesVisible(isShowShapes); // Handle the axis formating for the category axis configureAxis(jfreeChart.getXYPlot().getDomainAxis(), scatterPlot.getXAxisLabelFont(), scatterPlot.getXAxisLabelColor(), scatterPlot.getXAxisTickLabelFont(), scatterPlot.getXAxisTickLabelColor(), scatterPlot.getXAxisTickLabelMask(), scatterPlot.getXAxisVerticalTickLabels(), scatterPlot.getOwnXAxisLineColor(), getDomainAxisSettings(), (Comparable<?>) evaluateExpression(scatterPlot.getDomainAxisMinValueExpression()), (Comparable<?>) evaluateExpression(scatterPlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(jfreeChart.getXYPlot().getRangeAxis(), scatterPlot.getYAxisLabelFont(), scatterPlot.getYAxisLabelColor(), scatterPlot.getYAxisTickLabelFont(), scatterPlot.getYAxisTickLabelColor(), scatterPlot.getYAxisTickLabelMask(), scatterPlot.getYAxisVerticalTickLabels(), scatterPlot.getOwnYAxisLineColor(), getRangeAxisSettings(), (Comparable<?>) evaluateExpression(scatterPlot.getRangeAxisMinValueExpression()), (Comparable<?>) evaluateExpression(scatterPlot.getRangeAxisMaxValueExpression())); return jfreeChart; }
From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java
private JFreeChart createXYLineChart(String title, String xLabel, String yLabel, XYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // data orientation, // orientation true, // include legend true, // tooltips false // urls );/*from w ww . j a v a 2 s . co m*/ chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setNoDataMessage("No data available"); // customise the renderer... XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); // customise the range axis... if (lineCondition.indexOf("qq") != -1) { renderer.setBaseShapesFilled(true); renderer.setSeriesLinesVisible(1, true); renderer.setSeriesShapesVisible(1, false); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setUpperMargin(0); rangeAxis.setLowerMargin(0); // rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setUpperMargin(0); domainAxis.setLowerMargin(0); return chart; } NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (timeType.length() != 0) { setDateAxis(plot); } else { NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRange(false); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } // System.out.println("lineCondition "+lineCondition); if (lineCondition.indexOf("noshape") != -1) renderer.setBaseShapesVisible(false); else renderer.setBaseShapesVisible(true); if (lineCondition.indexOf("noline") != -1) renderer.setBaseLinesVisible(false); if (lineCondition.indexOf("nofill") != -1) { renderer.setBaseShapesFilled(false); renderer.setBaseFillPaint(Color.white); renderer.setDrawOutlines(true); } else { renderer.setBaseShapesFilled(true); renderer.setUseFillPaint(false); } return chart; }
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 w w w. j a v a2 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:gov.llnl.lustre.lwatch.PlotFrame2.java
/** * Define the JFreeChart chart.//from ww w . j a va2 s. co m * * @param dataset dataset to be plotted in the chart. */ public JFreeChart createChart(XYDataset dataset) { // Load data for settings from last "Refresh" time String[] selectedRows = lastRefreshPlotParams.getCategories(); String[] selectedVars = lastRefreshPlotParams.getVariables(); String[] selectedCurves = lastRefreshPlotParams.getCurves(); int savedGranularity = granularity; granularity = lastRefreshPlotParams.getGranularity(); boolean showLegend = true; //if (((isAnAggPlot) && (nColsSelected * nCurvesSelected > 8)) || //(nRowsSelected * nColsSelected * nCurvesSelected > 8)) //showLegend = false; if (((isAnAggPlot) && (selectedVars.length * selectedCurves.length > 8)) || (selectedRows.length * selectedVars.length * selectedCurves.length > 8)) showLegend = false; //if (fromRefresh && (nRowsSelected > 0 && nColsSelected > 0 && nCurvesSelected > 0) && //(!noVarSelected)) { if (fromRefresh && (selectedRows.length > 0 && selectedVars.length > 0 && selectedCurves.length > 0) && (!noVarSelected)) { //Debug.out("nRowsSelected = " + nRowsSelected + //" nColsSelected = " + nColsSelected + //" nCurvesSelected = " + nCurvesSelected); pD = new PlotDescriptor(); } chart = ChartFactory.createTimeSeriesChart(fsName + " - " + type + " data", // title "Date", // x-axis label yAxisLabel, // y-axis label dataset, // data showLegend, // create legend false, // generate tooltips false // generate URLs ); chart.setBackgroundPaint(Color.black); //white); // Border color chart.setBorderVisible(true); TextTitle tTitle = chart.getTitle(); tTitle.setPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.black); //lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); // Check need for logorihmic axis if (useLogRangeAxis) { LogarithmicAxis rangeAxis2 = new LogarithmicAxis(yAxisLabel); plot.setRangeAxis(0, rangeAxis2); } // Default axis annotation is in black. So if the chart background // Paint was set to black above, we need to set axis labels, // tick labels and tick marks to be a contrasting color. plot.getDomainAxis().setLabelPaint(Color.white); plot.getDomainAxis().setTickLabelPaint(Color.white); plot.getDomainAxis().setTickMarkPaint(Color.white); plot.getRangeAxis().setLabelPaint(Color.white); plot.getRangeAxis().setTickLabelPaint(Color.white); plot.getRangeAxis().setTickMarkPaint(Color.white); // Grab the colors from the legend. //int nCurves = nRowsSelected * nColsSelected * nCurvesSelected; int nCurves = selectedRows.length * selectedVars.length * selectedCurves.length; if (localDebug) { Debug.out("selectedRows.length, selectedVars.length, selectedCurves.length = " + selectedRows.length + ", " + selectedVars.length + ", " + selectedCurves.length); Debug.out("Dimension legendColors to size = " + nCurves); } legendColors = new Color[nCurves]; LegendItemCollection lic = plot.getLegendItems(); for (int i = 0; i < lic.getItemCount(); i++) { LegendItem li = lic.get(i); legendColors[i] = (Color) li.getLinePaint(); //if (localDebug) //Debug.out("Line Paint for legend " + i + " = " + //legendColors[i]); } XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(showIcons); // Controls icons at data pts. renderer.setBaseShapesFilled(false); } DateAxis axis = (DateAxis) plot.getDomainAxis(); if (granularity == Database.HOUR) axis.setDateFormatOverride(new SimpleDateFormat("MM/dd HH")); //("dd-MMM-yy")); else if (granularity == Database.DAY) axis.setDateFormatOverride(new SimpleDateFormat("MM/dd/yy")); //("dd-MMM-yy")); else if (granularity == Database.WEEK) axis.setDateFormatOverride(new SimpleDateFormat("MM/dd/yy")); //("dd-MMM-yy")); else if (granularity == Database.MONTH) axis.setDateFormatOverride(new SimpleDateFormat("MM/yy")); //("dd-MMM-yy")); else if (granularity == Database.YEAR) axis.setDateFormatOverride(new SimpleDateFormat("yyyy HH:mm")); //("dd-MMM-yy")); else // granualrity == Database.RAW or HEARTBEAT axis.setDateFormatOverride(new SimpleDateFormat("MM/dd HH:mm:ss")); //("dd-MMM-yy")); // Reset granularity; granularity = savedGranularity; return chart; }