List of usage examples for org.jfree.chart.axis NumberAxis createIntegerTickUnits
public static TickUnitSource createIntegerTickUnits()
From source file:com.kurvlrgui.gui.ChartPanel.java
/** * Creates new form ChartPanel// www .j a va 2 s. c o m */ public ChartPanel(String title, NumericData s1, NumericData s2) { initComponents(); calculated = new XYSeries("Calculated"); for (NumericPair np : s1.values) { calculated.add(np.x, np.y); } observed = null; if (s2 != null) { observed = new XYSeries("Observed"); for (NumericPair np : s2.values) { observed.add(np.x, np.y); } } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(calculated); if (s2 != null) dataset.addSeries(observed); JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesLinesVisible(1, false); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); panel = new org.jfree.chart.ChartPanel(chart); panel.setHorizontalAxisTrace(true); panel.setVerticalAxisTrace(true); this.add(panel); }
From source file:org.jfree.chart.demo.StackedAreaChartDemo1.java
public static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createStackedAreaChart("Stacked Area Chart", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setForegroundAlpha(0.85F); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setLowerMargin(0.0D);/*from w w w . j a v a2s.c om*/ categoryaxis.setUpperMargin(0.0D); categoryaxis.setCategoryMargin(0.0D); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer(); categoryitemrenderer.setBaseItemLabelsVisible(true); return jfreechart; }
From source file:utils.Graficos_old.java
public static JFreeChart GraficoLinhas(List<CarCapContas> pagar, List<CarCapContas> receber, String titulo) { XYSeries series1 = new XYSeries("Pagar"); // CarCapContas contasPagar = new CarCapContas(); for (CarCapContas contasPagar : pagar) { series1.add(contasPagar.getContaValorTotal(), contasPagar.getContaDataEmissao().getMonth()); }//from w w w .j a v a 2 s .c om XYSeries series2 = new XYSeries("Receber"); for (CarCapContas contasReceber : receber) { series2.add(contasReceber.getContaValorTotal(), contasReceber.getContaDataEmissao().getMonth()); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); JFreeChart chart = ChartFactory.createXYLineChart(titulo, // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:com.etest.view.tq.charts.SubjectTestLineChart.java
public static JFreeChart difficultIndex(int tqCoverageId) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (CellItem ci : CellItemDAO.getItemAnalysisResult(tqCoverageId)) { dataset.setValue((int) (ci.getDifficultIndex() * 100), "Difficulty Index", String.valueOf(ci.getItemNo())); }// w ww. j av a2s.c o m JFreeChart chart = ChartFactory.createLineChart("Item Analysis Report", "Item No.", "Difficulty Index (%)", dataset, PlotOrientation.VERTICAL, true, true, false); 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.setShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setFillPaint(Color.white); return chart; }
From source file:org.jfree.chart.demo.DeviationRendererDemo3.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart chart = ChartFactory.createXYLineChart("DeviationRenderer - Demo 3", "X", "Y", xydataset, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); ////from ww w .j ava2s.co m DeviationRenderer renderer = new DeviationRenderer(false, false); renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); renderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1)); renderer.setSeriesFillPaint(0, Color.red); renderer.setSeriesFillPaint(1, Color.orange); renderer.setSeriesFillPaint(2, Color.green); plot.setRenderer(renderer); // DateAxis domainAxis = new DateAxis("Date"); domainAxis.setLowerMargin(0.0D); domainAxis.setUpperMargin(0.0D); plot.setDomainAxis(domainAxis); NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis(); valueAxis.setRange(-40D, 40D); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ChartUtilities.applyCurrentTheme(chart); return chart; }
From source file:net.sf.profiler4j.console.MemoryPlotPanel.java
public MemoryPlotPanel(int maxAge, String title) { super(new BorderLayout()); totalSeries = new TimeSeries("Committed Memory", Millisecond.class); totalSeries.setMaximumItemAge(maxAge); usedSeries = new TimeSeries("Used Memory", Millisecond.class); usedSeries.setMaximumItemAge(maxAge); TimeSeriesCollection seriesCollection = new TimeSeriesCollection(); seriesCollection.addSeries(totalSeries); seriesCollection.addSeries(usedSeries); NumberAxis numberAxis = new NumberAxis("Memory (KB)"); numberAxis.setLabelFont(new Font("SansSerif", 0, 14)); numberAxis.setTickLabelFont(new Font("SansSerif", 0, 12)); numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); DateAxis dateAxis = new DateAxis("Time"); dateAxis.setTickLabelFont(new Font("SansSerif", 0, 12)); dateAxis.setLabelFont(new Font("SansSerif", 0, 14)); dateAxis.setAutoRange(true);/* w w w . j a v a2 s. c om*/ dateAxis.setLowerMargin(0); dateAxis.setUpperMargin(0); dateAxis.setTickLabelsVisible(true); dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); lineRenderer.setSeriesPaint(0, Color.RED); lineRenderer.setSeriesPaint(1, Color.GREEN.darker()); lineRenderer.setStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer); xyplot.setBackgroundPaint(Color.WHITE); xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.PLAIN, 14), xyplot, true); chart.setBackgroundPaint(Color.white); ChartPanel panel = new ChartPanel(chart); panel.setBorder(createCompoundBorder(createEmptyBorder(8, 8, 8, 8), createLineBorder(Color.LIGHT_GRAY))); add(panel); setBorder(createEmptyBorder(8, 8, 8, 8)); }
From source file:org.codehaus.mojo.chronos.chart.ChartUtil.java
public static XYPlot setupXYPlot(JFreeChart chart, DateFormat dateFormat) { XYPlot plot = chart.getXYPlot();/* ww w .j av a2 s . co m*/ DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(dateFormat); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return plot; }
From source file:loadmaprenderer.ChartTest.java
private JFreeChart makeChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createXYLineChart("Cost/Year Chart", "Year", "Cost", dataset, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = chart.getXYPlot();//w w w . j a va 2s.co m plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLUE); plot.setRangeGridlinePaint(Color.BLUE); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRange(rootPaneCheckingEnabled); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(rootPaneCheckingEnabled); return chart; }
From source file:org.gephi.statistics.plugin.ChartUtils.java
public static void scaleChart(JFreeChart chart, XYSeries dSeries, boolean normalized) { XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(1.0);// www . jav a 2 s.c om domainAxis.setUpperMargin(1.0); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (normalized) { domainAxis.setRange(-0.05, 1.05); } else { domainAxis.setRange(dSeries.getMinX() - 1, dSeries.getMaxX() + 1); } NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(-0.1 * Math.sqrt(dSeries.getMaxY()), dSeries.getMaxY() + 0.1 * Math.sqrt(dSeries.getMaxY())); }
From source file:org.jenkinsci.plugins.todos.TodosChartBuilder.java
/** * Build a trend chart from the provided data. * /*from www .j av a 2s. c om*/ * @param action * the build action * @return the trend chart */ public static JFreeChart buildChart(TodosBuildAction action) { String strComments = Messages.Todos_ReportSummary_Comments(); JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, strComments, buildDataset(action), PlotOrientation.VERTICAL, true, false, true); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); 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); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); TodosAreaRenderer renderer = new TodosAreaRenderer(action.getUrlName()); plot.setRenderer(renderer); return chart; }