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:trendgraph.XYLineChart_AWT.java
public XYLineChart_AWT(int yearStart, int yearEnd, String[] creditUnionName, String columnName) throws SQLException { super("Graph"); super.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.yearStart = yearStart; this.yearEnd = yearEnd; this.creditUnionName = creditUnionName; this.columnName = columnName; saveGraphButton = new JButton("Save Graph"); saveGraphButton.setBorderPainted(false); saveGraphButton.setFocusPainted(false); JFreeChart xylineChart = ChartFactory.createXYLineChart("CU Report", "Year (YYYY)", //X-axis columnName, //Y-axis (replace with columnName createDataset(), PlotOrientation.VERTICAL, true, true, false); ChartPanel chartPanel = new ChartPanel(xylineChart); chartPanel.setPreferredSize(new java.awt.Dimension(1000, 800)); //(x, y) final XYPlot plot = xylineChart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.RED); //can be GREEN, YELLOW, ETC. renderer.setSeriesStroke(0, new BasicStroke(3.0f)); //Font size renderer.setSeriesPaint(1, Color.BLUE); //can be GREEN, YELLOW, ETC. renderer.setSeriesStroke(1, new BasicStroke(3.0f)); //Font size renderer.setSeriesPaint(2, Color.GREEN); //can be GREEN, YELLOW, ETC. renderer.setSeriesStroke(2, new BasicStroke(3.0f)); //Font size renderer.setSeriesPaint(3, Color.yellow); //can be GREEN, YELLOW, ETC. renderer.setSeriesStroke(3, new BasicStroke(3.0f)); //Font size plot.setRenderer(renderer);//w w w . j a v a 2s .c o m chartPanel.setLayout(new FlowLayout(FlowLayout.TRAILING)); chartPanel.add(saveGraphButton); setContentPane(chartPanel); pack(); RefineryUtilities.centerFrameOnScreen(this); setVisible(true); saveGraphButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Rectangle rect = chartPanel.getBounds(); FileChooser chooser = new FileChooser(); //get chosen path and save the variable String path = chooser.getPath(); path = path.replace("\\", "/"); String format = "png"; String fileName = path + "." + format; BufferedImage captureImage = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_ARGB); chartPanel.paint(captureImage.getGraphics()); File file = new File(fileName); try { ImageIO.write(captureImage, format, file); //write data to file } catch (IOException ex) { Logger.getLogger(XYLineChart_AWT.class.getName()).log(Level.SEVERE, null, ex); } } }); }
From source file:ch.epfl.leb.sass.ijplugin.SimulatorStatusFrame.java
/** * Creates a new status frame./*from w w w . ja v a 2 s .co m*/ * * @param groundTruthYLabel The y-axis label for the ground truth signal. * @param analyzerYLabel The units output by the analyzer. * @param setpointYLabel The units of the controller setpoint. * @param outputYLabel The units output by the controller. */ public SimulatorStatusFrame(String groundTruthYLabel, String analyzerYLabel, String setpointYLabel, String outputYLabel) { String seriesLabel = ""; String yLabel = ""; CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new NumberAxis("Simulation Outputs")); Font yLabelFont = new Font("Dialog", Font.PLAIN, 10); datasets = new XYSeriesCollection[4]; for (int i = 0; i < SUBPLOT_COUNT; i++) { switch (i) { case 0: seriesLabel = "True density"; yLabel = groundTruthYLabel; break; case 1: seriesLabel = "Analyzer output"; yLabel = analyzerYLabel; break; case 2: seriesLabel = "Setpoint"; yLabel = setpointYLabel; break; case 3: seriesLabel = "Controller output"; yLabel = outputYLabel; break; } XYSeries timeseries = new XYSeries(seriesLabel); datasets[i] = new XYSeriesCollection(timeseries); NumberAxis numberaxis = new NumberAxis(yLabel); numberaxis.setAutoRangeIncludesZero(false); numberaxis.setNumberFormatOverride(new DecimalFormat("###0.00")); XYPlot xyplot = new XYPlot(datasets[i], null, numberaxis, new StandardXYItemRenderer()); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.getRangeAxis().setLabelFont(yLabelFont); combineddomainxyplot.add(xyplot); } JFreeChart jfreechart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, combineddomainxyplot, true); jfreechart.setBorderPaint(Color.black); jfreechart.setBorderVisible(true); jfreechart.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); ValueAxis valueaxis = combineddomainxyplot.getDomainAxis(); valueaxis.setAutoRange(true); // Number of frames to display valueaxis.setFixedAutoRange(2000D); ChartPanel chartpanel = new ChartPanel(jfreechart); chartpanel.setPreferredSize(new Dimension(800, 500)); chartpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chartpanel.setVisible(true); JPanel jPanel = new JPanel(); jPanel.setLayout(new BorderLayout()); jPanel.add(chartpanel, BorderLayout.NORTH); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); add(jPanel); pack(); setVisible(true); }
From source file:chart.statistic.HistogramChart.java
public ChartPanel createChartPanel() { chart = ChartFactory.createHistogram(mr.getLabel(), null, null, dataset, PlotOrientation.VERTICAL, useLegend, // legende false, false);/*from w w w.j av a2 s . c om*/ chart.getXYPlot().setForegroundAlpha(0.75f); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(widthD, heightD)); return chartPanel; }
From source file:com.ace.capitalflows.ui.frame.chart.NianYdChart.java
/** * A demonstration application showing how to create a simple time series * chart. This example uses monthly data. * * @param title the frame title.//from ww w .j a v a2s. c o m */ public NianYdChart(final String title, final Object[][] dataArray) { super(title); this.dataArray = dataArray; final ChartPanel chartPanel = (ChartPanel) createDemoPanel(); chartPanel.setPreferredSize(new java.awt.Dimension(1000, 600)); setContentPane(chartPanel); }
From source file:intelligentWebAlgorithms.util.gui.ScatterGui.java
/** * @param title/*from w w w .j a v a2 s. co m*/ * chart title * @param nameForData1 * identifier for a data group/series * @param nameForData2 * identifier for a data group/series * @param items * values/categories that correspond to data values */ public ScatterGui(String title, String nameForData1, String nameForData2, String[] items, double[] data1, double[] data2) { super(title); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0, n = items.length; i < n; i++) { dataset.addValue(data1[i], nameForData1, items[i]); dataset.addValue(data2[i], nameForData2, items[i]); } final JFreeChart chart = ChartFactory.createLineChart("User Similarity", "Items", "Rating", dataset, PlotOrientation.VERTICAL, true, true, false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.MarkerDemo1.java
/** * Creates a new instance./*ww w .j a v a 2 s . c o m*/ * * @param title the frame title. */ public MarkerDemo1(final String title) { super(title); final XYDataset data = createDataset(); final JFreeChart chart = createChart(data); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); // chartPanel.setVerticalZoom(true); // chartPanel.setHorizontalZoom(true); setContentPane(chartPanel); }
From source file:org.mc.okapi.PieChart.java
public PieChart(String[] label, double[] value, String applicationTitle, String chartTitle) { super(applicationTitle); // This will create the dataset DefaultPieDataset result = new DefaultPieDataset(); for (int i = 0; i < label.length; i++) { result.setValue(label[i], value[i]); }/*from w ww .j ava 2s . c o m*/ PieDataset dataset = result; // based on the dataset we create the chart JFreeChart chart = ChartFactory.createPieChart3D(chartTitle, // chart title dataset, // data true, // include legend true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); // we put the chart into a panel ChartPanel chartPanel = new ChartPanel(chart); setIconImage(Toolkit.getDefaultToolkit().getImage("images/ico/extra/science_32.png")); // default size chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); // add it to our application setContentPane(chartPanel); }
From source file:LineChart.java
public LineChart(JTable table) { final JFrame frame = new JFrame("jshow Chart"); final JFreeChart chart = createDataset(table); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); chartPanel.setMouseZoomable(true, false); frame.setContentPane(chartPanel);// w w w . j a v a 2 s . com frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setIconImage(Toolkit.getDefaultToolkit() .createImage(LineChart.class.getResource("de/skelton/images/chart.png"))); frame.pack(); frame.setVisible(true); frame.requestFocus(); frame.toFront(); }
From source file:cn.edu.thss.iise.bpmdemo.statistics.actions.ModelReusePanel.java
private JPanel createPanel() throws IOException { createDataSet();/*from w w w. j a v a 2 s . c o m*/ // create the chart... final JFreeChart chart = ChartFactory.createPieChart("Reused Times", // chart // title data1, // dataset false, // include legend true, false); // set the background color for the chart... chart.setBackgroundPaint(new Color(222, 222, 255)); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setCircular(true); plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setNoDataMessage("No data available"); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); String[] columnNames = { "Name", "Reuse Times" }; JTable table = new JTable(data2, columnNames); JPanel panel = new JPanel(); panel.add(chartPanel); panel.add(table); final Rotator rotator = new Rotator(plot); rotator.start(); return panel; }
From source file:netplot.DialPlotPanel.java
public void init() { finalize();//w w w . j ava 2 s. c o m this.dataset1 = new DefaultValueDataset(10.0); this.dataset2 = new DefaultValueDataset(50.0); // get data for diagrams plot = new DialPlot(); plot.setView(0.0, 0.0, 1.0, 1.0); plot.setDataset(0, this.dataset1); plot.setDataset(1, this.dataset2); StandardDialFrame dialFrame = new StandardDialFrame(); dialFrame.setBackgroundPaint(Color.lightGray); dialFrame.setForegroundPaint(Color.darkGray); plot.setDialFrame(dialFrame); GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(170, 170, 220)); DialBackground db = new DialBackground(gp); db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); plot.setBackground(db); DialCap cap = new DialCap(); cap.setRadius(0.10); plot.setCap(cap); chart = new JFreeChart(plot); ChartPanel cp1 = new ChartPanel(chart); cp1.setPreferredSize(new Dimension(400, 400)); add(cp1); }