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.CyclicXYPlotDemo.java
/** * A demonstration application showing an XY plot, with a cyclic axis and renderer * * @param title the frame title./*from w w w .j a v a 2 s.c o m*/ */ public CyclicXYPlotDemo(final String title) { super(title); this.series = new XYSeries("Random Data"); this.series.setMaximumItemCount(50); // Only 50 items are visible at the same time. // Keep more as a mean to test this. final XYSeriesCollection data = new XYSeriesCollection(this.series); final JFreeChart chart = ChartFactory.createXYLineChart("Cyclic XY Plot Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = chart.getXYPlot(); plot.setDomainAxis(new CyclicNumberAxis(10, 0)); plot.setRenderer(new CyclicXYItemRenderer()); final NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); axis.setAutoRangeMinimumSize(1.0); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(400, 300)); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel, BorderLayout.CENTER); final JButton button1 = new JButton("Start"); button1.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { timer.start(); } }); final JButton button2 = new JButton("Stop"); button2.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { timer.stop(); } }); final JButton button3 = new JButton("Step by step"); button3.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { CyclicXYPlotDemo.this.actionPerformed(null); } }); final JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); buttonPanel.add(button3); content.add(buttonPanel, BorderLayout.SOUTH); setContentPane(content); this.timer = new Timer(200, this); }
From source file:org.jfree.chart.demo.GanttDemo1.java
/** * Creates a new demo./* w ww. ja va 2 s.co m*/ * * @param title the frame title. */ public GanttDemo1(final String title) { super(title); final IntervalCategoryDataset dataset = createDataset(); final JFreeChart chart = createChart(dataset); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.MultiplePieChartDemo4.java
/** * Creates a new demo./* w w w . java 2 s . c om*/ * * @param title the frame title. */ public MultiplePieChartDemo4(final String title) { super(title); final CategoryDataset dataset = createDataset(); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart, true, true, true, false, true); chartPanel.setPreferredSize(new java.awt.Dimension(600, 380)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.EventFrequencyDemo.java
/** * Creates a new demo./*ww w . ja v a 2 s .com*/ * * @param title the frame title. */ public EventFrequencyDemo(final String title) { super(title); // create a dataset... final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // initialise the data... final Day d1 = new Day(12, SerialDate.JUNE, 2002); final Day d2 = new Day(14, SerialDate.JUNE, 2002); final Day d3 = new Day(15, SerialDate.JUNE, 2002); final Day d4 = new Day(10, SerialDate.JULY, 2002); final Day d5 = new Day(20, SerialDate.JULY, 2002); final Day d6 = new Day(22, SerialDate.AUGUST, 2002); dataset.setValue(new Long(d1.getMiddleMillisecond()), "Series 1", "Requirement 1"); dataset.setValue(new Long(d1.getMiddleMillisecond()), "Series 1", "Requirement 2"); dataset.setValue(new Long(d2.getMiddleMillisecond()), "Series 1", "Requirement 3"); dataset.setValue(new Long(d3.getMiddleMillisecond()), "Series 2", "Requirement 1"); dataset.setValue(new Long(d4.getMiddleMillisecond()), "Series 2", "Requirement 3"); dataset.setValue(new Long(d5.getMiddleMillisecond()), "Series 3", "Requirement 2"); dataset.setValue(new Long(d6.getMiddleMillisecond()), "Series 1", "Requirement 4"); // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Event Frequency Demo", // title "Category", // domain axis label "Value", // range axis label dataset, // dataset PlotOrientation.HORIZONTAL, // orientation true, // include legend true, // tooltips false // URLs ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(new Color(0xFF, 0xFF, 0xCC)); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); // plot.getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f); plot.setRangeAxis(new DateAxis("Date")); final CategoryToolTipGenerator toolTipGenerator = new StandardCategoryToolTipGenerator("", DateFormat.getDateInstance()); // final CategoryItemRenderer renderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES); // renderer.setToolTipGenerator(toolTipGenerator); // plot.setRenderer(renderer); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // OPTIONAL CUSTOMISATION COMPLETED. // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:se.backede.jeconomix.forms.report.TransactionsTotalReport.java
public void addLineChart(Map<String, List<TransactionReportDto>> reports) { JFreeChart lineChart = ChartFactory.createLineChart("Total", "Month", "Kronor", ReportUtils.createDataset(reports, Boolean.FALSE), PlotOrientation.VERTICAL, true, true, true); ChartPanel chartPanel = new ChartPanel(lineChart); chartPanel.setPreferredSize(new java.awt.Dimension(lineChartPanel.getWidth(), lineChartPanel.getHeight())); lineChartPanel.setLayout(new BorderLayout()); lineChartPanel.add(chartPanel, BorderLayout.NORTH); }
From source file:com.chris.brkopani.gui.analytics.Graph.java
public void createAndShowGui(JDesktopPane desk) throws SQLException { //? tabed pane ? WebLookAndFeel.install();/*from w ww . j av a 2s . c o m*/ frame = new JInternalFrame("PieChart", true, true, true, true); frame.setFrameIcon(new ImageIcon("res/br.png")); frame.setBounds(530, 5, 520, 350); frame.getContentPane().getBackground(); // This will create the dataset PieDataset dataset = createDataset(); // based on the dataset we create the chart JFreeChart chart = createChart(dataset, "PieChart"); // we put the chart into a panel ChartPanel chartPanel = new ChartPanel(chart); chart.setBackgroundPaint(Color.GRAY); // default size chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); // add it to our application frame.add(chartPanel); frame.setVisible(true); desk.add(frame); }
From source file:org.interpss.chart.dstab.SimpleOneStateChart.java
/** * create the chart based on the data attributes * /*from w w w. jav a2 s .co m*/ */ public void createChart() { final JFreeChart chart = ChartFactory.createXYLineChart(plotTitle, xLabel, yLabel, createXYDataSet(xDataAry, yDataAry, yDataLabel), PlotOrientation.VERTICAL, true, false, false); final XYPlot plot = (XYPlot) chart.getPlot(); final StandardXYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(renderer); //NumberAxis axis_x = (NumberAxis) plot.getDomainAxis(); //axis_x.setRangeAboutValue(12.0, 24.0); final NumberAxis axisLeft = (NumberAxis) plot.getRangeAxis(); axisLeft.setAutoRangeIncludesZero(false); axisLeft.setAutoRangeMinimumSize(autoRangeMinimumSize); final XYItemRenderer v_renderer = plot.getRenderer(0); v_renderer.setSeriesPaint(0, yColor); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(Chart_Width, Chart_Height)); setContentPane(chartPanel); }
From source file:lab10part2.Chart.java
/** * Creates new form chart// w w w . j a v a 2s . co m * * @param title the frame title. */ private Chart(final String title) { super(title); initComponents(); final CategoryDataset dataset = createDataset(); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(500, 270)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.ParetoChartDemo.java
/** * Creates a new demo instance.//from w ww . j a va 2s. co m * * @param title the frame title. */ public ParetoChartDemo(final String title) { super(title); final DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("C", new Integer(4843)); data.addValue("C++", new Integer(2098)); data.addValue("C#", new Integer(26)); data.addValue("Java", new Integer(1901)); data.addValue("Perl", new Integer(2507)); data.addValue("PHP", new Integer(1689)); data.addValue("Python", new Integer(948)); data.addValue("Ruby", new Integer(100)); data.addValue("SQL", new Integer(263)); data.addValue("Unix Shell", new Integer(485)); data.sortByValues(SortOrder.DESCENDING); final KeyedValues cumulative = DataUtilities.getCumulativePercentages(data); final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Languages", data); // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Freshmeat Software Projects", // chart title "Language", // domain axis label "Projects", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.addSubtitle(new TextTitle("By Programming Language")); chart.addSubtitle(new TextTitle("As at 5 March 2003")); // set the background color for the chart... chart.setBackgroundPaint(new Color(0xBBBBDD)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); final CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative", cumulative); final NumberAxis axis2 = new NumberAxis("Percent"); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); // OPTIONAL CUSTOMISATION COMPLETED. // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(550, 270)); setContentPane(chartPanel); }
From source file:org.jfree.experimental.chart.demo.XYTitleAnnotationDemo1.java
/** * A demonstration application showing how to create a simple time series * chart. This example uses monthly data. * * @param title the frame title./*w ww .j a v a2 s . c om*/ */ public XYTitleAnnotationDemo1(String title) { super(title); ChartPanel chartPanel = (ChartPanel) createDemoPanel(); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); chartPanel.setMouseZoomable(true, false); setContentPane(chartPanel); }