List of usage examples for org.jfree.chart.axis NumberAxis createIntegerTickUnits
public static TickUnitSource createIntegerTickUnits()
From source file:org.codehaus.mojo.dashboard.report.plugin.chart.StackedBarChartRenderer.java
/** * /*from w ww . j a v a 2s. c om*/ */ public void createChart() { CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset(); report = ChartFactory.createStackedBarChart(this.datasetStrategy.getTitle(), this.datasetStrategy.getYAxisLabel(), this.datasetStrategy.getXAxisLabel(), categorydataset, PlotOrientation.HORIZONTAL, true, true, false); // report.setBackgroundPaint( Color.lightGray ); report.setAntiAlias(false); report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d)); CategoryPlot categoryplot = (CategoryPlot) report.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setRangeGridlinePaint(Color.lightGray); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); if (datasetStrategy instanceof CloverBarChartStrategy || datasetStrategy instanceof MultiCloverBarChartStrategy) { numberaxis.setRange(0.0D, StackedBarChartRenderer.NUMBER_AXIS_RANGE); numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); } else { numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } numberaxis.setLowerMargin(0.0D); StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer(); stackedbarrenderer.setDrawBarOutline(false); stackedbarrenderer.setBaseItemLabelsVisible(true); stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); stackedbarrenderer.setBaseItemLabelFont(StackedBarRenderer.DEFAULT_VALUE_LABEL_FONT.deriveFont(Font.BOLD)); int height = (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * 2) + ChartUtils.STANDARD_BARCHART_ADDITIONAL_HEIGHT + 10; if (height > ChartUtils.MINIMUM_HEIGHT) { super.setHeight(height); } else { super.setHeight(ChartUtils.MINIMUM_HEIGHT); } Paint[] paints = this.datasetStrategy.getPaintColor(); for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) { stackedbarrenderer.setSeriesPaint(i, paints[i]); } }
From source file:net.footballpredictions.footballstats.swing.LeaguePositionGraph.java
/** * Plot league positions by date.//from w w w . j ava2 s. c om */ public void updateGraph(Object[] teams, LeagueSeason data) { assert teams.length > 0 : "Must be at least one team selected."; TimeSeriesCollection dataSet = new TimeSeriesCollection(); for (Object team : teams) { String teamName = (String) team; TimeSeries positionSeries = new TimeSeries(teamName); SortedMap<Date, Integer> positions = data.getTeam(teamName).getLeaguePositions(); for (Map.Entry<Date, Integer> entry : positions.entrySet()) { positionSeries.add(new Day(entry.getKey()), entry.getValue()); } dataSet.addSeries(positionSeries); } JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // Title messageResources.getString("graphs.date"), messageResources.getString("combo.GraphType.LEAGUE_POSITION"), dataSet, true, // Legend. false, // Tooltips. false); // URLs. chart.getXYPlot().getRangeAxis().setInverted(true); chart.getXYPlot().getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); chart.getXYPlot().getRangeAxis().setRangeWithMargins(1, data.getTeamNames().size()); chart.getLegend().setPosition(legendPosition); setChart(chart); }
From source file:com.kiyoshi.gui.AreaChart.java
private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls );// www.j a v a 2 s . c o m // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setAnchor(StandardLegend.SOUTH); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(0.5f); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.addCategoryLabelToolTip("Type 1", "The first type."); domainAxis.addCategoryLabelToolTip("Type 2", "The second type."); domainAxis.addCategoryLabelToolTip("Type 3", "The third type."); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.jfree.chart.demo.LineChart.java
private JFreeChart createChart(final XYDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart", // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );/*w ww .jav a2s. c o m*/ chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:org.jfree.chart.demo.MemoryUsageDemo.java
public MemoryUsageDemo(int i) { super(new BorderLayout()); total = new TimeSeries("Total Memory"); total.setMaximumItemAge(i);/*from ww w. ja v a 2 s . c o m*/ free = new TimeSeries("Free Memory"); free.setMaximumItemAge(i); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(total); timeseriescollection.addSeries(free); DateAxis dateaxis = new DateAxis("Time"); NumberAxis numberaxis = new NumberAxis("Memory"); dateaxis.setTickLabelFont(new Font("SansSerif", 0, 12)); numberaxis.setTickLabelFont(new Font("SansSerif", 0, 12)); dateaxis.setLabelFont(new Font("SansSerif", 0, 14)); numberaxis.setLabelFont(new Font("SansSerif", 0, 14)); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false); xylineandshaperenderer.setSeriesPaint(0, Color.red); xylineandshaperenderer.setSeriesPaint(1, Color.green); xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F, 0, 2)); xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(3F, 0, 2)); XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); dateaxis.setAutoRange(true); dateaxis.setLowerMargin(0.0D); dateaxis.setUpperMargin(0.0D); dateaxis.setTickLabelsVisible(true); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); JFreeChart jfreechart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", 1, 24), xyplot, true); jfreechart.setBackgroundPaint(Color.white); ChartPanel chartpanel = new ChartPanel(jfreechart, true); chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black))); add(chartpanel); }
From source file:logica_controladores.controlador_estadistica.java
private static void configurarRangeAxis(NumberAxis rangeAxis, double min, double max) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setTickUnit(new NumberTickUnit(500)); rangeAxis.setRange(min, max);// ww w . j a v a2 s .co m }
From source file:cheuk.licenseheaderchecker.resource.DataGraph.java
/** * Creates a trend graph/*from w w w. j av a 2s . c o m*/ * * @return the JFreeChart graph object */ protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createLineChart(null, // chart title null, // unused yLabel, // range axis label categoryDataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls ); // 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.setLowerBound(0); // rangeAxis.setAutoRange(true); final StackedAreaRenderer renderer = new StackedAreaRenderer2(); plot.setRenderer(renderer); //renderer.setBaseStroke(new BasicStroke(2.0f)); //ColorPalette.apply(renderer); plot.setRenderer(renderer); renderer.setSeriesPaint(2, RED); renderer.setSeriesPaint(1, GRAY); renderer.setSeriesPaint(0, YELLOW); // crop extra space around the graph plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); return chart; }
From source file:com.wsntools.iris.tools.Graph.java
private void setupChartType(JFreeChart chart) { chart.setBackgroundPaint(Color.white); // plot = chart.getCategoryPlot(); plot = chart.getXYPlot();/*from w w w . j a v a2 s. c o m*/ plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setAutoRange(true); domainAxis.setAutoRangeIncludesZero(false); rangeAxis.setAutoRange(true); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); chartPanel.setChart(chart); }
From source file:sim.app.sugarscape.Charts.java
JFreeChart createEvolution() { JFreeChart chart = ChartFactory.createXYLineChart("Evolution of Mean Agent Vision and Metabolism", "Time", "Level", model.evolution_vision_coll, PlotOrientation.VERTICAL, true, true, false); model.evolution_chart = chart;//from ww w . j a va 2s . c om NumberAxis rangeAxis1 = new NumberAxis("Time"); rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); org.jfree.chart.axis.NumberAxis domainAxis = new NumberAxis("Bins"); XYPlot plot = chart.getXYPlot(); ValueAxis xAxis = plot.getDomainAxis(); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, Color.BLACK); plot.setDataset(1, model.evolution_metabolism_coll); renderer.setSeriesPaint(1, Color.BLUE); return chart; }
From source file:org.sonar.server.charts.jruby.TrendsChart.java
public void initSerie(Long serieId, String legend, boolean isPercent) { TimeSeries series = new TimeSeries(legend); int index = seriesById.size(); seriesById.put(serieId, series);/*www.j a v a2s . co m*/ TimeSeriesCollection timeSeriesColl = new TimeSeriesCollection(); timeSeriesColl.addSeries(series); plot.setDataset(index, timeSeriesColl); if (isPercent) { if (percentAxisId == -1) { NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setNumberFormatOverride(new DecimalFormat("0'%'")); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(100.0); rangeAxis.setLowerBound(0.0); plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_LEFT); plot.setRangeAxis(index, rangeAxis); plot.mapDatasetToRangeAxis(index, index); percentAxisId = index; } else { plot.mapDatasetToRangeAxis(index, percentAxisId); } } else { NumberAxis rangeAxis = new NumberAxis(displayLegend ? legend : null); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeMinimumSize(2.0); plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_RIGHT); plot.setRangeAxis(index, rangeAxis); plot.mapDatasetToRangeAxis(index, index); } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesPaint(0, COLORS[index % COLORS.length]); plot.setRenderer(index, renderer); }