List of usage examples for org.jfree.chart.axis NumberAxis createIntegerTickUnits
public static TickUnitSource createIntegerTickUnits()
From source file:hudson.plugins.codeviation.MetricsAction.java
private JFreeChart createChart(CategoryDataset dataset, int maxVal) { final JFreeChart chart = ChartFactory.createLineChart(null, // chart title null, // unused "count", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls );//from w ww .j a va 2s . co m // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... final LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(maxVal); rangeAxis.setLowerBound(0); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setStroke(new BasicStroke(4.0f)); // crop extra space around the graph plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); return chart; }
From source file:org.jfree.chart.demo.ParetoChartDemo.java
/** * Creates a new demo instance./*from w w w. j a v a 2 s . c o 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:com.googlecode.logVisualizer.chart.turnrundownGantt.GanttChartBuilder.java
private JFreeChart createChart(final SlidingGanttCategoryDataset dataset) { this.dataset = dataset; final JFreeChart chart = ChartFactory.createGanttChart(getTitle(), null, null, dataset, false, true, false); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); final CategoryItemRenderer renderer = plot.getRenderer(); plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(0.15f); plot.setRangeAxis(new FixedZoomNumberAxis()); plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getRangeAxis().setAutoRange(false); plot.setRangeGridlinePaint(Color.black); setBarShadowVisible(chart, false);/*from w ww. j a v a 2 s.com*/ for (final AreaInterval ai : ((TurnRundownDataset) dataset.getUnderlyingDataset()).getDataset()) if (lastTurnNumber < ai.getEndTurn()) lastTurnNumber = ai.getEndTurn(); addDayMarkers(plot); addLevelMarkers(plot); addFamiliarMarkers(plot); plot.getRangeAxis().setUpperBound(lastTurnNumber + 10); renderer.setSeriesPaint(0, Color.red); renderer.setBaseToolTipGenerator( new IntervalCategoryToolTipGenerator("{1}, {3} - {4}", NumberFormat.getInstance())); return chart; }
From source file:sim.app.sugarscape.Charts.java
JFreeChart createChart4() { JFreeChart chart4 = ChartFactory.createHistogram("Wealth Distribution", "Wealth", "Count", model.dataset, PlotOrientation.VERTICAL, true, true, false); model.chart4 = chart4;/*from w ww . j ava2 s . co m*/ NumberAxis rangeAxis1 = new NumberAxis("Wealth"); rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); org.jfree.chart.axis.NumberAxis domainAxis = new NumberAxis("Bins"); XYPlot plot = chart4.getXYPlot(); XYItemRenderer renderer1 = plot.getRenderer(); renderer1.setSeriesPaint(0, Color.MAGENTA); return chart4; }
From source file:com.twocents.report.charts.BarChartDemo1.java
/** * Creates a sample chart./*from ww w . j av a2 s. com*/ * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 1", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // 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(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:gui.BarChart.java
/** * Zusammenbauen des Diagrammes.//from w w w . j av a 2 s . c om * * @return diagramm */ private JFreeChart createChart() { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("", // berschrift label_x_axis, // x label label_y_axis, // y label dataset, // datenstze PlotOrientation.VERTICAL, // vertikale balken true, // mit legende true, // mit tooltips false // URLs??? ); // Layoutanpassungen im Folgende: // allg. Hintergrundfarbe chart.setBackgroundPaint(Color.white); // Referenz auf Zeichnung: final CategoryPlot plot = chart.getCategoryPlot(); plot.setNoDataMessage("NO DATA!"); // aussehen des eigentlichen diagrammes: plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); // skaleneinteilung: final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.1); // kategorien renderer einstellungen verndern: final CategoryItemRenderer categories = plot.getRenderer(); // casten in bar renderer: final BarRenderer bars = (BarRenderer) categories; // werte im diagramm anzeigen: categories.setLabelGenerator(new StandardCategoryLabelGenerator()); categories.setItemLabelsVisible(true); final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER, TextAnchor.CENTER, -Math.PI / 6); categories.setPositiveItemLabelPosition(p); categories.setNegativeItemLabelPosition(p); plot.setRenderer(categories); // farbverlauf der serien 1 und 2 final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, new Color(127, 127, 255), 0.0f, 0.0f, new Color(127, 127, 127)); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, new Color(255, 127, 127), 0.0f, 0.0f, new Color(127, 127, 127)); bars.setSeriesPaint(0, gp0); bars.setSeriesPaint(1, gp1); // keine umrandung der balken bars.setDrawBarOutline(false); // abstand der zahlen vom balken bars.setItemLabelAnchorOffset(13); // x achsenbeschriftung final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
From source file:com.opensourcestrategies.financials.reports.JFreeFinancialCharts.java
/** * Liquidity snapshot chart. Documentation is at http://www.opentaps.org/docs/index.php/Financials_Home_Screen * * Because a user might not have permission to view balances in all areas, this method takes into consideration * the ability to view various bars in the chart. * * @param accountsMap Map of accounts keyed by the glAccountType * @return String filename pointing to the chart, to be used with showChart URI request *///from w w w. j a va2s . c o m public static String createLiquiditySnapshotChart(Map<String, GenericValue> accountsMap, List<GenericValue> creditCardAccounts, Locale locale, boolean hasReceivablesPermission, boolean hasPayablesPermission, boolean hasInventoryPermission) throws GenericEntityException, IOException { Map<String, Object> uiLabelMap = UtilMessage.getUiLabels(locale); // create the dataset DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // compile the four bars if (hasReceivablesPermission) { double cashBalance = 0.0; cashBalance += getPostedBalance(accountsMap.get("UNDEPOSITED_RECEIPTS")); cashBalance += getPostedBalance(accountsMap.get("BANK_STLMNT_ACCOUNT")); dataset.addValue(cashBalance, "", (String) uiLabelMap.get("FinancialsCashEquivalents")); double receivablesBalance = 0.0; receivablesBalance += getPostedBalance(accountsMap.get("ACCOUNTS_RECEIVABLE")); // merchant account settlement balances are receivable receivablesBalance += getPostedBalance(accountsMap.get("MRCH_STLMNT_ACCOUNT")); dataset.addValue(receivablesBalance, "", (String) uiLabelMap.get("FinancialsReceivables")); } if (hasInventoryPermission) { double inventoryBalance = 0.0; inventoryBalance += getPostedBalance(accountsMap.get("INVENTORY_ACCOUNT")); inventoryBalance += getPostedBalance(accountsMap.get("RAWMAT_INVENTORY")); inventoryBalance += getPostedBalance(accountsMap.get("WIP_INVENTORY")); dataset.addValue(inventoryBalance, "", (String) uiLabelMap.get("WarehouseInventory")); } if (hasPayablesPermission) { double payablesBalance = 0.0; payablesBalance += getPostedBalance(accountsMap.get("ACCOUNTS_PAYABLE")); payablesBalance += getPostedBalance(accountsMap.get("COMMISSIONS_PAYABLE")); payablesBalance += getPostedBalance(accountsMap.get("UNINVOICED_SHIP_RCPT")); dataset.addValue(payablesBalance, "", (String) uiLabelMap.get("FinancialsPayables")); } // set up the chart JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("FinancialsLiquiditySnapshot"), // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // get the bar renderer to put effects on the bars final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // disable bar outlines // set up gradient paint on bar final GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.GREEN, 0.0f, 0.0f, Color.GRAY); renderer.setSeriesPaint(0, gp); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // tilt the category labels so they fit CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // save as a png and return the file name return ServletUtilities.saveChartAsPNG(chart, 400, 300, null); }
From source file:lab10part2.Chart.java
private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );// w w w .j a va 2s.c om // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.LineChartDemo1a.java
/** * Creates a sample chart./*w w w. j av a 2 s . co m*/ * * @param dataset a dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation !legendPanelOn, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // customise the renderer... LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.white); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); setCategorySummary(dataset); return chart; }
From source file:fungus.PeerRatioChartFrame.java
public PeerRatioChartFrame(String prefix) { simulationCycles = Configuration.getDouble(PAR_SIMULATION_CYCLES); this.setTitle("MycoNet Statistics Chart"); graph = JungGraphObserver.getGraph(); //data.add(-1,0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.setAutoWidth(false);// w w w . j ava 2 s. c om dataset.setIntervalWidth(simulationCycles); //averageUtilizationData = new XYSeries("Average Utilization"); //dataset.addSeries(averageUtilizationData); //averageStableUtilizationData = new XYSeries("Avg Stable Util"); //dataset.addSeries(averageStableUtilizationData); bulwarkRatioData = new XYSeries("Bulwark Ratio"); dataset.addSeries(bulwarkRatioData); biomassRatioData = new XYSeries("Biomass Ratio"); dataset.addSeries(biomassRatioData); hyphaRatioData = new XYSeries("Hypha Ratio"); dataset.addSeries(hyphaRatioData); // stableHyphaRatioData = new XYSeries("Stable Hypha Ratio"); // dataset.addSeries(stableHyphaRatioData); //XYSeriesCollection dataset; JFreeChart peerRatioChart = ChartFactory.createXYLineChart("Bulwark Metrics", "Cycle", "Peer State Ratio", dataset, PlotOrientation.VERTICAL, true, false, false); ChartPanel peerRatioChartPanel = new ChartPanel(peerRatioChart); XYPlot xyplot = peerRatioChart.getXYPlot(); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setRange(0, 1); //chart.setBackgroundPaint(Color.white); //XYPlot plot = chart.getXYPlot(); // BufferedImage chartImage = chart.createBufferedImage(500,300); // chartLabel = new JLabel(); //chartLabel.setIcon(new ImageIcon(chartImage)); Container contentPane = getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); JPanel labelPane = new JPanel(); labelPane.setLayout(new GridLayout(1, 1)); //chartPane.setPreferredSize(new java.awt.Dimension(500, 300)); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); ////contentPane.add(labelPane,BorderLayout.PAGE_START); //contentPane.add(Box.createRigidArea(new Dimension(0,5))); contentPane.add(peerRatioChartPanel, BorderLayout.CENTER); //contentPane.add(Box.createRigidArea(new Dimension(0,5))); ////contentPane.add(buttonPane, BorderLayout.PAGE_END); //data = node.getHyphaData(); //link = node.getHyphaLink(); //mycocast = node.getMycoCast(); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //chartPanel.add(chartLabel); /*JButton updateButton = new JButton("Refresh"); ActionListener updater = new ActionListener() { public void actionPerformed(ActionEvent e) { refreshData(); } }; updateButton.addActionListener(updater); JButton closeButton = new JButton("Close"); ActionListener closer = new ActionListener() { public void actionPerformed(ActionEvent e) { closeFrame(); } }; closeButton.addActionListener(closer); buttonPane.add(Box.createHorizontalGlue()); buttonPane.add(updateButton); buttonPane.add(Box.createRigidArea(new Dimension(5,0))); buttonPane.add(closeButton); refreshData(); */ //JungGraphObserver.addChangeListener(this); this.pack(); this.setVisible(true); }