List of usage examples for org.jfree.chart.axis CategoryAxis setCategoryLabelPositions
public void setCategoryLabelPositions(CategoryLabelPositions positions)
From source file:edu.ucla.stat.SOCR.chart.demo.BarChart3DDemo2.java
/** * Creates a chart./*from w w w. j a v a 2 s . co m*/ * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart3D(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation !legendPanelOn, // include legend true, // tooltips false // urls ); CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(1.0f); // left align the category labels... CategoryAxis axis = plot.getDomainAxis(); CategoryLabelPositions p = axis.getCategoryLabelPositions(); CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f); axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left)); BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer(); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); setCategorySummary(dataset); return chart; }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.ProfilesComparisonReportChartCanvas.java
private void createChart() { // create dataset theDataset = createDataset();//w ww.ja v a2s . c o m // create axis CategoryAxis categoryAxis = new CategoryAxis(""); categoryAxis.setCategoryLabelPositions(org.jfree.chart.axis.CategoryLabelPositions.UP_45); ValueAxis valueAxis = new NumberAxis("Normalized Intensities"); // create renderer CategoryItemRenderer renderer = null; if (theOptions.REPRESENTATION == theOptions.BARS) renderer = new org.jfree.chart.renderer.category.BarRenderer(); else if (theOptions.REPRESENTATION == theOptions.ERRORBARS) renderer = new org.jfree.chart.renderer.category.StatisticalBarRenderer(); else if (theOptions.REPRESENTATION == theOptions.DISTRIBUTIONS) renderer = new org.jfree.chart.renderer.category.ScatterRenderer(); ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setBasePositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setBaseNegativeItemLabelPosition(position2); // create plot thePlot = new CategoryPlot(theDataset, categoryAxis, valueAxis, renderer); thePlot.setOrientation(org.jfree.chart.plot.PlotOrientation.VERTICAL); // add mean values if (theOptions.REPRESENTATION == theOptions.DISTRIBUTIONS) { thePlot.setDataset(1, createMeansDataset()); thePlot.mapDatasetToRangeAxis(1, 0); CategoryItemRenderer lr = new org.jfree.chart.renderer.category.LevelRenderer(); lr.setPaint(Color.black); thePlot.setRenderer(1, lr); } // create chart theChart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, thePlot, true); theChart.setBackgroundPaint(Color.white); theChart.setBorderVisible(false); }
From source file:org.ow2.clif.jenkins.ClifProjectAction.java
private JFreeChart createActionErrorGraph(ClifGraphParam params) { DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel> errorsDS = new DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel>(); List<AbstractBuild> builds = new ArrayList<AbstractBuild>(getProject().getBuilds()); Collections.sort(builds);/*from ww w .j a va 2s . c om*/ for (Run<?, ?> currentBuild : builds) { Result buildResult = currentBuild.getResult(); if (buildResult != null && buildResult.isBetterOrEqualTo(Result.SUCCESS)) { ChartUtil.NumberOnlyBuildLabel label = new ChartUtil.NumberOnlyBuildLabel(currentBuild); ClifBuildAction clifBuildAction = currentBuild.getAction(ClifBuildAction.class); if (clifBuildAction == null) { continue; } ClifReport clifReport = clifBuildAction.getReport(); if (clifReport == null) { continue; } TestPlan tp = clifReport.getTestplan(params.getTestPlan()); if (tp == null) { continue; } if (tp.getAggregatedMeasures() != null) { Measure m = tp.getAggregatedMeasure(params.getLabel()); if (m == null) { continue; } errorsDS.add(m.errorPercent() * 100, Messages.ProjectAction_Errors(), label); } } } final CategoryAxis xAxis = new CategoryAxis(Messages.ProjectAction_BuildAxis()); xAxis.setLowerMargin(0.01); xAxis.setUpperMargin(0.01); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); xAxis.setMaximumCategoryLabelLines(3); final ValueAxis errorsAxis = new NumberAxis(Messages.ProjectAction_ErrorAxis()); errorsAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); errorsAxis.setUpperMargin(0.1); final LineAndShapeRenderer errorRenderer = new LineAndShapeRenderer(); errorRenderer.setItemMargin(0.0); final CategoryPlot plot = new CategoryPlot(errorsDS.build(), xAxis, errorsAxis, errorRenderer); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); JFreeChart chart = new JFreeChart(Messages.ProjectAction_PercentageOfErrors(), plot); chart.setBackgroundPaint(Color.WHITE); return chart; }
From source file:org.ow2.clif.jenkins.ClifProjectAction.java
private JFreeChart createActionGraph(ClifGraphParam params) { DefaultStatisticalCategoryDataset timeDS = new DefaultStatisticalCategoryDataset(); DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel> minmaxDS = new DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel>(); List<AbstractBuild> builds = new ArrayList<AbstractBuild>(getProject().getBuilds()); Collections.sort(builds);// w ww . jav a2 s. co m for (Run<?, ?> currentBuild : builds) { Result buildResult = currentBuild.getResult(); if (buildResult != null && buildResult.isBetterOrEqualTo(Result.SUCCESS)) { ChartUtil.NumberOnlyBuildLabel label = new ChartUtil.NumberOnlyBuildLabel(currentBuild); ClifBuildAction clifBuildAction = currentBuild.getAction(ClifBuildAction.class); if (clifBuildAction == null) { continue; } ClifReport clifReport = clifBuildAction.getReport(); if (clifReport == null) { continue; } TestPlan tp = clifReport.getTestplan(params.getTestPlan()); if (tp == null) { continue; } if (tp.getAggregatedMeasures() != null) { Measure m = tp.getAggregatedMeasure(params.getLabel()); if (m == null) { continue; } timeDS.add(m.getAverage(), m.getStdDev(), Messages.ProjectAction_Mean(), label); minmaxDS.add(m.getMax(), Messages.ProjectAction_Max(), label); minmaxDS.add(m.getMin(), Messages.ProjectAction_Min(), label); } } } final CategoryAxis xAxis = new CategoryAxis(Messages.ProjectAction_BuildAxis()); xAxis.setLowerMargin(0.01); xAxis.setUpperMargin(0.01); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); xAxis.setMaximumCategoryLabelLines(3); final ValueAxis timeAxis = new NumberAxis(Messages.ProjectAction_TimeAxis()); timeAxis.setUpperMargin(0.1); // final ValueAxis minmaxTimeAxis = new NumberAxis("Time (ms)"); final BarRenderer timeRenderer = new StatisticalBarRenderer(); timeRenderer.setSeriesPaint(2, ColorPalette.RED); timeRenderer.setSeriesPaint(1, ColorPalette.YELLOW); timeRenderer.setSeriesPaint(0, ColorPalette.BLUE); timeRenderer.setItemMargin(0.0); final CategoryPlot plot = new CategoryPlot(timeDS, xAxis, timeAxis, timeRenderer); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); final CategoryItemRenderer minmaxRenderer = new LineAndShapeRenderer(); // plot.setRangeAxis(1, timeAxis); plot.setDataset(1, minmaxDS.build()); plot.mapDatasetToRangeAxis(1, 0); plot.setRenderer(1, minmaxRenderer); JFreeChart chart = new JFreeChart(params.getLabel(), plot); chart.setBackgroundPaint(Color.WHITE); return chart; }
From source file:UserInterface.EmployeeViewArea.ViewResolvedIssuesStatisticsJPanel.java
/** * Creates a sample chart./* w w w . jav a 2 s. c o m*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Open and Resolved Issues", // 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... 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.coeia.charts.BarChartPanel.java
private JFreeChart createChart(final CategoryDataset dataset, String str) { final JFreeChart chart = ChartFactory.createBarChart3D(str, // chart title "Names", // domain axis label "Values(%)", // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation true, // include legend true, // tooltips false // urls );/*w w w.j ava 2s . co m*/ final CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(1.0f); // left align the category labels... final CategoryAxis axis = plot.getDomainAxis(); final CategoryLabelPositions p = axis.getCategoryLabelPositions(); final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f); axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left)); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(from, to); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:com.mentor.questa.vrm.jenkins.QuestaVrmHostAction.java
private JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title "Relative time", // unused "count", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls );/*w w w . j a va 2 s.c om*/ 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(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); StackedAreaRenderer ar = new StackedAreaRenderer2() { private long getTime(CategoryDataset dataset, int column) { Long offset = (Long) dataset.getColumnKey(column); return getRegressionResult().getRegressionBegin().getTime() + offset * 1000; } @Override public String generateURL(CategoryDataset dataset, int row, int column) { return "javascript:getSummary(" + getTime(dataset, column) + ");"; } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { String host = (String) dataset.getRowKey(row); Date date = new Date(getTime(dataset, column)); int value = (Integer) dataset.getValue(row, column); return value + " on " + host + "@" + date.toString(); } }; plot.setRenderer(ar); // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
From source file:com.wicht.benchmark.utils.Benchs.java
/** * Generate the chart.// ww w . j a v a2s . co m * * @param title The title of the chart. * @param benchmarks The benchmarks to include in the chart. * @param sub A boolean tag indicating if we want to generate sub chart ({@code true}) or not ({@code * false}). * @param prefix The time prefix. */ private void generateChart(String title, Collection<NamedBenchmark> benchmarks, boolean sub, Prefix prefix) { String data = "Time (" + prefix.getSymbol() + "s)"; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (NamedBenchmark benchmark : benchmarks) { dataset.addValue(getExactMean(benchmark.getMean(), prefix), "", benchmark.getTitle()); } JFreeChart chart = ChartFactory.createBarChart(title.replace("-sub", ""), "Methods", data, dataset, PlotOrientation.VERTICAL, false, false, false); final CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setMaximumCategoryLabelLines(5); BufferedImage image = chart.createBufferedImage(width, height); try { ImageIO.write(image, "png", new File(folder + title + ".png")); } catch (IOException e) { e.printStackTrace(); } if (sub) { generateSubChart(title, benchmarks); } }
From source file:org.patientview.radar.service.impl.UtilityManagerImpl.java
public JFreeChart getPatientCountPerUnitChart() { // create dataset String srnsSeries = "SRNS"; String mpgnSeries = "MPGN"; DiagnosisCode srnsCode = new DiagnosisCode(); srnsCode.setId(DiagnosisCode.SRNS_ID); DiagnosisCode mpgnCode = new DiagnosisCode(); mpgnCode.setId(DiagnosisCode.MPGN_ID); Map<Long, Integer> srnsPatientCountMap = getPatientCountPerUnitByDiagnosisCode(srnsCode); Map<Long, Integer> mpgnPatientCountMap = getPatientCountPerUnitByDiagnosisCode(mpgnCode); java.util.List<Centre> centreList = getCentres(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Centre centre : centreList) { String centreCategory = centre.getAbbreviation() != null ? centre.getAbbreviation() : centre.getName(); Integer srnsCount = srnsPatientCountMap.containsKey(centre.getId()) ? srnsPatientCountMap.get(centre.getId()) : null;// ww w.j a v a 2s .c o m if (srnsCount != null && srnsCount > 0) { dataset.addValue(srnsCount, srnsSeries, centreCategory); } Integer mpgnCount = mpgnPatientCountMap.containsKey(centre.getId()) ? mpgnPatientCountMap.get(centre.getId()) : null; if (mpgnCount != null && mpgnCount > 0) { dataset.addValue(mpgnCount, mpgnSeries, centreCategory); } } // create chart JFreeChart chart = ChartFactory.createBarChart("Total number of registered patients by unit", // chart title "", // domain axis label "", // 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 = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); 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... BarRenderer renderer = (BarRenderer) plot.getRenderer(); DecimalFormat decimalformat1 = new DecimalFormat("##,###"); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1)); renderer.setItemLabelsVisible(true); renderer.setBaseItemLabelsVisible(true); // 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.setLabelFont(new Font("Times New Roman", Font.PLAIN, 12)); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_vertical.java
/** * Creates a chart./* www . j a v a 2 s.c om*/ * * @param dataset the dataset. * * @return a chart. */ protected JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation !legendPanelOn, // 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 = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // 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; }