List of usage examples for org.jfree.chart.axis CategoryAxis setLowerMargin
public void setLowerMargin(double margin)
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartCategoryGraphSource.java
@Override public void initialize() throws GraphException { String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE); String xLabel = getParam(GraphSource.GRAPH_X_LABEL, String.class, DEFAULT_DOMAIN_LABEL); String yLabel = getParam(GraphSource.GRAPH_Y_LABEL, String.class, DEFAULT_RANGE_LABEL); CategoryDataset dataset = makeDataSet(); chart = createChart(title, xLabel, yLabel, dataset, false, false); // start customizing the graph Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR); Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor); Double offset = getParam(GraphSource.AXIS_OFFSET, Double.class, DEFAULT_AXIS_OFFSET); Paint graphDomainGridlinePaint = getParam(GraphSource.GRAPH_DOMAIN_GRIDLINE_PAINT, Paint.class, backgroundColor);/*from w ww . j a v a2 s . c o m*/ Paint graphRangeGridlinePaint = getParam(GraphSource.GRAPH_RANGE_GRIDLINE_PAINT, Paint.class, backgroundColor); boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER); chart.setBackgroundPaint(backgroundColor); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(plotColor); plot.setAxisOffset(new RectangleInsets(offset, offset, offset, offset)); plot.setDomainGridlinePaint(graphDomainGridlinePaint); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(graphRangeGridlinePaint); plot.setOutlineVisible(graphBorder); // set the axis location AxisLocation axisLocation = getParam(GraphSource.GRAPH_RANGE_AXIS_LOCATION, AxisLocation.class, AxisLocation.TOP_OR_LEFT); plot.setRangeAxisLocation(axisLocation); // customize the y-axis if (params.get(RANGE_AXIS) instanceof ValueAxis) { ValueAxis valueAxis = (ValueAxis) params.get(RANGE_AXIS); plot.setRangeAxis(valueAxis); } ValueAxis valueAxis = plot.getRangeAxis(); Object yAxisFont = params.get(GraphSource.GRAPH_Y_AXIS_FONT); Object yAxisLabelFont = params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT); Double rangeLowerBound = getParam(GraphSource.GRAPH_RANGE_LOWER_BOUND, Double.class, null); Double rangeUpperBound = getParam(GraphSource.GRAPH_RANGE_UPPER_BOUND, Double.class, null); boolean graphRangeIntegerTick = getParam(GraphSource.GRAPH_RANGE_INTEGER_TICK, Boolean.class, false); boolean graphRangeMinorTickVisible = getParam(GraphSource.GRAPH_RANGE_MINOR_TICK_VISIBLE, Boolean.class, true); if (yAxisFont instanceof Font) { valueAxis.setTickLabelFont((Font) yAxisFont); } if (yAxisLabelFont instanceof Font) { valueAxis.setLabelFont((Font) yAxisLabelFont); } if (rangeLowerBound != null) { valueAxis.setLowerBound(rangeLowerBound); } if (rangeUpperBound != null) { valueAxis.setUpperBound(rangeUpperBound); } if (graphRangeIntegerTick) { valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } valueAxis.setMinorTickMarksVisible(graphRangeMinorTickVisible); // customize the x-axis if (params.get(DOMAIN_AXIS) instanceof CategoryAxis) { CategoryAxis domainAxis = (CategoryAxis) params.get(DOMAIN_AXIS); plot.setDomainAxis(domainAxis); } CategoryAxis domainAxis = plot.getDomainAxis(); Object xAxisFont = params.get(GraphSource.GRAPH_X_AXIS_FONT); Object xAxisLabelFont = params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT); if (xAxisFont instanceof Font) { domainAxis.setTickLabelFont((Font) xAxisFont); } if (xAxisLabelFont instanceof Font) { domainAxis.setLabelFont((Font) xAxisLabelFont); } domainAxis.setLabel(xLabel); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); plot.setDomainAxis(domainAxis); // change the font of the graph title Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT); TextTitle textTitle = new TextTitle(); textTitle.setText(title); textTitle.setFont(titleFont); chart.setTitle(textTitle); // makes a wrapper for the legend to remove the border around it boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND); boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER); Object legendFont = params.get(GraphSource.LEGEND_FONT); if (legend) { LegendTitle legendTitle = new LegendTitle(chart.getPlot()); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); if (legendBorder) { wrapper.setFrame(new BlockBorder(1, 1, 1, 1)); } else { wrapper.setFrame(new BlockBorder(0, 0, 0, 0)); } BlockContainer items = legendTitle.getItemContainer(); items.setPadding(2, 10, 5, 2); wrapper.add(items); legendTitle.setWrapper(wrapper); legendTitle.setPosition(RectangleEdge.BOTTOM); legendTitle.setHorizontalAlignment(HorizontalAlignment.CENTER); if (legendFont instanceof Font) { legendTitle.setItemFont((Font) legendFont); } chart.addSubtitle(legendTitle); } this.initialized = true; }
From source file:hudson.plugins.plot.PlotData.java
/** * Generates the plot and stores it in the plot instance variable. * /*from w ww . j a va 2 s . c o m*/ * @param forceGenerate if true, force the plot to be re-generated * even if the on-disk data hasn't changed */ private void generatePlot(boolean forceGenerate) { class Label implements Comparable<Label> { final private Integer buildNum; final private String buildDate; final private String text; public Label(String buildNum, String buildTime, String text) { this.buildNum = Integer.parseInt(buildNum); synchronized (DATE_FORMAT) { this.buildDate = DATE_FORMAT.format(new Date(Long.parseLong(buildTime))); } this.text = text; } public int compareTo(Label that) { return this.buildNum - that.buildNum; } @Override public boolean equals(Object o) { return o instanceof Label && ((Label) o).buildNum.equals(buildNum); } @Override public int hashCode() { return buildNum.hashCode(); } public String numDateString() { return "#" + buildNum + " (" + buildDate + ")"; } @Override public String toString() { return text != null ? text : numDateString(); } } LOGGER.fine("Generating plot from file: " + csvFilePath.getName()); PlotCategoryDataset dataset = new PlotCategoryDataset(); for (String[] record : rawPlotData) { // record: series y-value, series label, build number, build date, url int buildNum; try { buildNum = Integer.valueOf(record[2]); if (project.getBuildByNumber(buildNum) == null || buildNum > getRightBuildNum()) { continue; // skip this record } } catch (NumberFormatException nfe) { continue; // skip this record all together } Number value = null; try { value = Integer.valueOf(record[0]); } catch (NumberFormatException nfe) { try { value = Double.valueOf(record[0]); } catch (NumberFormatException nfe2) { continue; // skip this record all together } } String series = record[1]; Label xlabel = getUrlUseDescr() ? new Label(record[2], record[3], descriptionForBuild(buildNum)) : new Label(record[2], record[3], getBuildName(buildNum)); String url = null; if (record.length >= 5) url = record[4]; dataset.setValue(value, url, series, xlabel); } int numBuilds; try { numBuilds = Integer.parseInt(getURLNumBuilds()); } catch (NumberFormatException nfe) { numBuilds = DEFAULT_NUMBUILDS; } dataset.clipDataset(numBuilds); plot = createChart(dataset); CategoryPlot categoryPlot = (CategoryPlot) plot.getPlot(); categoryPlot.setDomainGridlinePaint(Color.black); categoryPlot.setRangeGridlinePaint(Color.black); categoryPlot.setDrawingSupplier(PlotData.supplier); CategoryAxis domainAxis = new ShiftedCategoryAxis(Messages.Plot_Build()); categoryPlot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.03); domainAxis.setCategoryMargin(0.0); for (Object category : dataset.getColumnKeys()) { Label label = (Label) category; if (label.text != null) { domainAxis.addCategoryLabelToolTip(label, label.numDateString()); } else { domainAxis.addCategoryLabelToolTip(label, descriptionForBuild(label.buildNum)); } } AbstractCategoryItemRenderer renderer = (AbstractCategoryItemRenderer) categoryPlot.getRenderer(); int numColors = dataset.getRowCount(); for (int i = 0; i < numColors; i++) { renderer.setSeriesPaint(i, new Color(Color.HSBtoRGB((1f / numColors) * i, 1f, 1f))); } renderer.setStroke(new BasicStroke(2.0f)); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator(Messages.Plot_Build() + " {1}: {2}", NumberFormat.getInstance())); renderer.setItemURLGenerator(new PointURLGenerator()); if (renderer instanceof LineAndShapeRenderer) { LineAndShapeRenderer lasRenderer = (LineAndShapeRenderer) renderer; lasRenderer.setShapesVisible(true); // TODO: deprecated, may be unnecessary } }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getChapterPareto(DefaultKeyedValues data, String title, String quantity, String range) { JFreeChart chart;//from www .j a va 2 s. c o m data.sortByValues(SortOrder.DESCENDING); KeyedValues cummulative = DataUtilities.getCumulativePercentages(data); CategoryDataset dataset = DatasetUtilities.createCategoryDataset(quantity, data); // create the chart... chart = ChartFactory.createBarChart(title, // chart title "Chapter", // domain axis label range, // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cummulative", cummulative); NumberAxis axis2 = new NumberAxis("Percent"); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); axis2.setUpperBound(1); axis2.setLowerBound(0); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return chart; }
From source file:nl.strohalm.cyclos.controls.reports.statistics.graphs.ChartPostProcessorImpl.java
/** * This method sets the width of the bars, and the spacing between the bars. It sets a general, hard coded standard for this. In JFreeChart, you * cannot set the bar width. In stead, you set the gaps: - lowerMargin is the gap between the start of the x-axis and the first bar - upperMargin * is the gap between the end of the x-axis and the last bar - categoryMargin is the gap between the categories. Note that the number you provide * here, is divided over all the gaps. So if you set this margin to 0.5 (is 50%) and there are 6 categories, this means that there are 5 gaps, so * each gap will get 10%. - itemMargin is the gap between the bars within a category. Again, this number is divided over all the itemgaps in the * whole graph. The method also takes care that extreme cases (with a very small amount of bars) still look acceptable. * @param plot/*from w w w . ja v a2s .com*/ */ private void setMargins(final CategoryPlot plot) { final CategoryAxis axis = plot.getDomainAxis(); axis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 9)); final int categoryCount = plot.getCategories().size(); final int seriesCount = plot.getDataset().getRowCount(); axis.setCategoryMargin(0.23); // sets spacing between categories on x% // set spacing between bars inside a catgory (in fractions, so 1 = 100%) final BarRenderer renderer = (BarRenderer) plot.getRenderer(); if (categoryCount == 1) { renderer.setItemMargin(0.15); } else { renderer.setItemMargin(0.03); } // extreme cases if (categoryCount * seriesCount < 4) { final double outerMargins = (4.0 - (categoryCount * seriesCount)) / 10.0; axis.setLowerMargin(outerMargins); axis.setUpperMargin(outerMargins); } }
From source file:edu.ucla.stat.SOCR.chart.demo.BoxAndWhiskerChartDemo1.java
/** * Creates a sample chart.// w w w.j a va 2s .com * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(BoxAndWhiskerCategoryDataset dataset) { CategoryAxis domainAxis = new CategoryAxis(null); NumberAxis rangeAxis = new NumberAxis(rangeLabel); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(chartTitle, plot); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setLegendItemLabelGenerator( new SOCRCategoryCellLabelGenerator(dataset, values_storage, SERIES_COUNT, CATEGORY_COUNT)); //RowCount -- serie count if (dataset.getColumnCount() * dataset.getRowCount() < 5) { domainAxis.setLowerMargin(0.2); domainAxis.setUpperMargin(0.2); if (dataset.getColumnCount() == 1) renderer.setItemMargin(0.5); // domainAxis.setCategoryMargin(domainAxis.getCategoryMargin()*2); /* System.out.println("1lowerMargin="+domainAxis.getLowerMargin()); System.out.println("ItemMargin="+renderer.getItemMargin()); System.out.println("CategoryMargin="+domainAxis.getCategoryMargin());*/ } else if (dataset.getColumnCount() * dataset.getRowCount() < 10) { domainAxis.setLowerMargin(domainAxis.getLowerMargin() * 2); domainAxis.setUpperMargin(domainAxis.getUpperMargin() * 2); if (dataset.getColumnCount() == 1) renderer.setItemMargin(renderer.getItemMargin() * 2); else domainAxis.setCategoryMargin(domainAxis.getCategoryMargin() * 2); /*System.out.println("2lowerMargin="+domainAxis.getLowerMargin()); System.out.println("ItemMargin="+renderer.getItemMargin()); System.out.println("CategoryMargin="+domainAxis.getCategoryMargin());*/ } if (legendPanelOn) chart.removeLegend(); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.CategoryStepChartDemo1.java
/** * Creates a chart./* www . ja v a 2 s. c om*/ * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { CategoryItemRenderer renderer = new CategoryStepRenderer(true); CategoryAxis domainAxis = new CategoryAxis(domainLabel); NumberAxis rangeAxis = new NumberAxis(rangeLabel); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(chartTitle, plot); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); plot.setAxisOffset(new RectangleInsets(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); AbstractCategoryItemRenderer renderer2 = (AbstractCategoryItemRenderer) plot.getRenderer(); renderer2.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); 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."); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. setCategorySummary(dataset); if (legendPanelOn) chart.removeLegend(); return chart; }
From source file:org.jfree.chart.demo.CategoryStepChartDemo.java
/** * Creates a chart.// ww w . ja v a 2s. co m * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final CategoryItemRenderer renderer = new CategoryStepRenderer(true); final CategoryAxis domainAxis = new CategoryAxis("Category"); final ValueAxis rangeAxis = new NumberAxis("Value"); final CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); final JFreeChart chart = new JFreeChart("Category Step Chart", plot); // 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); // 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); 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."); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:edu.ucla.stat.SOCR.chart.ChartGenerator.java
private JFreeChart createBoxAndWhiskerChart(String title, String xLabel, String yLabel, BoxAndWhiskerCategoryDataset dataset) { CategoryAxis domainAxis = new CategoryAxis(xLabel); NumberAxis rangeAxis = new NumberAxis(yLabel); // CategoryItemRenderer renderer = new BoxAndWhiskerRenderer(); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(title, plot); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //columnCount -- category count //RowCount -- serie count if (dataset.getColumnCount() * dataset.getRowCount() < 5) { domainAxis.setLowerMargin(0.2); domainAxis.setUpperMargin(0.2);/*w w w . j a va2s.co m*/ if (dataset.getColumnCount() == 1) renderer.setItemMargin(0.5); // domainAxis.setCategoryMargin(domainAxis.getCategoryMargin()*2); /* System.out.println("lowerMargin="+domainAxis.getLowerMargin()); System.out.println("ItemMargin="+renderer.getItemMargin()); System.out.println("CategoryMargin="+domainAxis.getCategoryMargin());*/ } else if (dataset.getColumnCount() * dataset.getRowCount() < 10) { domainAxis.setLowerMargin(domainAxis.getLowerMargin() * 2); domainAxis.setUpperMargin(domainAxis.getUpperMargin() * 2); if (dataset.getColumnCount() == 1) renderer.setItemMargin(renderer.getItemMargin() * 2); else domainAxis.setCategoryMargin(domainAxis.getCategoryMargin() * 2); /*System.out.println("lowerMargin="+domainAxis.getLowerMargin()); System.out.println("ItemMargin="+renderer.getItemMargin()); System.out.println("CategoryMargin="+domainAxis.getCategoryMargin()); */ } return chart; }
From source file:hudson.plugins.plot.Plot.java
/** * Generates the plot and stores it in the plot instance variable. * * @param forceGenerate/*from w ww . j a v a 2s . co m*/ * if true, force the plot to be re-generated even if the on-disk * data hasn't changed */ private void generatePlot(boolean forceGenerate) { class Label implements Comparable<Label> { final private Integer buildNum; final private String buildDate; final private String text; public Label(String buildNum, String buildTime, String text) { this.buildNum = Integer.parseInt(buildNum); synchronized (DATE_FORMAT) { this.buildDate = DATE_FORMAT.format(new Date(Long.parseLong(buildTime))); } this.text = text; } public Label(String buildNum, String buildTime) { this(buildNum, buildTime, null); } public int compareTo(Label that) { return this.buildNum - that.buildNum; } @Override public boolean equals(Object o) { return o instanceof Label && ((Label) o).buildNum.equals(buildNum); } @Override public int hashCode() { return buildNum.hashCode(); } public String numDateString() { return "#" + buildNum + " (" + buildDate + ")"; } @Override public String toString() { return text != null ? text : numDateString(); } } // LOGGER.info("Determining if we should generate plot " + // getCsvFileName()); File csvFile = new File(project.getRootDir(), getCsvFileName()); if (csvFile.lastModified() == csvLastModification && plot != null && !forceGenerate) { // data hasn't changed so don't regenerate the plot return; } if (rawPlotData == null || csvFile.lastModified() > csvLastModification) { // data has changed or has not been loaded so load it now loadPlotData(); } // LOGGER.info("Generating plot " + getCsvFileName()); csvLastModification = csvFile.lastModified(); PlotCategoryDataset dataset = new PlotCategoryDataset(); for (String[] record : rawPlotData) { // record: series y-value, series label, build number, build date, // url int buildNum; try { buildNum = Integer.valueOf(record[2]); if (!reportBuild(buildNum) || buildNum > getRightBuildNum()) { continue; // skip this record } } catch (NumberFormatException nfe) { LOGGER.log(Level.SEVERE, "Exception converting to integer", nfe); continue; // skip this record all together } Number value = null; try { value = Integer.valueOf(record[0]); } catch (NumberFormatException nfe) { try { value = Double.valueOf(record[0]); } catch (NumberFormatException nfe2) { LOGGER.log(Level.SEVERE, "Exception converting to number", nfe2); continue; // skip this record all together } } String series = record[1]; Label xlabel = getUrlUseDescr() ? new Label(record[2], record[3], descriptionForBuild(buildNum)) : new Label(record[2], record[3]); String url = null; if (record.length >= 5) url = record[4]; dataset.setValue(value, url, series, xlabel); } String urlNumBuilds = getURLNumBuilds(); int numBuilds; if (StringUtils.isBlank(urlNumBuilds)) { numBuilds = Integer.MAX_VALUE; } else { try { numBuilds = Integer.parseInt(urlNumBuilds); } catch (NumberFormatException nfe) { LOGGER.log(Level.SEVERE, "Exception converting to integer", nfe); numBuilds = Integer.MAX_VALUE; } } dataset.clipDataset(numBuilds); plot = createChart(dataset); CategoryPlot categoryPlot = (CategoryPlot) plot.getPlot(); categoryPlot.setDomainGridlinePaint(Color.black); categoryPlot.setRangeGridlinePaint(Color.black); categoryPlot.setDrawingSupplier(Plot.supplier); CategoryAxis domainAxis = new ShiftedCategoryAxis(Messages.Plot_Build()); categoryPlot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.03); domainAxis.setCategoryMargin(0.0); for (Object category : dataset.getColumnKeys()) { Label label = (Label) category; if (label.text != null) { domainAxis.addCategoryLabelToolTip(label, label.numDateString()); } else { domainAxis.addCategoryLabelToolTip(label, descriptionForBuild(label.buildNum)); } } // Replace the range axis by a logarithmic axis if the option is // selected if (isLogarithmic()) { LogarithmicAxis logAxis = new LogarithmicAxis(getYaxis()); logAxis.setExpTickLabelsFlag(true); categoryPlot.setRangeAxis(logAxis); } // optionally exclude zero as default y-axis value ValueAxis rangeAxis = categoryPlot.getRangeAxis(); if ((rangeAxis != null) && (rangeAxis instanceof NumberAxis)) { if (hasYaxisMinimum()) { ((NumberAxis) rangeAxis).setLowerBound(getYaxisMinimum()); } if (hasYaxisMaximum()) { ((NumberAxis) rangeAxis).setUpperBound(getYaxisMaximum()); } ((NumberAxis) rangeAxis).setAutoRangeIncludesZero(!getExclZero()); } AbstractCategoryItemRenderer renderer = (AbstractCategoryItemRenderer) categoryPlot.getRenderer(); int numColors = dataset.getRowCount(); for (int i = 0; i < numColors; i++) { renderer.setSeriesPaint(i, new Color(Color.HSBtoRGB((1f / numColors) * i, 1f, 1f))); } renderer.setBaseStroke(new BasicStroke(2.0f)); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(Messages.Plot_Build() + " {1}: {2}", NumberFormat.getInstance())); renderer.setBaseItemURLGenerator(new PointURLGenerator()); if (renderer instanceof LineAndShapeRenderer) { String s = getUrlStyle(); LineAndShapeRenderer lasRenderer = (LineAndShapeRenderer) renderer; if ("lineSimple".equalsIgnoreCase(s)) { lasRenderer.setShapesVisible(false); // TODO: deprecated, may be unnecessary } else { lasRenderer.setShapesVisible(true); // TODO: deprecated, may be unnecessary } } }
From source file:edu.ucla.stat.SOCR.chart.demo.BoxAndWhiskerChartDemo2.java
/** * Creates a sample chart.//from w ww.j a v a 2 s. c om * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(BoxAndWhiskerCategoryDataset dataset) { CategoryAxis domainAxis = new CategoryAxis(null); NumberAxis rangeAxis = new NumberAxis(rangeLabel); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(chartTitle, plot); plot.setOrientation(PlotOrientation.HORIZONTAL); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setLegendItemLabelGenerator( new SOCRCategoryCellLabelGenerator(dataset, values_storage, SERIES_COUNT, CATEGORY_COUNT)); //columnCount -- category count //RowCount -- serie count domainAxis.setLowerMargin(0.44); domainAxis.setUpperMargin(0.44); if (dataset.getColumnCount() == 1) renderer.setItemMargin(0.5); // domainAxis.setCategoryMargin(domainAxis.getCategoryMargin()*2); /* System.out.println("1lowerMargin="+domainAxis.getLowerMargin()); System.out.println("ItemMargin="+renderer.getItemMargin()); System.out.println("CategoryMargin="+domainAxis.getCategoryMargin());*/ renderer.setItemMargin(renderer.getItemMargin() * 2); /*System.out.println("2lowerMargin="+domainAxis.getLowerMargin()); System.out.println("ItemMargin="+renderer.getItemMargin()); System.out.println("CategoryMargin="+domainAxis.getCategoryMargin());*/ return chart; }