List of usage examples for org.jfree.chart.axis NumberAxis setAutoRange
public void setAutoRange(boolean auto)
From source file:ch.zhaw.simulation.diagram.charteditor.DefaultNumberAxisEditor.java
/** * Sets the properties of the specified axis to match the properties defined * on this panel.//from ww w . ja v a 2s.co m * * @param axis * the axis. */ public void setAxisProperties(Axis axis) { super.setAxisProperties(axis); NumberAxis numberAxis = (NumberAxis) axis; numberAxis.setAutoRange(this.autoRange); if (!this.autoRange) { numberAxis.setRange(this.minimumValue, this.maximumValue); } }
From source file:com.bt.aloha.sipstone.GenGraph.java
private JFreeChart createSingleChart() { XYDataset xydatasetArray[] = createDataset_CallsPerSecond_AvgResponseTime(); XYDataset xydataset = xydatasetArray[0]; final XYDataset percXydataset = xydatasetArray[1]; JFreeChart jfreechart = ChartFactory.createXYLineChart("SIPStone result", "Calls per second", "Avg response time", xydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); XYItemRenderer xyrenderer = (XYItemRenderer) xyplot.getRenderer(); xyrenderer.setBaseItemLabelGenerator(new MyXYItemLabelGenerator(percXydataset)); xyrenderer.setBaseItemLabelsVisible(true); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); numberaxis.setAutoRange(true); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return jfreechart; }
From source file:org.amanzi.awe.distribution.ui.widgets.DistributionChartWidget.java
public void updateChartType(final ChartType chartType) { final CategoryPlot plot = (CategoryPlot) distributionChart.getPlot(); switch (chartType) { case LOGARITHMIC: final LogarithmicAxis logAxis = new LogarithmicAxis("Logarithmic"); logAxis.setAllowNegativesFlag(true); plot.setRangeAxis(logAxis);/*from w ww .jav a2s . co m*/ logAxis.setAutoRange(true); break; case COUNTS: final NumberAxis countAxis = new NumberAxis("Counts"); countAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setRangeAxis(countAxis); countAxis.setAutoRange(true); break; case PERCENTS: final NumberAxis percentageAxis = new NumberAxis("Percentage"); percentageAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); percentageAxis.setRange(0, 100); plot.setRangeAxis(percentageAxis); break; } dataset.updateDelegate(chartType); update(); }
From source file:de.fub.maps.project.detector.model.inference.ui.charts.ClassificationBarChart.java
/** * Creates new form ClassificationBarChart *///from w w w. ja v a 2s . c om public ClassificationBarChart() { super(); initComponents(); plot = new CustomCategoryPlot(); barChart = new JFreeChart(NbBundle.getMessage(ClassificationBarChart.class, "CLT_Chart_Classify_Name"), null, plot, true); ChartFactory.getChartTheme().apply(barChart); plot.setDomainAxis(new CategoryAxis()); plot.getDomainAxis().setLabel(NbBundle.getMessage(ClassificationBarChart.class, "CLT_Doman_Axis_Name")); plot.setOrientation(PlotOrientation.VERTICAL); Font font = new JLabel().getFont().deriveFont(Font.BOLD, 14); barChart.getTitle().setFont(font); barChart.getTitle().setPaint(new Color(153, 153, 153)); plot.setDataset(0, relDataset); plot.setDataset(1, absDataset); plot.mapDatasetToRangeAxis(0, 0); plot.mapDatasetToRangeAxis(1, 1); NumberAxis relAxis = new NumberAxis( NbBundle.getMessage(ClassificationBarChart.class, "CLT_Value_Axis_Name")); relAxis.setAutoRange(true); relAxis.setUpperMargin(.20); NumberAxis absAxis = new NumberAxis( NbBundle.getMessage(ClassificationBarChart.class, "CLT_Value_Rel_Axis_Name")); absAxis.setAutoRange(true); absAxis.setUpperMargin(.20); plot.setRangeAxis(0, relAxis); plot.setRangeAxis(1, absAxis); plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT); BarRenderer relRenderer = new BarRenderer(); relRenderer.setBasePaint(relColor); relRenderer.setAutoPopulateSeriesPaint(false); relRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); relRenderer.setBarPainter(new StandardBarPainter()); relRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator( StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat())); relRenderer.setBaseItemLabelsVisible(true); BarRenderer absRenderer = new BarRenderer(); absRenderer.setBasePaint(absColor); absRenderer.setAutoPopulateSeriesPaint(false); absRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); absRenderer.setBarPainter(new StandardBarPainter()); absRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator( StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat())); absRenderer.setBaseItemLabelsVisible(true); plot.setRenderer(0, relRenderer); plot.setRenderer(1, absRenderer); plot.setBackgroundPaint(Color.white); barChart.setBackgroundPaint(Color.white); plot.setRangeGridlinesVisible(false); chartPanel = new ChartPanel(barChart, false); chartPanel.setVerticalAxisTrace(false); chartPanel.setDisplayToolTips(true); chartPanel.setBackground(Color.white); add(chartPanel, BorderLayout.CENTER); }
From source file:com.googlecode.refit.jenkins.ReFitGraph.java
/** * Creates a chart from the test result data set. * <p>//from www.ja va 2 s. com * The i-th row of the data set corresponds to the results from the i-th build. * Each row has columns 0, 1, 2 containing the number of failed, skipped and passed tests. * The chart stacks these values from bottom to top, joins the values for the same columns * with lines and fills the areas between the lines with given colours. * <p> * TODO Find out if Jenkins core provides any caching for the chart or the data set. */ @Override protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title null, // domain axis label "count", // range axis label data, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); final 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); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); ChartUtil.adjustChebyshev(data, rangeAxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRange(true); StackedAreaRenderer ar = new StackedAreaRenderer2() { private static final long serialVersionUID = 1L; /** * Colour brush for the given data point. */ @Override public Paint getItemPaint(int row, int column) { return super.getItemPaint(row, column); } /** * URL for the given data point, which gets opened when the user clicks on or near * the data point in the chart. */ @Override public String generateURL(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); return label.getUrl(); } /** * Tooltip to be displayed on the chart when the user hovers at or near the * data point. * <p> * The tooltip has the format {@code #17 : 300 Passed}, indicating the build number * and the number of tests with the given result. */ @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { ChartLabel label = (ChartLabel) dataset.getColumnKey(column); TestResult result = label.getResult(); String rowKey = (String) dataset.getRowKey(row); return result.getOwner().getDisplayName() + " : " + dataset.getValue(row, column) + " " + rowKey.substring(1); } }; plot.setRenderer(ar); // Define colours for the data points by column index ar.setSeriesPaint(0, ColorPalette.RED); // Failed ar.setSeriesPaint(1, ColorPalette.YELLOW); // Skipped ar.setSeriesPaint(2, ColorPalette.BLUE); // Passed // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
From source file:gg.view.categoriesbalances.GraphCategoriesBalancesTopComponent.java
/** * Displays the categories/sub-categories' balances by period * @param balances Categories' balances//from w ww. ja va 2 s. c o m */ private void displayData(Map<Long, Map<SearchCriteria, BigDecimal>> balances) { log.info("Categories' balances graph computed and displayed"); // Display hourglass cursor Utilities.changeCursorWaitStatus(true); // Create the dataset (that will contain the categories/sub-categories' balances) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Create an empty chart JFreeChart chart = ChartFactory.createLineChart("", // chart title "", // x axis label NbBundle.getMessage(GraphCategoriesBalancesTopComponent.class, "GraphAccountsBalancesTopComponent.Amount"), // y axis label dataset, // data displayed in the chart PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // Chart color chart.setBackgroundPaint(jPanelCategoriesBalances.getBackground()); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); // Grid lines plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // Set the orientation of the categories on the domain axis (X axis) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Add the series on the chart for each category/sub-category displayed in the table for (Long categoryId : balances.keySet()) { Category category = Wallet.getInstance().getCategoriesWithId().get(categoryId); assert (category != null); SortedSet<SearchCriteria> sortedSearchCriteria = new TreeSet<SearchCriteria>( balances.get(categoryId).keySet()); for (SearchCriteria searchCriteria : sortedSearchCriteria) { if ((!searchCriteria.hasCategoriesFilter() && category.isTopCategory() && !category.getSystemProperty()) || searchCriteria.getCategories().contains(category)) { BigDecimal balance = new BigDecimal(0); if (balances.get(categoryId) != null && balances.get(categoryId).get(searchCriteria) != null) { balance = balances.get(categoryId).get(searchCriteria); } dataset.addValue(balance, category.getName(), searchCriteria.getPeriod()); } } } // Series' shapes LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F)); } // Set the scale of the chart NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create the chart panel that contains the chart ChartPanel chartPanel = new ChartPanel(chart); // Display the chart jPanelCategoriesBalances.removeAll(); jPanelCategoriesBalances.add(chartPanel, BorderLayout.CENTER); jPanelCategoriesBalances.updateUI(); // Display normal cursor Utilities.changeCursorWaitStatus(false); }
From source file:gg.view.accountsbalances.GraphAccountsBalancesTopComponent.java
/** * Displays the accounts' balances by period * @param balances Accounts' balances// w w w .ja v a2 s .c om */ private void displayData(Map<MoneyContainer, Map<SearchCriteria, BigDecimal>> balances) { log.info("Accounts' balances graph computed and displayed"); // Display hourglass cursor Utilities.changeCursorWaitStatus(true); // Create the dataset (that will contain the accounts' balances) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Create an empty chart JFreeChart chart = ChartFactory.createLineChart("", // chart title "", // x axis label NbBundle.getMessage(GraphAccountsBalancesTopComponent.class, "AccountsBalancesTopComponent.Amount"), // y axis label dataset, // data displayed in the chart PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // Chart color chart.setBackgroundPaint(jPanelAccountsBalances.getBackground()); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); // Grid lines plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // Set the orientation of the categories on the domain axis (X axis) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Add the series on the chart for each account displayed in the table for (MoneyContainer moneyContainer : balances.keySet()) { if (moneyContainer instanceof Account) { Account account = (Account) moneyContainer; SortedSet<SearchCriteria> sortedSearchCriteria = new TreeSet<SearchCriteria>( balances.get(account).keySet()); for (SearchCriteria searchCriteria : sortedSearchCriteria) { if (!searchCriteria.hasAccountsFilter() || searchCriteria.getAccounts().contains(account)) { dataset.addValue(balances.get(moneyContainer).get(searchCriteria), account.toString(), searchCriteria.getPeriod()); } } } } // Series' shapes LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F)); } // Set the scale of the chart NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create the chart panel that contains the chart ChartPanel chartPanel = new ChartPanel(chart); // Display the chart jPanelAccountsBalances.removeAll(); jPanelAccountsBalances.add(chartPanel, BorderLayout.CENTER); jPanelAccountsBalances.updateUI(); // Display normal cursor Utilities.changeCursorWaitStatus(false); }
From source file:gg.view.movementsbalances.GraphMovementsBalancesTopComponent.java
/** * Displays the accounts' movements balances by period * @param searchFilters Search filter objects (one per period) for which the movements balances are wanted */// w w w .ja va 2 s.c om private void displayData(Map<MoneyContainer, Map<SearchCriteria, BigDecimal>> balances) { log.info("Movements' balances graph computed and displayed"); // Display hourglass cursor Utilities.changeCursorWaitStatus(true); // Create the dataset (that will contain the movements' balances) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Create an empty chart JFreeChart chart = ChartFactory.createLineChart("", // chart title "", // x axis label NbBundle.getMessage(GraphMovementsBalancesTopComponent.class, "GraphMovementsBalancesTopComponent.Amount"), // y axis label dataset, // data displayed in the chart PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // Chart color chart.setBackgroundPaint(jPanelMovementsBalances.getBackground()); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); // Grid lines plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // Set the orientation of the categories on the domain axis (X axis) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Add the series on the chart for (MoneyContainer moneyContainer : balances.keySet()) { if (moneyContainer instanceof Account) { SortedSet<SearchCriteria> sortedSearchFilters = new TreeSet<SearchCriteria>( balances.get(moneyContainer).keySet()); for (SearchCriteria searchCriteria : sortedSearchFilters) { BigDecimal accountBalance = balances.get(moneyContainer).get(searchCriteria); accountBalance = accountBalance.setScale(2, RoundingMode.HALF_EVEN); dataset.addValue(accountBalance, moneyContainer.toString(), searchCriteria.getPeriod()); } } } // Series' shapes LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F)); } // Set the scale of the chart NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create the chart panel that contains the chart ChartPanel chartPanel = new ChartPanel(chart); // Display the chart jPanelMovementsBalances.removeAll(); jPanelMovementsBalances.add(chartPanel, BorderLayout.CENTER); jPanelMovementsBalances.updateUI(); // Display normal cursor Utilities.changeCursorWaitStatus(false); }
From source file:br.upe.ecomp.dosa.controller.chart.FileBoxplotChartManager.java
private JFreeChart createChart(String title, String xLabel, String yLabel, BoxAndWhiskerCategoryDataset dataset, boolean logarithmicYAxis) { final CategoryAxis xAxis = new CategoryAxis("Sample"); final NumberAxis yAxis; if (logarithmicYAxis) { yAxis = new LogarithmicAxis("Fitness (Log10)"); ((LogarithmicAxis) yAxis).setExpTickLabelsFlag(true); } else {// ww w . j a v a 2s. c o m yAxis = new NumberAxis("Fitness"); } yAxis.setAutoRangeIncludesZero(false); yAxis.setAutoRange(true); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(true); renderer.setBaseCreateEntities(true); // renderer.setArtifactPaint(Color.green); renderer.setBaseOutlinePaint(Color.blue); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(title, xAxis.getLabel(), yAxis.getLabel(), dataset, true); final CategoryPlot plot = chart.getCategoryPlot();// new CategoryPlot(dataset, xAxis, yAxis, // renderer); plot.setBackgroundPaint(Color.white); // chart.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setRenderer(renderer); plot.setRangeAxis(yAxis); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:grafix.graficos.eixos.Eixo.java
public void configurarEscalaVertical(XYPlot plot) { NumberAxis nAxis = (NumberAxis) plot.getRangeAxis(); if (this.isAutoEscala()) { if (this.isIncluiZero()) { nAxis.setAutoRange(true); nAxis.setAutoRangeIncludesZero(true); } else {//from w w w .jav a 2s .c om nAxis.setAutoRange(true); nAxis.setAutoRangeIncludesZero(false); } } else { if (this.isIncluiZero()) { nAxis.setRange(Math.min(getEscalaMin(), 0), Math.max(0, getEscalaMax())); } else { nAxis.setRange(getEscalaMin(), getEscalaMax()); } } }