List of usage examples for org.jfree.chart ChartPanel setPreferredSize
@BeanProperty(preferred = true, description = "The preferred size of the component.") public void setPreferredSize(Dimension preferredSize)
From source file:org.jfree.chart.demo.CombinedTimeSeriesDemo1.java
public static JPanel createDemoPanel() { TimeSeries timeseries = new TimeSeries("Annual"); timeseries.add(new Year(1998), 80D); timeseries.add(new Year(1999), 85D); timeseries.add(new Year(2000), 87.599999999999994D); TimeSeriesCollection dataset1 = new TimeSeriesCollection(timeseries); TimeSeries timeseries1 = new TimeSeries("Monthly A"); timeseries1.add(new Month(7, 2000), 85.799999999999997D); timeseries1.add(new Month(8, 2000), 85.799999999999997D); timeseries1.add(new Month(9, 2000), 85.799999999999997D); timeseries1.add(new Month(10, 2000), 86.5D); timeseries1.add(new Month(11, 2000), 86.5D); timeseries1.add(new Month(12, 2000), 86.5D); timeseries1.add(new Month(1, 2001), 87.700000000000003D); timeseries1.add(new Month(2, 2001), 87.700000000000003D); timeseries1.add(new Month(3, 2001), 87.700000000000003D); timeseries1.add(new Month(4, 2001), 88.5D); timeseries1.add(new Month(5, 2001), 88.5D); timeseries1.add(new Month(6, 2001), 88.5D); timeseries1.add(new Month(7, 2001), 90D); timeseries1.add(new Month(8, 2001), 90D); timeseries1.add(new Month(9, 2001), 90D); timeseries1.add(new Month(10, 2001), 90D); timeseries1.add(new Month(11, 2001), 90D); timeseries1.add(new Month(12, 2001), 90D); timeseries1.add(new Month(1, 2002), 90D); timeseries1.add(new Month(2, 2002), 90D); timeseries1.add(new Month(3, 2002), 90D); timeseries1.add(new Month(4, 2002), 90D); timeseries1.add(new Month(5, 2002), 90D); timeseries1.add(new Month(6, 2002), 90D); TimeSeries timeseries2 = new TimeSeries("Monthly B"); timeseries2.add(new Month(7, 2000), 83.799999999999997D); timeseries2.add(new Month(8, 2000), 83.799999999999997D); timeseries2.add(new Month(9, 2000), 83.799999999999997D); timeseries2.add(new Month(10, 2000), 84.5D); timeseries2.add(new Month(11, 2000), 84.5D); timeseries2.add(new Month(12, 2000), 84.5D); timeseries2.add(new Month(1, 2001), 85.700000000000003D); timeseries2.add(new Month(2, 2001), 85.700000000000003D); timeseries2.add(new Month(3, 2001), 85.700000000000003D); timeseries2.add(new Month(4, 2001), 86.5D); timeseries2.add(new Month(5, 2001), 86.5D); timeseries2.add(new Month(6, 2001), 86.5D); timeseries2.add(new Month(7, 2001), 88D); timeseries2.add(new Month(8, 2001), 88D); timeseries2.add(new Month(9, 2001), 88D); timeseries2.add(new Month(10, 2001), 88D); timeseries2.add(new Month(11, 2001), 88D); timeseries2.add(new Month(12, 2001), 88D); timeseries2.add(new Month(1, 2002), 88D); timeseries2.add(new Month(2, 2002), 88D); timeseries2.add(new Month(3, 2002), 88D); timeseries2.add(new Month(4, 2002), 88D); timeseries2.add(new Month(5, 2002), 88D); timeseries2.add(new Month(6, 2002), 88D); TimeSeriesCollection dataset21 = new TimeSeriesCollection(); dataset21.addSeries(timeseries1);/*w w w . j av a 2s. c om*/ dataset21.addSeries(timeseries2); TimeSeries timeseries3 = new TimeSeries("XXX"); timeseries3.add(new Month(7, 2000), 81.5D); timeseries3.add(new Month(8, 2000), 86D); timeseries3.add(new Month(9, 2000), 82D); timeseries3.add(new Month(10, 2000), 89.5D); timeseries3.add(new Month(11, 2000), 88D); timeseries3.add(new Month(12, 2000), 88D); timeseries3.add(new Month(1, 2001), 90D); timeseries3.add(new Month(2, 2001), 89.5D); timeseries3.add(new Month(3, 2001), 90.200000000000003D); timeseries3.add(new Month(4, 2001), 90.599999999999994D); timeseries3.add(new Month(5, 2001), 87.5D); timeseries3.add(new Month(6, 2001), 91D); timeseries3.add(new Month(7, 2001), 89.700000000000003D); timeseries3.add(new Month(8, 2001), 87D); timeseries3.add(new Month(9, 2001), 91.200000000000003D); timeseries3.add(new Month(10, 2001), 84D); timeseries3.add(new Month(11, 2001), 90D); timeseries3.add(new Month(12, 2001), 92D); TimeSeriesCollection dataset22 = new TimeSeriesCollection(timeseries3); // XYBarRenderer renderer1 = new XYBarRenderer(0.20000000000000001D); renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} ({1}, {2})", new SimpleDateFormat("yyyy"), new DecimalFormat("0.00"))); XYPlot plot1 = new XYPlot(dataset1, new DateAxis("Date"), null, renderer1); // XYAreaRenderer renderer21 = new XYAreaRenderer(); XYPlot plot2 = new XYPlot(dataset21, new DateAxis("Date"), null, renderer21); StandardXYItemRenderer renderer22 = new StandardXYItemRenderer(3); renderer22.setBaseShapesFilled(true); plot2.setDataset(1, dataset22); plot2.setRenderer(1, renderer22); plot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // NumberAxis valueAxis = new NumberAxis("Value"); valueAxis.setAutoRangeIncludesZero(false); CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(valueAxis); combinedPlot.add(plot1, 1); combinedPlot.add(plot2, 4); //chart JFreeChart jfreechart = new JFreeChart("Sample Combined Plot", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot, true); ChartPanel chartpanel = new ChartPanel(jfreechart); chartpanel.setPreferredSize(new Dimension(500, 270)); chartpanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseClicked(ChartMouseEvent chartmouseevent) { System.out.println(chartmouseevent.getEntity()); } public void chartMouseMoved(ChartMouseEvent chartmouseevent) { System.out.println(chartmouseevent.getEntity()); } }); return chartpanel; }
From source file:com.leonarduk.finance.analysis.BuyAndSellSignalsToChart.java
/** * Displays a chart in a frame./* w w w . ja v a2 s . co m*/ * * @param chart * the chart to be displayed */ private static void displayChart(final JFreeChart chart) { // Chart panel final ChartPanel panel = new ChartPanel(chart); panel.setFillZoomRectangle(true); panel.setMouseWheelEnabled(true); panel.setPreferredSize(new Dimension(1024, 400)); // Application frame final ApplicationFrame frame = new ApplicationFrame("Ta4j example - Buy and sell signals to chart"); frame.setContentPane(panel); frame.pack(); RefineryUtilities.centerFrameOnScreen(frame); frame.setVisible(true); }
From source file:org.systemsbiology.mzxmlviewer.utilities.SpectrumComponent.java
public static Component getBPIComponent(ScanHeader[] scanHeaders, ClickListener cl) { XYSeries dataSeries = new XYSeries("TIC"); for (int i = 0; i < scanHeaders.length; i++) dataSeries.add(scanHeaders[i].getDoubleRetentionTime(), scanHeaders[i].getTotIonCurrent()); XYSeriesCollection dataSet = new XYSeriesCollection(dataSeries); JFreeChart BPIChart = ChartFactory.createXYAreaChart(null, "Retention time (s)", "Intensity", dataSet, PlotOrientation.VERTICAL, false, false, false); ChartPanel cPanel = new ChartPanel(BPIChart); cPanel.setPreferredSize(new Dimension(640, 300)); cPanel.addChartMouseListener(new CMListAdapter(cl, scanHeaders)); return cPanel; }
From source file:org.systemsbiology.mzxmlviewer.utilities.SpectrumComponent.java
public static Component getTICComponent(ScanHeader[] scanHeaders, ClickListener cl) { XYSeries dataSeries = new XYSeries("BPI"); for (int i = 0; i < scanHeaders.length; i++) dataSeries.add(scanHeaders[i].getDoubleRetentionTime(), scanHeaders[i].getBasePeakIntensity()); XYSeriesCollection dataSet = new XYSeriesCollection(dataSeries); JFreeChart BPIChart = ChartFactory.createXYAreaChart(null, "Retention time (s)", "Intensity", dataSet, PlotOrientation.VERTICAL, false, false, false); ChartPanel cPanel = new ChartPanel(BPIChart); cPanel.setPreferredSize(new Dimension(640, 300)); cPanel.addChartMouseListener(new CMListAdapter(cl, scanHeaders)); return cPanel; }
From source file:charts.PieChart3D.java
/** * Creates a panel for the chart (used by Superchart.java). * * @return A panel./*w w w . j a v a2 s . com*/ */ public static JPanel createchartPanel(PieChartModel model) { JFreeChart chart = createChart(createDataset(model), model); chart.setPadding(new RectangleInsets(20, 8, 2, 2)); ChartPanel panel = new ChartPanel(chart); panel.setMouseWheelEnabled(true); panel.setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize()); return panel; }
From source file:max.hubbard.Factoring.Graphing.java
public static void graph(String equation) { LinkedList<LinkedHashMap<Float, Integer>> list = Separate.separate(equation); XYDataset set = createDataset(list, equation); final JFreeChart chart = createChart(set, equation); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setVisible(true);/*from w ww . j av a 2 s . c o m*/ chartPanel.setDomainZoomable(true); chartPanel.setRangeZoomable(true); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(new java.awt.Dimension(Main.label.getWidth(), Main.label.getHeight())); Main.getPanel().removeAll(); Main.getPanel().updateUI(); Main.getPanel().add(chartPanel, BorderLayout.CENTER); Main.getPanel().add(Interface.box, BorderLayout.EAST); Main.getFrame().pack(); }
From source file:lu.lippmann.cdb.weka.SilhouetteUtil.java
/** * //from w w w.j av a2s . c o m * @param sils * @return */ public static JPanel buildSilhouettePanel(final Instances ds, final WekaClusteringResult result) { final Map<Integer, List<Double>> sils = computeSilhouette(ds, result); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); final JFreeChart chart = ChartFactory.createBarChart("Silhouette", "Category", "Value", dataset, PlotOrientation.HORIZONTAL, true, true, false); int nbClass = sils.keySet().size(); int id = 0; double minValue = 0; int counter[][] = new int[nbClass][4]; for (int i = 0; i < nbClass; i++) { final double[] tree = ArrayUtils.toPrimitive(sils.get(i).toArray(new Double[0])); for (double val : tree) { if (val > 0.75) { dataset.addValue(val, "Cluster " + i + " ++", "" + id); counter[i][0]++; } else if (val > 0.50) { dataset.addValue(val, "Cluster " + i + " +", "" + id); counter[i][1]++; } else if (val > 0.25) { dataset.addValue(val, "Cluster " + i + " =", "" + id); counter[i][2]++; } else { dataset.addValue(val, "Cluster " + i + " -", "" + id); counter[i][3]++; } if (val < minValue) { minValue = val; } id++; } } final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); categoryplot.setBackgroundPaint(Color.WHITE); categoryplot.getDomainAxis().setVisible(false); categoryplot.setDomainGridlinesVisible(false); categoryplot.setRangeGridlinesVisible(false); categoryplot.getRangeAxis().setRange(minValue, 1.0); //Add line markers ValueMarker target = new ValueMarker(0.75); target.setPaint(Color.BLACK); target.setLabel(" ++"); target.setLabelAnchor(RectangleAnchor.TOP_LEFT); target.setLabelTextAnchor(TextAnchor.TOP_LEFT); categoryplot.addRangeMarker(target); target = new ValueMarker(0.5); target.setPaint(Color.BLACK); target.setLabel(" +"); target.setLabelAnchor(RectangleAnchor.TOP_LEFT); target.setLabelTextAnchor(TextAnchor.TOP_LEFT); categoryplot.addRangeMarker(target); target = new ValueMarker(0.25); target.setPaint(Color.BLACK); target.setLabel(" ="); target.setLabelAnchor(RectangleAnchor.TOP_LEFT); target.setLabelTextAnchor(TextAnchor.TOP_LEFT); categoryplot.addRangeMarker(target); target = new ValueMarker(0); target.setPaint(Color.BLACK); target.setLabel(" -"); target.setLabelAnchor(RectangleAnchor.TOP_LEFT); target.setLabelTextAnchor(TextAnchor.TOP_LEFT); categoryplot.addRangeMarker(target); //Remove visual effects on bar final BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setBarPainter(new StandardBarPainter()); //set bar colors int p = 0; final int max = ColorHelper.COLORBREWER_SEQUENTIAL_PALETTES.size(); for (int i = 0; i < nbClass; i++) { final Color[] color = new ArrayList<Color[]>(ColorHelper.COLORBREWER_SEQUENTIAL_PALETTES.values()) .get((max - i) % max); final int nbColors = color.length; for (int k = 0; k < counter[i].length; k++) { if (counter[i][k] > 0) barrenderer.setSeriesPaint(p++, color[(nbColors - k - 3) % nbColors]); } } //remove blank line between bars barrenderer.setItemMargin(-dataset.getRowCount()); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(new Dimension(1200, 900)); chartPanel.setBorder(new TitledBorder("Silhouette plot")); chartPanel.setBackground(Color.WHITE); chart.setTitle(""); return chartPanel; }
From source file:unalcol.termites.boxplots.SucessfulRatesGlobal.java
private static JFreeChart createChart(CategoryDataset categorydataset, ArrayList<Double> pf) { JFreeChart jfreechart = ChartFactory.createBarChart("Success Rates - " + getTitle(pf), "", "", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.getTitle().setFont(new Font("Sans-Serif", Font.PLAIN, 18)); jfreechart.setBackgroundPaint(new Color(221, 223, 238)); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setRangeGridlinePaint(Color.gray); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); BarRenderer renderer = (BarRenderer) categoryplot.getRenderer(); //categoryplot.setBackgroundPaint(new Color(221, 223, 238)); renderer.setSeriesPaint(0, new Color(130, 165, 70)); renderer.setSeriesPaint(1, new Color(220, 165, 70)); renderer.setSeriesPaint(4, new Color(255, 165, 70)); renderer.setDrawBarOutline(false);//from ww w . ja v a2s. c o m renderer.setShadowVisible(false); // renderer.setMaximumBarWidth(1); renderer.setGradientPaintTransformer(null); renderer.setDefaultBarPainter(new StandardBarPainter()); categoryplot.setRenderer(renderer); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setUpperMargin(0.25D); CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer(); categoryitemrenderer.setBaseItemLabelsVisible(true); categoryitemrenderer.setBaseItemLabelGenerator(new LabelGenerator(null)); numberaxis.setRange(0, 100); //numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); Font font = new Font("SansSerif", Font.ROMAN_BASELINE, 12); numberaxis.setTickLabelFont(font); CategoryAxis axisd = categoryplot.getDomainAxis(); ValueAxis axisr = categoryplot.getRangeAxis(); axisd.setTickLabelFont(font); axisr.setTickLabelFont(font); final ChartPanel chartPanel = new ChartPanel(jfreechart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); FileOutputStream output; try { output = new FileOutputStream("successGlobalRates" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, jfreechart, 650, 370, null); } catch (FileNotFoundException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } return jfreechart; }
From source file:dumbara.view.Chart1.java
public static void ViewLineChart(String[] agencyID, String[] sslesDate, ArrayList<String[]> arrayList) throws SQLException, ClassNotFoundException { XYSeries series1 = new XYSeries("Agency 1"); XYSeries series2 = new XYSeries("Agency 2"); XYSeries series3 = new XYSeries("Agency 3"); XYSeries series4 = new XYSeries("Agency 4"); for (String[] strings : arrayList) { for (int i = 0; i < sslesDate.length; i++) { System.out.println(sslesDate[i].split("-")[1] + ""); series1.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""), Double.parseDouble(arrayList.get(0)[i])); }// ww w . jav a2 s. c o m for (int i = 0; i < sslesDate.length; i++) { series2.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""), Double.parseDouble(arrayList.get(1)[i])); } for (int i = 0; i < sslesDate.length; i++) { series3.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""), Double.parseDouble(arrayList.get(2)[i])); } for (int i = 0; i < sslesDate.length; i++) { series4.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""), Double.parseDouble(arrayList.get(3)[i])); } } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); dataset.addSeries(series3); dataset.addSeries(series4); XYDataset dataset1 = dataset; JFreeChart chart = ChartFactory.createXYLineChart("", "Test Id", "Average Marks", dataset1, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesLinesVisible(1, true); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(2, true); renderer.setSeriesShapesVisible(2, true); renderer.setSeriesFillPaint(2, Color.MAGENTA); plot.setRenderer(renderer); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 300)); //(chartPanel); ChartFrame frame = new ChartFrame("Dumbara Water Management System", chart); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); }
From source file:unalcol.termites.boxplots.SucessfulRatesHybrid.java
private static JFreeChart createChart(CategoryDataset categorydataset, ArrayList<Double> pf) { JFreeChart jfreechart = ChartFactory.createBarChart("Success Rates - " + getTitle(pf), "", "", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.getTitle().setFont(new Font("Sans-Serif", Font.PLAIN, 18)); jfreechart.setBackgroundPaint(new Color(221, 223, 238)); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setRangeGridlinePaint(Color.gray); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); BarRenderer renderer = (BarRenderer) categoryplot.getRenderer(); //categoryplot.setBackgroundPaint(new Color(221, 223, 238)); renderer.setSeriesPaint(0, new Color(130, 165, 70)); renderer.setSeriesPaint(1, new Color(220, 165, 70)); renderer.setSeriesPaint(4, new Color(255, 165, 70)); renderer.setDrawBarOutline(false);// w ww . j av a2 s .c o m renderer.setShadowVisible(false); // renderer.setMaximumBarWidth(1); renderer.setGradientPaintTransformer(null); renderer.setDefaultBarPainter(new StandardBarPainter()); categoryplot.setRenderer(renderer); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setUpperMargin(0.25D); CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer(); categoryitemrenderer.setBaseItemLabelsVisible(true); categoryitemrenderer.setBaseItemLabelGenerator(new LabelGenerator(null)); numberaxis.setRange(0, 100); //numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); Font font = new Font("SansSerif", Font.ROMAN_BASELINE, 12); numberaxis.setTickLabelFont(font); CategoryAxis axisd = categoryplot.getDomainAxis(); ValueAxis axisr = categoryplot.getRangeAxis(); axisd.setTickLabelFont(font); axisr.setTickLabelFont(font); axisd.setMaximumCategoryLabelLines(5); final ChartPanel chartPanel = new ChartPanel(jfreechart); chartPanel.setPreferredSize(new java.awt.Dimension(1300, 370)); FileOutputStream output; try { output = new FileOutputStream("sucessrates1" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, jfreechart, 1300, 370, null); } catch (FileNotFoundException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } return jfreechart; }