List of usage examples for org.jfree.chart ChartFrame getChartPanel
public ChartPanel getChartPanel()
From source file:com.imaging100x.tracker.TrackerUtils.java
/** * Create a frame with a plot of the data given in XYSeries *///from ww w . ja va 2s. co m public static void plotData(String title, final XYSeries data, String xTitle, String yTitle, int xLocation, int yLocation) { // JFreeChart code XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(data); JFreeChart chart = ChartFactory.createScatterPlot(title, // Title xTitle, // x-axis Label yTitle, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation false, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); final XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesFillPaint(0, Color.white); renderer.setSeriesLinesVisible(0, true); Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(0, circle, false); renderer.setUseFillPaint(true); ChartFrame graphFrame = new ChartFrame(title, chart); graphFrame.getChartPanel().setMouseWheelEnabled(true); graphFrame.setPreferredSize(new Dimension(SIZE, SIZE)); graphFrame.setResizable(true); graphFrame.pack(); graphFrame.setLocation(xLocation, yLocation); graphFrame.setVisible(true); dataset.addChangeListener(new DatasetChangeListener() { public void datasetChanged(DatasetChangeEvent dce) { double xRange = data.getMaxX() - data.getMinX(); double yRange = data.getMaxY() - data.getMinY(); double xAvg = (data.getMaxX() + data.getMinX()) / 2; double yAvg = (data.getMaxY() + data.getMinY()) / 2; double range = xRange; if (yRange > range) { range = yRange; } double offset = 0.55 * range; plot.getDomainAxis().setRange(xAvg - offset, xAvg + offset); plot.getRangeAxis().setRange(yAvg - offset, yAvg + offset); } }); }
From source file:lectorarchivos.VerCSV.java
public static void mostrarGrafica(JTable jTableInfoCSV) { //Fuente de datos DefaultCategoryDataset dataset = new DefaultCategoryDataset(); //Recorremos la columna del consumo de la tabla for (int i = jTableInfoCSV.getRowCount() - 1; i >= 0; i--) { if (Double.parseDouble(jTableInfoCSV.getValueAt(i, 4).toString()) > 0) dataset.setValue(Double.parseDouble(jTableInfoCSV.getValueAt(i, 4).toString()), "Consumo", jTableInfoCSV.getValueAt(i, 0).toString()); }/* w w w . j a v a 2 s . c om*/ //Creando el grfico JFreeChart chart = ChartFactory.createBarChart3D("Consumo", "Fecha", "Consumo", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.cyan); chart.getTitle().setPaint(Color.black); chart.setBackgroundPaint(Color.white); chart.removeLegend(); //Cambiar color de barras CategoryPlot plot = (CategoryPlot) chart.getPlot(); BarRenderer barRenderer = (BarRenderer) plot.getRenderer(); barRenderer.setSeriesPaint(0, Color.decode("#5882FA")); // Mostrar Grafico ChartFrame frame = new ChartFrame("CONSUMO", chart); frame.pack(); frame.getChartPanel().setMouseZoomable(false); frame.setVisible(true); panel.add(frame); }
From source file:org.micromanager.CRISP.CRISPFrame.java
/** * Create a frame with a plot of the data given in XYSeries *//*from w ww . j a v a 2 s . c om*/ public static void plotData(String title, XYSeries data, String xTitle, String yTitle, int xLocation, int yLocation) { // JFreeChart code XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(data); JFreeChart chart = ChartFactory.createScatterPlot(title, // Title xTitle, // x-axis Label yTitle, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation false, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesFillPaint(0, Color.white); renderer.setSeriesLinesVisible(0, true); Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(0, circle, false); renderer.setUseFillPaint(true); ChartFrame graphFrame = new ChartFrame(title, chart); graphFrame.getChartPanel().setMouseWheelEnabled(true); graphFrame.pack(); graphFrame.setLocation(xLocation, yLocation); graphFrame.setVisible(true); }
From source file:lectorarchivos.MostrarGraficaCSV.java
/** * Creates new form MostrarGraficaCSV/*from ww w . ja v a2 s.co m*/ */ public MostrarGraficaCSV(JTable jTableInfoCSV) { initComponents(); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); panel = new JPanel(); getContentPane().add(panel); //Fuente de datos DefaultCategoryDataset dataset = new DefaultCategoryDataset(); //Recorremos la columna del consumo de la tabla for (int i = jTableInfoCSV.getRowCount() - 1; i >= 0; i--) { if (Double.parseDouble(jTableInfoCSV.getValueAt(i, 4).toString()) > 0) dataset.setValue(Double.parseDouble(jTableInfoCSV.getValueAt(i, 4).toString()), "Consumo", jTableInfoCSV.getValueAt(i, 0).toString()); } //Creando el grfico JFreeChart chart = ChartFactory.createBarChart3D("Consumo", "Fecha", "Consumo", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.cyan); chart.getTitle().setPaint(Color.black); chart.setBackgroundPaint(Color.white); chart.removeLegend(); //Cambiar color de barras CategoryPlot plot = (CategoryPlot) chart.getPlot(); BarRenderer barRenderer = (BarRenderer) plot.getRenderer(); barRenderer.setSeriesPaint(0, Color.decode("#5882FA")); // Mostrar Grafico ChartFrame frame = new ChartFrame("CONSUMO", chart); frame.pack(); frame.getChartPanel().setMouseZoomable(false); frame.setVisible(true); panel.add(frame); }
From source file:edu.uara.gui.tableeditor.ChartGenerationFrame.java
private void generateChart() { //generate Base Dataset (Category Dataset) if (datasetTable != null) this.generateBaseDataset(); if (c != null) { if (this.splitPane.getTopComponent() == panel) { int option = JOptionPane.showConfirmDialog(this, "Create new chart?\r\n", "Warning", JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { if (this.cmd_saveChart.isEnabled()) { int innerOption = JOptionPane.showConfirmDialog(this, "Current chart is modified. Do you want to save?\r\n", "Warning", JOptionPane.YES_NO_OPTION); if (innerOption == JOptionPane.YES_OPTION) this.saveFigure(); }/* w w w.j a va 2 s .com*/ this.figure = null; this.splitPane.remove(panel); } else return; } } if (this.pieChartOption.isSelected()) { //get series PieDataset dataset = null; String series = this.cbo_pieDataSeries.getSelectedItem().toString(); CustomPieChart ch = new CustomPieChart(txt_chartName.getText(), this.opt_legend.isSelected());//legend String tableOrder = cbo_pieDataSelect.getSelectedItem().toString(); TableOrder tbOrder = null; if (tableOrder.equals("Row")) { tbOrder = TableOrder.BY_ROW; } else { tbOrder = TableOrder.BY_COLUMN; } if (this.opt_multiPieCharts.isSelected())//multiple piechart { if (this.opt_effect3D.isSelected()) ch.generateMultiple3DPieChart(baseDataset, tbOrder); else ch.generateMultiplePieChart(baseDataset, tbOrder); if (this.opt_exploded.isSelected()) { try { ch.setExplodePercent(this.cbo_explodedSections.getSelectedItem().toString(), Double.parseDouble(this.txt_explodedPercent.getText())); } catch (Exception ex) { System.out.println("Error setting exploded section! " + ex.getMessage()); } } } else { try { if (tbOrder == TableOrder.BY_ROW) dataset = DatasetUtilities.createPieDatasetForRow(baseDataset, series); else dataset = DatasetUtilities.createPieDatasetForColumn(baseDataset, series); } catch (Exception ex) { System.out.println("Error with pie dataset, default series is used"); dataset = DatasetUtilities.createPieDatasetForRow(baseDataset, 0); } //ch.setIgnoreNullOrZeroValues(true);//ignore null values if (opt_effect3D.isSelected()) { ch.generate3DPieChart(dataset, series, tbOrder); } else { ch.generatePieChart(dataset, series, tbOrder); //edit exploded parts if (this.opt_exploded.isSelected()) { try { ch.setExplodePercent(this.cbo_explodedSections.getSelectedItem().toString(), Double.parseDouble(this.txt_explodedPercent.getText())); } catch (Exception ex) { System.out.println("Error setting exploded section! " + ex.getMessage()); } } } } ch.setIgnoreNullOrZeroValues(true);//ignore null values int labelFormat = cbo_pieSectionLabel.getSelectedIndex(); ch.setLabelFormat(labelFormat); c = ch; this.updateStatus("Pie chart has been generated."); } else if (this.lineChartOption.isSelected()) { // create a chart... PlotOrientation orientation;//options for orientation if (this.opt_layoutV.isSelected()) orientation = PlotOrientation.VERTICAL; else if (this.opt_layoutH.isSelected()) orientation = PlotOrientation.HORIZONTAL; else orientation = PlotOrientation.VERTICAL; CustomLineChart ch = new CustomLineChart(this.txt_chartName.getText(), this.txt_DomainLabel.getText(), this.txt_RangeLabel.getText(), orientation, this.opt_legend.isSelected()); if (opt_effect3D.isSelected()) { ch.generate3DLineChart(baseDataset); } else { ch.generateLineChart(baseDataset); } //apply options if (this.opt_showGridline.isSelected()) { ch.setGridLineVisible(true); } else { ch.setGridLineVisible(false); } c = ch; this.updateStatus("Line chart has been generated."); } else if (this.BarChartOption.isSelected()) { // create a chart... PlotOrientation orientation;//options for orientation if (this.opt_layoutV.isSelected()) orientation = PlotOrientation.VERTICAL; else if (this.opt_layoutH.isSelected()) orientation = PlotOrientation.HORIZONTAL; else orientation = PlotOrientation.VERTICAL; CustomBarChart ch = new CustomBarChart(this.txt_chartName.getText(), this.txt_DomainLabel.getText(), this.txt_RangeLabel.getText(), orientation, opt_legend.isSelected()); if (this.opt_subCategory.isSelected()) { ch.generateGroupBarChart(baseDataset, groupMap); ch.setSubCategoryAxis(txt_DomainLabel.getText(), datasetTable.getGroupKey()); } else { if (opt_effect3D.isSelected()) { if (this.opt_effectStacked.isSelected()) ch.generate3DStackedBarChart(baseDataset); else ch.generate3DBarChart(baseDataset); } else { if (this.opt_effectStacked.isSelected()) ch.generateStackedBarChart(baseDataset); else ch.generateBarChart(baseDataset); } } //apply options if (this.opt_showGridline.isSelected()) { ch.setGridLineVisible(true); } else { ch.setGridLineVisible(false); } if (this.opt_showItemLabel.isSelected()) { ch.setItemLabelGenerator(txt_itemLabelFormat.getText(), Integer.parseInt(cbo_itemLabelSize.getSelectedItem().toString())); ch.setItemLabelVisible(true); } c = ch; this.updateStatus("Bar chart has been generated."); } else if (this.combinedChartOption.isSelected()) { //not available yet } else { JOptionPane.showMessageDialog(this, "Please select chart type first!"); return; } //c.generate3DStackedBarChart(baseDataset); ChartFrame f = c.drawChart(""); panel = f.getChartPanel(); splitPane.setDividerLocation(panel.getHeight()); this.splitPane.setTopComponent(panel); //ChartPanel.add(panel); //panel.setSize(500, splitPane.getWidth()); if (panel != null) panel.addHierarchyBoundsListener(new java.awt.event.HierarchyBoundsListener() { @Override public void ancestorResized(java.awt.event.HierarchyEvent evt) { panelAncestorResized(evt); }; @Override public void ancestorMoved(HierarchyEvent e) { } }); this.cmd_saveChart.setEnabled(true); this.cmd_changeSeriesColor.setEnabled(true); this.cmd_generateChart.setEnabled(false); }