Java Code Examples for org.jfree.chart.ChartPanel#setSize()
The following examples show how to use
org.jfree.chart.ChartPanel#setSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResultPlotTab.java From incubator-iotdb with Apache License 2.0 | 5 votes |
ResultPlotTab(String planName, Map<String, JFreeChart> charts, TabCloseCallBack closeCallBack) { super(planName, charts, closeCallBack); chartPanel = new ChartPanel(null); chartPanel.setBorder(BorderFactory.createTitledBorder("Plot area")); chartPanel.setLayout(new GridBagLayout()); chartPanel.setLocation(0, 60); chartPanel.setSize(800, 480); add(chartPanel); }
Example 2
Source File: ChartLogics.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
/** * Calculates the size of a chart for a given fixed plot width and height * * @param chart * @param plotWidth * @return */ public static Dimension calcSizeForPlotSize(ChartPanel myChart, double plotWidth, double plotHeight, int iterations) { makeChartResizable(myChart); // estimate plotwidth / height double estimatedChartWidth = plotWidth + 200; double estimatedChartHeight = plotHeight + 200; double lastW = estimatedChartWidth; double lastH = estimatedChartHeight; // paint and get closer try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy // panel==true) myChart.setSize((int) estimatedChartWidth, (int) estimatedChartHeight); myChart.paintImmediately(myChart.getBounds()); // rendering info ChartRenderingInfo info = myChart.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // // calc title space: will be added later to the right plot // size // double titleWidth = chartArea.getWidth()-dataArea.getWidth(); // double titleHeight = // chartArea.getHeight()-dataArea.getHeight(); // calc width and height estimatedChartWidth = estimatedChartWidth - dataArea.getWidth() + plotWidth; estimatedChartHeight = estimatedChartHeight - dataArea.getHeight() + plotHeight; if ((int) lastW == (int) estimatedChartWidth && (int) lastH == (int) estimatedChartHeight) break; else { lastW = estimatedChartWidth; lastH = estimatedChartHeight; } } } catch (Exception ex) { ex.printStackTrace(); } return new Dimension((int) estimatedChartWidth, (int) estimatedChartHeight); }
Example 3
Source File: ChartLogics.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
/** * calculates the correct height with multiple iterations Domain and Range axes need to share the * same unit (e.g. mm) * * @param myChart * @param copyToNewPanel * @param dataWidth width of data * @param axis for width calculation * @return */ public static double calcHeightToWidth(ChartPanel myChart, double chartWidth, double estimatedHeight, int iterations, boolean copyToNewPanel) { // if(myChart.getChartRenderingInfo()==null || // myChart.getChartRenderingInfo().getChartArea()==null || // myChart.getChartRenderingInfo().getChartArea().getWidth()==0) // result double height = estimatedHeight; double lastH = height; makeChartResizable(myChart); // paint on a ghost panel JPanel parent = (JPanel) myChart.getParent(); JPanel p = copyToNewPanel ? new JPanel() : parent; if (copyToNewPanel) p.add(myChart, BorderLayout.CENTER); try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy // panel==true) myChart.setSize((int) chartWidth, (int) estimatedHeight); myChart.paintImmediately(myChart.getBounds()); XYPlot plot = (XYPlot) myChart.getChart().getPlot(); ChartRenderingInfo info = myChart.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // calc title space: will be added later to the right plot size double titleWidth = chartArea.getWidth() - dataArea.getWidth(); double titleHeight = chartArea.getHeight() - dataArea.getHeight(); // calc right plot size with axis dim. // real plot width is given by factor; double realPW = chartWidth - titleWidth; // ranges ValueAxis domainAxis = plot.getDomainAxis(); org.jfree.data.Range x = domainAxis.getRange(); ValueAxis rangeAxis = plot.getRangeAxis(); org.jfree.data.Range y = rangeAxis.getRange(); // real plot height can be calculated by double realPH = realPW / x.getLength() * y.getLength(); // the real height height = realPH + titleHeight; // for next iteration estimatedHeight = height; if ((int) lastH == (int) height) break; else lastH = height; } } catch (Exception ex) { ex.printStackTrace(); } if (copyToNewPanel) { // reset to frame p.removeAll(); parent.add(myChart); } return height; }
Example 4
Source File: WinrateHistogramDialog.java From mylizzie with GNU General Public License v3.0 | 4 votes |
private void initCustomComponents() { WinrateHistogramTableModel winrateHistogramTableModel = new WinrateHistogramTableModel(tableWinrateHistory); tableWinrateHistory.setModel(winrateHistogramTableModel); XYSeries blackSeries = new XYSeries("Black"); XYSeries whiteSeries = new XYSeries("White"); XYSeries standardSeries = new XYSeries("50%"); for (int i = 0; i <= 50; ++i) { standardSeries.add(i, 50); } dataSet = new XYSeriesCollection(); dataSet.addSeries(blackSeries); dataSet.addSeries(whiteSeries); dataSet.addSeries(standardSeries); JFreeChart chart = ChartFactory.createXYLineChart( "", // chart title "", // x axis label "Win%", // y axis label dataSet, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.WHITE); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setRange(0.0, 100.0); histogramChartPanel = new ChartPanel(chart); panelWinrateHistogram.add(histogramChartPanel); winrateHistogramTableModel.setRefreshObserver(new Consumer<WinrateHistogramTableModel>() { private long lastRefreshTime = System.currentTimeMillis(); @Override public void accept(WinrateHistogramTableModel model) { long currentTime = System.currentTimeMillis(); if (currentTime - lastRefreshTime < 250L) { return; } lastRefreshTime = currentTime; SwingUtilities.invokeLater(() -> { blackSeries.clear(); whiteSeries.clear(); standardSeries.clear(); for (int i = 0; i < model.getHistogramEntryList().size(); ++i) { WinrateHistogramEntry entry = model.getHistogramEntryList().get(i); standardSeries.add(entry.getMoveNumber(), 50); if (checkBoxHistogramShowBlack.isSelected()) { blackSeries.add(entry.getMoveNumber(), entry.getBlackWinrate()); } if (checkBoxHistogramShowWhite.isSelected()) { whiteSeries.add(entry.getMoveNumber(), entry.getWhiteWinrate()); } } if (model.getHistogramEntryList().size() < 50) { for (int i = model.getHistogramEntryList().size() - 1; i <= 50; ++i) { standardSeries.add(i, 50); } } histogramChartPanel.repaint(); }); } }); setPreferredSize(new Dimension( Lizzie.optionSetting.getWinrateHistogramWindowState().getWidth() , Lizzie.optionSetting.getWinrateHistogramWindowState().getHeight() )); splitPaneHistogram.setDividerLocation(0.3); pack(); histogramChartPanel.setPreferredSize(new Dimension(panelWinrateHistogram.getWidth(), panelWinrateHistogram.getHeight())); histogramChartPanel.setSize(panelWinrateHistogram.getWidth(), panelWinrateHistogram.getHeight()); pack(); }
Example 5
Source File: ChartLogics.java From old-mzmine3 with GNU General Public License v2.0 | 4 votes |
/** * Calculates the size of a chart for a given fixed plot width and height * * @param chart * @param plotWidth * @return */ public static Dimension calcSizeForPlotSize(ChartPanel myChart, double plotWidth, double plotHeight, int iterations) { makeChartResizable(myChart); // estimate plotwidth / height double estimatedChartWidth = plotWidth + 200; double estimatedChartHeight = plotHeight + 200; double lastW = estimatedChartWidth; double lastH = estimatedChartHeight; // paint and get closer try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.setSize((int) estimatedChartWidth, (int) estimatedChartHeight); myChart.paintImmediately(myChart.getBounds()); // rendering info ChartRenderingInfo info = myChart.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // // calc title space: will be added later to the right plot size // double titleWidth = chartArea.getWidth()-dataArea.getWidth(); // double titleHeight = chartArea.getHeight()-dataArea.getHeight(); // calc width and height estimatedChartWidth = estimatedChartWidth - dataArea.getWidth() + plotWidth; estimatedChartHeight = estimatedChartHeight - dataArea.getHeight() + plotHeight; if ((int) lastW == (int) estimatedChartWidth && (int) lastH == (int) estimatedChartHeight) break; else { lastW = estimatedChartWidth; lastH = estimatedChartHeight; } } } catch (Exception ex) { ex.printStackTrace(); } return new Dimension((int) estimatedChartWidth, (int) estimatedChartHeight); }
Example 6
Source File: ChartLogics.java From old-mzmine3 with GNU General Public License v2.0 | 4 votes |
/** * calculates the correct height with multiple iterations Domain and Range axes need to share the * same unit (e.g. mm) * * @param myChart * @param copyToNewPanel * @param dataWidth width of data * @param axis for width calculation * @return */ public static double calcHeightToWidth(ChartPanel myChart, double chartWidth, double estimatedHeight, int iterations, boolean copyToNewPanel) { // if(myChart.getChartRenderingInfo()==null || // myChart.getChartRenderingInfo().getChartArea()==null || // myChart.getChartRenderingInfo().getChartArea().getWidth()==0) // result double height = estimatedHeight; double lastH = height; makeChartResizable(myChart); // paint on a ghost panel JPanel parent = (JPanel) myChart.getParent(); JPanel p = copyToNewPanel ? new JPanel() : parent; if (copyToNewPanel) p.add(myChart, BorderLayout.CENTER); try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.setSize((int) chartWidth, (int) estimatedHeight); myChart.paintImmediately(myChart.getBounds()); XYPlot plot = (XYPlot) myChart.getChart().getPlot(); ChartRenderingInfo info = myChart.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // calc title space: will be added later to the right plot size double titleWidth = chartArea.getWidth() - dataArea.getWidth(); double titleHeight = chartArea.getHeight() - dataArea.getHeight(); // calc right plot size with axis dim. // real plot width is given by factor; double realPW = chartWidth - titleWidth; // ranges ValueAxis domainAxis = plot.getDomainAxis(); org.jfree.data.Range x = domainAxis.getRange(); ValueAxis rangeAxis = plot.getRangeAxis(); org.jfree.data.Range y = rangeAxis.getRange(); // real plot height can be calculated by double realPH = realPW / x.getLength() * y.getLength(); // the real height height = realPH + titleHeight; // for next iteration estimatedHeight = height; if ((int) lastH == (int) height) break; else lastH = height; } } catch (Exception ex) { ex.printStackTrace(); } if (copyToNewPanel) { // reset to frame p.removeAll(); parent.add(myChart); } return height; }
Example 7
Source File: ChartLogics.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
/** * Calculates the size of a chart for a given fixed plot width and height * * @param chart * @param plotWidth * @return */ public static Dimension calcSizeForPlotSize(ChartPanel myChart, double plotWidth, double plotHeight, int iterations) { makeChartResizable(myChart); // estimate plotwidth / height double estimatedChartWidth = plotWidth + 200; double estimatedChartHeight = plotHeight + 200; double lastW = estimatedChartWidth; double lastH = estimatedChartHeight; // paint and get closer try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.setSize((int) estimatedChartWidth, (int) estimatedChartHeight); myChart.paintImmediately(myChart.getBounds()); // rendering info ChartRenderingInfo info = myChart.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // // calc title space: will be added later to the right plot size // double titleWidth = chartArea.getWidth()-dataArea.getWidth(); // double titleHeight = chartArea.getHeight()-dataArea.getHeight(); // calc width and height estimatedChartWidth = estimatedChartWidth - dataArea.getWidth() + plotWidth; estimatedChartHeight = estimatedChartHeight - dataArea.getHeight() + plotHeight; if ((int) lastW == (int) estimatedChartWidth && (int) lastH == (int) estimatedChartHeight) break; else { lastW = estimatedChartWidth; lastH = estimatedChartHeight; } } } catch (Exception ex) { ex.printStackTrace(); } return new Dimension((int) estimatedChartWidth, (int) estimatedChartHeight); }
Example 8
Source File: ChartLogics.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
/** * calculates the correct height with multiple iterations Domain and Range axes need to share the * same unit (e.g. mm) * * @param myChart * @param copyToNewPanel * @param dataWidth width of data * @param axis for width calculation * @return */ public static double calcHeightToWidth(ChartPanel myChart, double chartWidth, double estimatedHeight, int iterations, boolean copyToNewPanel) { // if(myChart.getChartRenderingInfo()==null || // myChart.getChartRenderingInfo().getChartArea()==null || // myChart.getChartRenderingInfo().getChartArea().getWidth()==0) // result double height = estimatedHeight; double lastH = height; makeChartResizable(myChart); // paint on a ghost panel JPanel parent = (JPanel) myChart.getParent(); JPanel p = copyToNewPanel ? new JPanel() : parent; if (copyToNewPanel) p.add(myChart, BorderLayout.CENTER); try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.setSize((int) chartWidth, (int) estimatedHeight); myChart.paintImmediately(myChart.getBounds()); XYPlot plot = (XYPlot) myChart.getChart().getPlot(); ChartRenderingInfo info = myChart.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // calc title space: will be added later to the right plot size double titleWidth = chartArea.getWidth() - dataArea.getWidth(); double titleHeight = chartArea.getHeight() - dataArea.getHeight(); // calc right plot size with axis dim. // real plot width is given by factor; double realPW = chartWidth - titleWidth; // ranges ValueAxis domainAxis = plot.getDomainAxis(); org.jfree.data.Range x = domainAxis.getRange(); ValueAxis rangeAxis = plot.getRangeAxis(); org.jfree.data.Range y = rangeAxis.getRange(); // real plot height can be calculated by double realPH = realPW / x.getLength() * y.getLength(); // the real height height = realPH + titleHeight; // for next iteration estimatedHeight = height; if ((int) lastH == (int) height) break; else lastH = height; } } catch (Exception ex) { ex.printStackTrace(); } if (copyToNewPanel) { // reset to frame p.removeAll(); parent.add(myChart); } return height; }
Example 9
Source File: TSNEDemo.java From COMP6237 with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Component getComponent(int width, int height) throws IOException { final JPanel base = new JPanel(); base.setOpaque(false); base.setPreferredSize(new Dimension(width, height)); base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS)); chart = ChartFactory.createScatterPlot("", "", "", dataset, PlotOrientation.VERTICAL, false, false, false); final XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true) { private static final long serialVersionUID = 1L; @Override public ItemLabelPosition getPositiveItemLabelPosition(int row, int column) { return new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_LEFT); } }; final Font font = Font.decode("Helvetica Neue-22"); renderer.setBaseItemLabelFont(font); chart.getXYPlot().setRenderer(renderer); // chart.getXYPlot().getDomainAxis().setRange(-0.5, 5.5) chart.getXYPlot().getDomainAxis().setTickLabelFont(font); // chart.getXYPlot().getDomainAxis().setTickUnit(new NumberTickUnit(1)) // chart.getXYPlot().getRangeAxis().setRange(-0.5, 5.5) chart.getXYPlot().getRangeAxis().setTickLabelFont(font); // chart.getXYPlot().getRangeAxis().setTickUnit(new NumberTickUnit(1)) chart.getXYPlot().getRenderer().setBaseItemLabelGenerator(new StandardXYItemLabelGenerator() { private static final long serialVersionUID = 1L; @Override public String generateLabel(XYDataset ds, int series, int item) { return ((Dataset) ds).getLabel(series, item); }; }); chart.getXYPlot().getRenderer().setBaseItemLabelsVisible(true); chartPanel = new ChartPanel(chart); chart.setBackgroundPaint(new java.awt.Color(255, 255, 255, 255)); chart.getXYPlot().setBackgroundPaint(java.awt.Color.WHITE); chart.getXYPlot().setRangeGridlinePaint(java.awt.Color.GRAY); chart.getXYPlot().setDomainGridlinePaint(java.awt.Color.GRAY); chartPanel.setSize(width, height - 50); chartPanel.setPreferredSize(chartPanel.getSize()); base.add(chartPanel); final JPanel controls = new JPanel(); controls.setPreferredSize(new Dimension(width, 50)); controls.setMaximumSize(new Dimension(width, 50)); controls.setSize(new Dimension(width, 50)); controls.add(new JSeparator(SwingConstants.VERTICAL)); runBtn = new JButton("Run t-SNE"); runBtn.setActionCommand("button.run"); runBtn.addActionListener(this); controls.add(runBtn); controls.add(new JSeparator(SwingConstants.VERTICAL)); cnclBtn = new JButton("Cancel"); cnclBtn.setEnabled(false); cnclBtn.setActionCommand("button.cancel"); cnclBtn.addActionListener(this); controls.add(cnclBtn); base.add(controls); controls.add(new JSeparator(SwingConstants.VERTICAL)); iterLabel = new JLabel(" "); final Dimension size = iterLabel.getPreferredSize(); iterLabel.setMinimumSize(size); iterLabel.setPreferredSize(size); controls.add(iterLabel); updateImage(); return base; }
Example 10
Source File: MDSDemo.java From COMP6237 with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Component getComponent(int width, int height) throws IOException { final JPanel base = new JPanel(); base.setOpaque(false); base.setPreferredSize(new Dimension(width, height)); base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS)); chart = ChartFactory.createScatterPlot("", "", "", dataset, PlotOrientation.VERTICAL, false, false, false); final XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true) { private static final long serialVersionUID = 1L; @Override public ItemLabelPosition getPositiveItemLabelPosition(int row, int column) { return new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_LEFT); } }; final Font font = Font.decode("Helvetica Neue-22"); renderer.setBaseItemLabelFont(font); chart.getXYPlot().setRenderer(renderer); // chart.getXYPlot().getDomainAxis().setRange(-0.5, 5.5) chart.getXYPlot().getDomainAxis().setTickLabelFont(font); // chart.getXYPlot().getDomainAxis().setTickUnit(new NumberTickUnit(1)) // chart.getXYPlot().getRangeAxis().setRange(-0.5, 5.5) chart.getXYPlot().getRangeAxis().setTickLabelFont(font); // chart.getXYPlot().getRangeAxis().setTickUnit(new NumberTickUnit(1)) chart.getXYPlot().getRenderer().setBaseItemLabelGenerator(new StandardXYItemLabelGenerator() { private static final long serialVersionUID = 1L; @Override public String generateLabel(XYDataset ds, int series, int item) { return ((Dataset) ds).getLabel(series, item); }; }); chart.getXYPlot().getRenderer().setBaseItemLabelsVisible(true); chartPanel = new ChartPanel(chart); chart.setBackgroundPaint(new java.awt.Color(255, 255, 255, 255)); chart.getXYPlot().setBackgroundPaint(java.awt.Color.WHITE); chart.getXYPlot().setRangeGridlinePaint(java.awt.Color.GRAY); chart.getXYPlot().setDomainGridlinePaint(java.awt.Color.GRAY); chartPanel.setSize(width, height - 50); chartPanel.setPreferredSize(chartPanel.getSize()); base.add(chartPanel); final JPanel controls = new JPanel(); controls.setPreferredSize(new Dimension(width, 50)); controls.setMaximumSize(new Dimension(width, 50)); controls.setSize(new Dimension(width, 50)); controls.add(new JSeparator(SwingConstants.VERTICAL)); controls.add(new JLabel("Distance:")); distCombo = new JComboBox<String>(); distCombo.addItem("Euclidean"); distCombo.addItem("1-Pearson"); distCombo.addItem("1-Cosine"); controls.add(distCombo); controls.add(new JSeparator(SwingConstants.VERTICAL)); runBtn = new JButton("Run MDS"); runBtn.setActionCommand("button.run"); runBtn.addActionListener(this); controls.add(runBtn); controls.add(new JSeparator(SwingConstants.VERTICAL)); cnclBtn = new JButton("Cancel"); cnclBtn.setEnabled(false); cnclBtn.setActionCommand("button.cancel"); cnclBtn.addActionListener(this); controls.add(cnclBtn); base.add(controls); controls.add(new JSeparator(SwingConstants.VERTICAL)); iterLabel = new JLabel(" "); final Dimension size = iterLabel.getPreferredSize(); iterLabel.setMinimumSize(size); iterLabel.setPreferredSize(size); controls.add(iterLabel); updateImage(); return base; }