List of usage examples for org.jfree.chart ChartPanel setChart
public void setChart(JFreeChart chart)
From source file:ws.moor.bt.grapher.Grapher.java
public static void main(String[] args) throws IOException { if (args.length != 1) { System.err.println("Please specify a tab-separated values file"); System.exit(1);//from w w w . j a va 2 s . c o m } File file = new File(args[0]); final CSVMapCollector collector = new CSVMapCollector( new CSVSkipFilter(new CSVInputStream(new FileInputStream(file)), 0 * 1000)); JFrame window = new JFrame("Grapher"); window.setSize(1100, 800); window.setLayout(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(null); List<String> possibleNames = collector.getAvailableStreams(); Collections.sort(possibleNames); TreeNode root = convertToTree(possibleNames); final JTree tree = new JTree(root); tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { List<String> names = new ArrayList<String>(); final TreePath[] paths = tree.getSelectionModel().getSelectionPaths(); if (paths == null) { chartPanel.setChart(null); return; } for (TreePath path : paths) { Object lastPath = path.getLastPathComponent(); if (lastPath instanceof DefaultMutableTreeNode) { Object value = ((DefaultMutableTreeNode) lastPath).getUserObject(); if (value instanceof NodeValue) { names.add(value.toString()); } } } chartPanel.setChart(createChart(collector, names.toArray(new String[names.size()]))); } }); Font font = tree.getFont(); tree.setFont(font.deriveFont(10.0f)); JScrollPane scrollPane = new JScrollPane(tree); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitPane.setLeftComponent(scrollPane); splitPane.setRightComponent(chartPanel); splitPane.setDividerLocation(200); window.setContentPane(splitPane); window.setVisible(true); }
From source file:com.hazelcast.simulator.visualiser.ui.Chart.java
public Chart(Model model, AccuracyRadioButtons accuracyRadioButtons, AutoScaleRadioButtons autoScaleRadioButtons, ProbesCheckboxes probesCheckboxes) { this.model = model; this.accuracyRadioButtons = accuracyRadioButtons; this.autoScaleRadioButtons = autoScaleRadioButtons; this.probesCheckboxes = probesCheckboxes; setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); setLayout(new BorderLayout()); initSliders();/*from w w w . j av a2 s . co m*/ JPanel horizontalSlidersPanel = new JPanel(); horizontalSlidersPanel.setLayout(new BoxLayout(horizontalSlidersPanel, BoxLayout.Y_AXIS)); horizontalSlidersPanel.add(mainHorizontalSlider); horizontalSlidersPanel.add(fineHorizontalSlider); JFreeChart chart = ChartFactory.createHistogram("Latency Distribution", "Latency (s)", "Operations", null, PlotOrientation.VERTICAL, true, true, true); plot = chart.getXYPlot(); plot.setForegroundAlpha(ALPHA); ChartPanel chartPanel = new ChartPanel(null); chartPanel.setChart(chart); add(horizontalSlidersPanel, BorderLayout.SOUTH); add(verticalSlider, BorderLayout.EAST); add(chartPanel, BorderLayout.CENTER); initSliderChangeListener(); }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.DoseResponseController.java
/** * Plots the fitted data.//from w w w . jav a2 s .c o m */ public void plotDoseResponse(ChartPanel chartPanel, JPanel subviewPanel, List<DoseResponsePair> dataToPlot, DoseResponseAnalysisGroup analysisGroup, boolean normalized) { JFreeChart doseResponseChart = createDoseResponseChart(dataToPlot, normalized); chartPanel.setChart(doseResponseChart); //add chartpanel to graphics parent panel and repaint subviewPanel.add(chartPanel, gridBagConstraints); dRPanel.getGraphicsDRParentPanel().repaint(); dRPanel.getGraphicsDRParentPanel().revalidate(); }
From source file:edu.wpi.cs.wpisuitetng.modules.requirementsmanager.view.charts.StatView.java
/** * method to update the displayed chart based on the user's selection *///w w w. j a v a2 s .c o m public void updateChart() { JFreeChart chart = null; AbstractRequirementStatistics stats = null; // initialize the stats based on the type of data which the user has // selected switch (chartDataType) { case STATUS: stats = new StatusRequirementStatistics(); break; case ITERATION: stats = new IterationRequirementStatistics(); break; case ASSIGNEE: stats = new AssigneeRequirementStatistics(); break; case ESTIMATES: stats = new EstimateRequirementStatistics(); break; case EFFORT: stats = new ActualRequirementStatistics(); break; case VELOCITY: stats = new VelocityIterationStatistics(); break; case TASK: stats = new TaskRequirementStatistics(); break; default: // if you encounter this default statement, it means that new // values // have been // added to the DataType enum, but nobody has modified this poor // little method } // build the chart based on the type of chart the user has selected switch (chartType) { case BAR: // TODO: determine if additional modifications need to be // made // to the plot chart = stats.buildBarChart(); final CategoryPlot barPlot = (CategoryPlot) chart.getPlot(); barPlot.setNoDataMessage("No data available"); break; case PIE: chart = stats.buildPieChart(); final PiePlot3D piePlot = (PiePlot3D) chart.getPlot(); piePlot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); piePlot.setNoDataMessage("No data available"); piePlot.setCircular(true); piePlot.setLabelGap(0.02); piePlot.setForegroundAlpha(0.7f); final PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{0} = {1} ({2})"); piePlot.setLabelGenerator(generator); break; case LINE: chart = stats.buildLineChart(); final CategoryPlot linePlot = (CategoryPlot) chart.getPlot(); linePlot.setNoDataMessage("No data available"); default: // if you encounter this default statement, it means that new // values have been added to the ChartType enum, but nobody has // modified this poor little method } // add the newly generated chart to the panel final JSplitPane mainPane = (JSplitPane) getComponent(0); final ChartPanel chartPanel = (ChartPanel) mainPane.getLeftComponent(); chartPanel.setChart(chart); return; }
From source file:org.streamspinner.harmonica.application.CQGraphTerminal.java
public void dataDistributed(CQRowSetEvent e) { try {//from w ww . ja v a2 s. com base = 0; CQRowSet rs = (CQRowSet) e.getSource(); CQRowSetMetaData meta = rs.getMetaData(); if (chart == null) { c = new TimeSeriesCollection(); boolean first_loop = true; rs.beforeFirst(); String[] t_obj = new String[meta.getColumnCount()]; String[] t_val = new String[meta.getColumnCount()]; while (rs.next()) { for (int i = 1; i <= meta.getColumnCount(); i++) { double val = 0; t_obj[i - 1] = meta.getColumnName(i); if (meta.getColumnTypeName(i).equals(DataTypes.STRING)) { t_val[i - 1] = rs.getString(i); continue; } if (meta.getColumnTypeName(i).equals(DataTypes.OBJECT)) { t_val[i - 1] = rs.getObject(i).toString(); continue; } if (meta.getColumnTypeName(i).equals(DataTypes.LONG)) { long lval = rs.getLong(i); val = (double) lval; t_val[i - 1] = String.valueOf(lval); } else if (meta.getColumnTypeName(i).equals(DataTypes.DOUBLE)) { val = rs.getDouble(i); t_val[i - 1] = String.valueOf(val); } else { t_val[i - 1] = rs.getString(i); continue; } if (val < 1000000 || Double.isNaN(val)) { TimeSeries ts = updateTimeSeries(meta.getColumnName(i), i, val); } } if (model == null) { model = new DefaultTableModel(t_obj, 0); getJTable().setModel(model); } model.addRow(t_val); while (model.getRowCount() > 100) { model.removeRow(0); } first_loop = false; } chart = ChartFactory.createTimeSeriesChart("", "", "", c, true, true, true); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.BLACK); plot.setRangeGridlinePaint(Color.WHITE); plot.getDomainAxis().setAutoRange(true); plot.getRangeAxis().setAutoRange(true); ValueAxis axis = plot.getDomainAxis(); axis.setLowerMargin(0.03); axis.setUpperMargin(0.03); ChartPanel panel = (ChartPanel) getJPanel(); panel.setChart(chart); } else { String[] t_val = new String[meta.getColumnCount()]; rs.beforeFirst(); while (rs.next()) { for (int i = 1; i <= meta.getColumnCount(); i++) { double val = 0; if (meta.getColumnTypeName(i).equals(DataTypes.STRING)) { t_val[i - 1] = rs.getString(i); continue; } if (meta.getColumnTypeName(i).equals(DataTypes.OBJECT)) { t_val[i - 1] = rs.getObject(i).toString(); continue; } if (meta.getColumnTypeName(i).equals(DataTypes.LONG)) { long lval = rs.getLong(i); val = (double) lval; t_val[i - 1] = String.valueOf(lval); } else if (meta.getColumnTypeName(i).equals(DataTypes.DOUBLE)) { val = rs.getDouble(i); t_val[i - 1] = String.valueOf(val); } else { t_val[i - 1] = rs.getString(i); continue; } if (val < 1000000 || Double.isNaN(val)) { TimeSeries ts = updateTimeSeries(meta.getColumnName(i), i, val); } } model.addRow(t_val); while (model.getRowCount() > 100) { model.removeRow(0); } } repaint(); } } catch (CQException ce) { ce.printStackTrace(); } }
From source file:com.compomics.cell_coord.gui.controller.summary.VisualizeTracksController.java
/** * Given the number of columns to use, set the charts with the * xySeriesCollections generated./*from w ww. ja va 2 s .c o m*/ * * @param nCols */ private void setChartsWithCollections(int nCols) { List<Sample> samples = loadTracksController.getSamples(); int nPlots = xYSeriesCollections.size(); for (int i = 0; i < nPlots; i++) { XYSeriesCollection collection = xYSeriesCollections.get(i); int numberTracks = collection.getSeries().size(); String title = numberTracks + " tracks" + " - " + samples.get(i).getName(); // create a chart for each plate condition JFreeChart coordinatesChart = ChartFactory.createXYLineChart(title, "x (m)", "y (m)", collection, PlotOrientation.VERTICAL, false, true, false); // and a new chart panel as well ChartPanel coordinatesChartPanel = new ChartPanel(null); coordinatesChartPanel.setOpaque(false); // compute the constraints GridBagConstraints specialGBC = getGridBagConstraints(nPlots, i, nCols); visualizeTracksPanel.getTracksGraphicsParentPanel().add(coordinatesChartPanel, specialGBC); if (visualizeTracksPanel.getScaleAxesRadioButton().isSelected()) { scaleAxes(coordinatesChart, visualizeTracksPanel.getRawCoordRadioButton().isSelected()); } coordinatesChartPanel.setChart(coordinatesChart); // add the chart panels to the list tracksChartPanels.add(coordinatesChartPanel); visualizeTracksPanel.getTracksGraphicsParentPanel().revalidate(); visualizeTracksPanel.getTracksGraphicsParentPanel().repaint(); } }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.SingleCellAnalysisController.java
/** * Set all the charts with the generated XYSeriesCollections. * * @param nCols// w w w .jav a2 s .c o m */ private void setTrackChartsWithCollections(int nCols) { int length = GuiUtils.getAvailableColors().length; List<PlateCondition> plateConditionList = singleCellMainController.getPlateConditionList(); for (int i = 0; i < plateConditionList.size(); i++) { XYSeriesCollection collection = cellTracksData.get(i); int numberTracks = collection.getSeries().size(); String title = numberTracks + " tracks" + " - " + plateConditionList.get(i); // create a chart for each plate condition JFreeChart coordinatesChart = ChartFactory.createXYLineChart(title, "x (m)", "y (m)", collection, PlotOrientation.VERTICAL, false, true, false); // and a new chart panel as well ChartPanel coordinatesChartPanel = new ChartPanel(null); coordinatesChartPanel.setOpaque(false); // compute the constraints GridBagConstraints tempBagConstraints = GuiUtils.getTempBagConstraints(plateConditionList.size(), i, nCols); analysisPanel.getTrackPlotParentPanel().add(coordinatesChartPanel, tempBagConstraints); JFreeChartUtils.setupTrackChart(coordinatesChart); TrackXYLineAndShapeRenderer trackXYLineAndShapeRenderer = new TrackXYLineAndShapeRenderer(true, false, false, null, -1, 2, false); trackXYLineAndShapeRenderer.setChosenColor(GuiUtils.getAvailableColors()[i % length]); coordinatesChart.getXYPlot().setRenderer(trackXYLineAndShapeRenderer); coordinatesChartPanel.setChart(coordinatesChart); // add the chart panels to the list cellTracksChartPanels.add(coordinatesChartPanel); analysisPanel.getTrackPlotParentPanel().revalidate(); analysisPanel.getTrackPlotParentPanel().repaint(); } }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.GlobalViewConditionController.java
/** * Set all the charts with the generated XYSeriesCollections. * * @param nCols/*www .ja va2 s . c om*/ */ private void setChartsWithCollections(int nCols) { // plot logic boolean plotLines = plotSettingsMenuBar.getPlotLinesCheckBoxMenuItem().isSelected(); boolean plotPoints = plotSettingsMenuBar.getPlotPointsCheckBoxMenuItem().isSelected(); boolean showEndPoints = plotSettingsMenuBar.getShowEndPointsCheckBoxMenuItem().isSelected(); Float lineWidth = plotSettingsMenuBar.getSelectedLineWidth(); boolean useCellMissyColor = plotSettingsMenuBar.getUseCellMissyColors().isSelected(); int nPlots = xYSeriesCollections.size(); int length = GuiUtils.getAvailableColors().length; for (int i = 0; i < nPlots; i++) { XYSeriesCollection collection = xYSeriesCollections.get(i); int numberTracks = collection.getSeries().size(); SingleCellConditionDataHolder conditionDataHolder = trackCoordinatesController .getConditionDataHolder(trackCoordinatesController.getCurrentCondition()); String title = numberTracks + " tracks" + " - " + conditionDataHolder.getSingleCellWellDataHolders().get(i).getWell(); // create a chart for each plate condition JFreeChart coordinatesChart = ChartFactory.createXYLineChart(title, "x (m)", "y (m)", collection, PlotOrientation.VERTICAL, false, true, false); // and a new chart panel as well ChartPanel coordinatesChartPanel = new ChartPanel(null); coordinatesChartPanel.setOpaque(false); // compute the constraints GridBagConstraints tempBagConstraints = GuiUtils.getTempBagConstraints(nPlots, i, nCols); trackCoordinatesController.getTrackCoordinatesPanel().getGlobalViewConditionParentPanel() .add(coordinatesChartPanel, tempBagConstraints); // see if exes need to be scaled if (plotOptionsPanel.getScaleAxesRadioButton().isSelected()) { trackCoordinatesController.scaleAxesToExperiment(coordinatesChart, plotOptionsPanel.getUnshiftedCoordinatesRadioButton().isSelected()); } JFreeChartUtils.setupTrackChart(coordinatesChart); TrackXYLineAndShapeRenderer trackXYLineAndShapeRenderer = new TrackXYLineAndShapeRenderer(plotLines, plotPoints, showEndPoints, getEndPoints(collection), -1, lineWidth, useCellMissyColor); trackXYLineAndShapeRenderer.setChosenColor(GuiUtils.getAvailableColors()[i % length]); coordinatesChart.getXYPlot().setRenderer(trackXYLineAndShapeRenderer); coordinatesChartPanel.setChart(coordinatesChart); // add the chart panels to the list coordinatesChartPanels.add(coordinatesChartPanel); trackCoordinatesController.getTrackCoordinatesPanel().getGlobalViewConditionParentPanel().revalidate(); trackCoordinatesController.getTrackCoordinatesPanel().getGlobalViewConditionParentPanel().repaint(); } }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.GlobalViewExperimentController.java
/** * Set all the charts with the generated XYSeriesCollections. * * @param nCols/* w w w .ja va 2 s.c o m*/ */ private void setChartsWithCollections(int nCols) { // plot logic boolean plotLines = plotSettingsMenuBar.getPlotLinesCheckBoxMenuItem().isSelected(); boolean plotPoints = plotSettingsMenuBar.getPlotPointsCheckBoxMenuItem().isSelected(); boolean showEndPoints = plotSettingsMenuBar.getShowEndPointsCheckBoxMenuItem().isSelected(); Float lineWidth = plotSettingsMenuBar.getSelectedLineWidth(); boolean useCellMissyColor = plotSettingsMenuBar.getUseCellMissyColors().isSelected(); int nPlots = xYSeriesCollections.size(); int length = GuiUtils.getAvailableColors().length; List<PlateCondition> plateConditionList = trackCoordinatesController.getPlateConditionList(); for (int i = 0; i < nPlots; i++) { XYSeriesCollection collection = xYSeriesCollections.get(i); int numberTracks = collection.getSeries().size(); String title = numberTracks + " tracks" + " - " + plateConditionList.get(i); // create a chart for each plate condition JFreeChart coordinatesChart = ChartFactory.createXYLineChart(title, "x (m)", "y (m)", collection, PlotOrientation.VERTICAL, false, true, false); // and a new chart panel as well ChartPanel coordinatesChartPanel = new ChartPanel(null); coordinatesChartPanel.setOpaque(false); // compute the constraints GridBagConstraints tempBagConstraints = GuiUtils.getTempBagConstraints(nPlots, i, nCols); trackCoordinatesController.getTrackCoordinatesPanel().getGlobalViewExpParentPanel() .add(coordinatesChartPanel, tempBagConstraints); // see if exes need to be scaled if (plotOptionsPanel.getScaleAxesRadioButton().isSelected()) { trackCoordinatesController.scaleAxesToExperiment(coordinatesChart, plotOptionsPanel.getUnshiftedCoordinatesRadioButton().isSelected()); } JFreeChartUtils.setupTrackChart(coordinatesChart); TrackXYLineAndShapeRenderer trackXYLineAndShapeRenderer = new TrackXYLineAndShapeRenderer(plotLines, plotPoints, showEndPoints, getEndPoints(collection), -1, lineWidth, useCellMissyColor); trackXYLineAndShapeRenderer.setChosenColor(GuiUtils.getAvailableColors()[i % length]); coordinatesChart.getXYPlot().setRenderer(trackXYLineAndShapeRenderer); coordinatesChartPanel.setChart(coordinatesChart); // add the chart panels to the list coordinatesChartPanels.add(coordinatesChartPanel); trackCoordinatesController.getTrackCoordinatesPanel().getGlobalViewExpParentPanel().revalidate(); trackCoordinatesController.getTrackCoordinatesPanel().getGlobalViewExpParentPanel().repaint(); } }
From source file:jgnash.ui.report.compiled.RunningAccountBalanceChart.java
private JPanel createPanel() { LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate()); LocalDate start = end.minusYears(1); startDateField.setDate(start);// w w w.j a va 2 s. c o m JButton refreshButton = new JButton(rb.getString("Button.Refresh")); refreshButton.setIcon(IconUtils.getIcon("/jgnash/resource/view-refresh.png")); subAccountCheckBox = new JCheckBox(rb.getString("Button.IncludeSubAccounts")); subAccountCheckBox.setSelected(true); hideLockedAccountCheckBox = new JCheckBox(rb.getString("Button.HideLockedAccount")); hidePlaceholderAccountCheckBox = new JCheckBox(rb.getString("Button.HidePlaceholderAccount")); JFreeChart chart = createVerticalXYBarChart(combo.getSelectedAccount()); final ChartPanel chartPanel = new ChartPanel(chart); FormLayout layout = new FormLayout("p, 4dlu, p:g", ""); DefaultFormBuilder builder = new DefaultFormBuilder(layout); FormLayout dLayout = new FormLayout("p, 4dlu, p, 8dlu, p, 4dlu, p, 8dlu, p", ""); DefaultFormBuilder dBuilder = new DefaultFormBuilder(dLayout); dBuilder.append(rb.getString("Label.StartDate"), startDateField); dBuilder.append(rb.getString("Label.EndDate"), endDateField); dBuilder.append(refreshButton); FormLayout cbLayout = new FormLayout("p, 4dlu, p, 4dlu, p, 4dlu", ""); DefaultFormBuilder cbBuilder = new DefaultFormBuilder(cbLayout); cbBuilder.append(subAccountCheckBox); cbBuilder.append(hideLockedAccountCheckBox); cbBuilder.append(hidePlaceholderAccountCheckBox); builder.append(rb.getString("Label.Account"), combo); builder.nextLine(); builder.append(" "); builder.append(cbBuilder.getPanel()); builder.nextLine(); builder.appendRelatedComponentsGapRow(); builder.nextLine(); builder.append(dBuilder.getPanel(), 3); builder.nextLine(); builder.appendUnrelatedComponentsGapRow(); builder.nextLine(); builder.appendRow(RowSpec.decode("fill:p:g")); builder.append(chartPanel, 3); final JPanel panel = builder.getPanel(); ActionListener listener = e -> { updateSubAccountBox(); Account a = combo.getSelectedAccount(); if (a == null) { return; } chartPanel.setChart(createVerticalXYBarChart(a)); panel.validate(); }; hideLockedAccountCheckBox.addActionListener(e -> { combo.setHideLocked(hideLockedAccountCheckBox.isSelected()); updateSubAccountBox(); Account a = combo.getSelectedAccount(); if (a == null) { return; } chartPanel.setChart(createVerticalXYBarChart(a)); panel.validate(); }); hidePlaceholderAccountCheckBox.addActionListener(e -> { combo.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected()); updateSubAccountBox(); Account a = combo.getSelectedAccount(); if (a == null) { return; } chartPanel.setChart(createVerticalXYBarChart(a)); panel.validate(); }); updateSubAccountBox(); combo.addActionListener(listener); refreshButton.addActionListener(listener); return panel; }