List of usage examples for org.jfree.chart.axis CategoryAxis setCategoryMargin
public void setCategoryMargin(double margin)
From source file:org.pentaho.chart.plugin.jfreechart.chart.bar.JFreeBarChartGenerator.java
/** * This method allows to manipulate bar width indirectly by sepecifying percentages for lower margin, * upper margin, category margin and item margin. Definitions of these margins and how they effect bar width * are available in the JFreeChart documentation. * * @param chartDocument Current chart defintion * @param categoryPlot The plot object for the current chart *//*from w w w . j a va 2 s . c o m*/ private void setAxisMargins(final ChartDocument chartDocument, final CategoryPlot categoryPlot) { final ArrayList<ChartElement> axisElementsList = chartDocument.getAxisSeriesLinkInfo() .getDomainAxisElements(); if (axisElementsList != null) { for (final ChartElement axisElement : axisElementsList) { if (axisElement != null) { final String axisType = (String) axisElement.getAttribute("type");//$NON-NLS-1$ if (axisType != null && DOMAIN_AXIS.equalsIgnoreCase(axisType)) { final LayoutStyle layoutStyle = axisElement.getLayoutStyle(); final CSSValue lowerMarginValue = layoutStyle.getValue(ChartStyleKeys.MARGIN_LOWER); final CSSValue upperMarginValue = layoutStyle.getValue(ChartStyleKeys.MARGIN_UPPER); final CSSValue itemMarginValue = layoutStyle.getValue(ChartStyleKeys.MARGIN_ITEM); final CSSValue categoryMarginValue = layoutStyle.getValue(ChartStyleKeys.MARGIN_CATEGORY); // The lower, upper and category margins can be controlled through category axis final CategoryAxis categoryAxis = categoryPlot.getDomainAxis(); if (lowerMarginValue != null) { final double lowerMargin = ((CSSNumericValue) lowerMarginValue).getValue() / 100; categoryAxis.setLowerMargin(lowerMargin); } if (upperMarginValue != null) { final double upperMargin = ((CSSNumericValue) upperMarginValue).getValue() / 100; categoryAxis.setUpperMargin(upperMargin); } if (categoryMarginValue != null) { final double categoryMargin = ((CSSNumericValue) categoryMarginValue).getValue() / 100; categoryAxis.setCategoryMargin(categoryMargin); } if (itemMarginValue != null) { final double itemMargin = ((CSSNumericValue) itemMarginValue).getValue() / 100; final int datasetCount = categoryPlot.getDatasetCount(); for (int i = 0; i < datasetCount; i++) { if (categoryPlot.getRenderer() instanceof BarRenderer) { final BarRenderer barRenderer = (BarRenderer) categoryPlot.getRenderer(i); barRenderer.setItemMargin(itemMargin); } } } } } } } }
From source file:hudson.plugins.plot.PlotData.java
/** * Generates the plot and stores it in the plot instance variable. * //from ww w. j av a2s . 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:KIDLYFactory.java
/** * Creates a stacked area chart with default settings. The chart object * returned by this method uses a {@link CategoryPlot} instance as the * plot, with a {@link CategoryAxis} for the domain axis, a * {@link NumberAxis} as the range axis, and a {@link StackedAreaRenderer} * as the renderer.//from w w w .j a va2s . co m * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> not permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A stacked area chart. */ public static JFreeChart createStackedAreaChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); categoryAxis.setCategoryMargin(0.0); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); StackedAreaRenderer renderer = new StackedAreaRenderer(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:KIDLYFactory.java
/** * Creates an area chart with default settings. The chart object returned * by this method uses a {@link CategoryPlot} instance as the plot, with a * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the * range axis, and an {@link AreaRenderer} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted).//from w w w. j a v a 2s . c o m * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (<code>null</code> not * permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return An area chart. */ public static JFreeChart createAreaChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); categoryAxis.setCategoryMargin(0.0); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); AreaRenderer renderer = new AreaRenderer(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:KIDLYFactory.java
/** * Creates a waterfall chart. The chart object returned by this method * uses a {@link CategoryPlot} instance as the plot, with a * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the * range axis, and a {@link WaterfallBarRenderer} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted).//from w ww. j av a 2s.co m * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A waterfall chart. */ public static JFreeChart createWaterfallChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); categoryAxis.setCategoryMargin(0.0); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); WaterfallBarRenderer renderer = new WaterfallBarRenderer(); if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, Math.PI / 2.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseNegativeItemLabelPosition(position); } if (tooltips) { StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator(); renderer.setBaseToolTipGenerator(generator); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.clearRangeMarkers(); Marker baseline = new ValueMarker(0.0); baseline.setPaint(Color.black); plot.addRangeMarker(baseline, Layer.FOREGROUND); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:be.ugent.maf.cellmissy.gui.view.renderer.jfreechart.ExtendedBoxAndWhiskerRenderer.java
/** * Draws the visual representation of a single data item when the plot has a * vertical orientation.//w ww . j a va 2s . com * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the plot is being drawn. * @param plot the plot (can be used to obtain standard color information * etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param row the row index (zero-based). * @param column the column index (zero-based). */ @Override public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) { // do nothing if item is not visible if (!getItemVisible(row, column)) { return; } //Determine the catgory start and end. BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset; double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryWidth = categoryEnd - categoryStart; domainAxis.setCategoryMargin(0.25); rangeAxis.setUpperMargin(0.3); rangeAxis.setLowerMargin(0.3); double xx = categoryStart; int seriesCount = getRowCount(); int categoryCount = getColumnCount(); if (seriesCount > 1) { double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); double usedWidth = (state.getBarWidth() * seriesCount) + (seriesGap * (seriesCount - 1)); // offset the start of the boxes if the total width used is smaller // than the category width double offset = (categoryWidth - usedWidth) / 2; xx = xx + offset + (row * (state.getBarWidth() + seriesGap)); } else { // offset the start of the box if the box width is smaller than the category width double offset = (categoryWidth - state.getBarWidth()) / 2; xx = xx + offset; } double xxmid = xx + state.getBarWidth() / 2.0; //Draw the box. Paint p = getItemPaint(row, column); if (p != null) { g2.setPaint(p); } Stroke s = getItemStroke(row, column); g2.setStroke(s); RectangleEdge location = plot.getRangeAxisEdge(); Shape box = null; Number yQ1 = bawDataset.getQ1Value(row, column); Number yQ3 = bawDataset.getQ3Value(row, column); Number yMax = bawDataset.getMaxRegularValue(row, column); Number yMin = bawDataset.getMinRegularValue(row, column); if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) { double yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea, location); double yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea, location); double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location); double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location); // set the paint according to the right technical replicate int length = GuiUtils.getAvailableColors().length; int colorIndex = row % length; Color color = GuiUtils.getAvailableColors()[colorIndex]; g2.setPaint(color); // draw the upper whisker g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3)); g2.draw(new Line2D.Double(xx, yyMax, xx + state.getBarWidth(), yyMax)); // draw the lower whisker g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1)); g2.draw(new Line2D.Double(xx, yyMin, xx + state.getBarWidth(), yyMin)); // draw the body box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), state.getBarWidth(), Math.abs(yyQ1 - yyQ3)); g2.setPaint(new Color(color.getRed(), color.getGreen(), color.getBlue(), 175)); // if (getFillBox()) { // g2.fill(box); // } g2.draw(box); } // draw mean g2.setPaint(getArtifactPaint()); double yyAverage = 0.0; double aRadius = 2.0; // mean radius Number yMean = bawDataset.getMeanValue(row, column); if (yMean != null) { yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location); Ellipse2D.Double avgEllipse = new Ellipse2D.Double((xxmid - aRadius), (yyAverage - aRadius), aRadius * 2, aRadius * 2); g2.draw(avgEllipse); } //draw median double yyMedian = 0.0; Number yMedian = bawDataset.getMedianValue(row, column); if (yMedian != null) { yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location); g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian)); } //Outliers and Farouts double oRadius = 2.0; //outlier radius double foRadius = 1.0; //farout radius // From outlier array sort out which are outliers and put these into a // list. If there are any farouts, add them to the farout list. // draw the outliers and farouts only if they are within the data area. double yyOutlier; double yyFarout; List outliers = new ArrayList(); List farOutValues = new ArrayList(); List yOutliers = bawDataset.getOutliers(row, column); if (yOutliers != null) { for (int i = 0; i < yOutliers.size(); i++) { Number outlierNum = (Number) yOutliers.get(i); double outlier = outlierNum.doubleValue(); Number minOutlier = bawDataset.getMinOutlier(row, column); Number maxOutlier = bawDataset.getMaxOutlier(row, column); Number minRegular = bawDataset.getMinRegularValue(row, column); Number maxRegular = bawDataset.getMaxRegularValue(row, column); if (outlier > maxOutlier.doubleValue() || outlier < minOutlier.doubleValue()) { yyFarout = rangeAxis.valueToJava2D(outlier, dataArea, location); Outlier faroutToAdd = new Outlier(xxmid, yyFarout, foRadius); if (dataArea.contains(faroutToAdd.getPoint())) { farOutValues.add(faroutToAdd); } } else if (outlier > maxRegular.doubleValue() || outlier < minRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); Outlier outlierToAdd = new Outlier(xxmid, yyOutlier, oRadius); if (dataArea.contains(outlierToAdd.getPoint())) { outliers.add(outlierToAdd); } } } //draw the outliers g2.setPaint(this.outlierPaint); for (Iterator iterator = outliers.iterator(); iterator.hasNext();) { Outlier outlier = (Outlier) iterator.next(); Point2D point = outlier.getPoint(); Shape dot = createEllipse(point, oRadius); g2.draw(dot); } //draw the farout values g2.setPaint(this.farOutColor); for (Iterator iterator = farOutValues.iterator(); iterator.hasNext();) { Outlier outlier = (Outlier) iterator.next(); Point2D point = outlier.getPoint(); Shape triangle = createTriangleVertical(point, foRadius); g2.draw(triangle); } } }
From source file:hudson.plugins.plot.Plot.java
/** * Generates the plot and stores it in the plot instance variable. * * @param forceGenerate/* www. ja va 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:msi.gama.outputs.layers.ChartLayerStatement.java
/** * create dataset for box_whisker chart// w ww .ja va2s . c o m * @return A sample dataset. */ private BoxAndWhiskerCategoryDataset createWhisker(final IScope scope) { final CategoryPlot plot = (CategoryPlot) chart.getPlot(); // final int seriesCount = 1; final int categoryCount = 3; final int entityCount = 2; final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); for (int i = 0; i < datas.size(); i++) { // ChartData e = datas.get(i); for (int j = 0; j < categoryCount; j++) { final List list = new ArrayList(); // add some values... for (int k = 0; k < entityCount; k++) { // list.add(new Double(k*2)); // list.add(new Double(k*3)); final double value1 = 10.0 + Math.random() * 3; list.add(new Double(value1)); final double value2 = 11.25 + Math.random(); // concentrate values in the middle list.add(new Double(value2)); } dataset.add(list, "Series " + i, " Type " + j); history.append("Series " + i); history.append(','); } } history.deleteCharAt(history.length() - 1); history.append(Strings.LN); plot.setDataset(dataset); chart.removeLegend(); final CategoryAxis axis = plot.getDomainAxis(); axis.setTickLabelFont(getTickFont()); axis.setLabelFont(getLabelFont()); // ((BarRenderer3D) plot.getRenderer()).setItemMargin(0.1); axis.setCategoryMargin(0.1); axis.setUpperMargin(0.05); axis.setLowerMargin(0.05); return dataset; }
From source file:msi.gama.outputs.layers.ChartLayerStatement.java
private void createBars(final IScope scope) { final CategoryPlot plot = (CategoryPlot) chart.getPlot(); BarRenderer renderer = new CustomRenderer(); plot.setRenderer(renderer);/*w w w . j a v a 2 s. co m*/ dataset = new DefaultCategoryDataset(); int i = 0; for (final ChartData e : datas) { // String legend = e.getName(); // ((DefaultCategoryDataset) dataset).setValue(0d, new Integer(0), legend/* , legend */); final String legend = e.getName(); if (!CategoryItemRenderer.class.isInstance(e.getRenderer())) { e.renderer = new CustomRenderer(); } plot.setRenderer(i, (CategoryItemRenderer) e.getRenderer(), false); final Color c = e.getColor(); plot.getRenderer(i).setSeriesPaint(0, c); // plot.setDataset(i, (DefaultCategoryDataset) dataset); i++; history.append(legend); history.append(','); } if (history.length() > 0) { history.deleteCharAt(history.length() - 1); } history.append(Strings.LN); plot.setDataset((DefaultCategoryDataset) dataset); chart.removeLegend(); final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setTickLabelFont(getTickFont()); yAxis.setLabelFont(getLabelFont()); IExpression expr = getFacet(YRANGE); IExpression expr2 = getFacet(YTICKUNIT); if (expr != null) { Object range = expr.value(scope); // Double range = Cast.asFloat(scope, expr.value(scope)); if (range instanceof Number) { double r = ((Number) range).doubleValue(); if (r > 0) { yAxis.setFixedAutoRange(r); yAxis.setAutoRangeMinimumSize(r); } // yAxis.setAutoRangeIncludesZero(false); } else if (range instanceof GamaPoint) { yAxis.setRange(((GamaPoint) range).getX(), ((GamaPoint) range).getY()); } } if (expr2 != null) { Object range = expr2.value(scope); // Double range = Cast.asFloat(scope, expr.value(scope)); if (range instanceof Number) { double r = ((Number) range).doubleValue(); if (r > 0) { yAxis.setTickUnit(new NumberTickUnit(r)); } } } final CategoryAxis axis = plot.getDomainAxis(); Double gap = Cast.asFloat(scope, getFacetValue(scope, IKeyword.GAP, 0.01)); // ((BarRenderer) plot.getRenderer()).setItemMargin(gap); renderer.setMaximumBarWidth(1 - gap); axis.setCategoryMargin(gap); axis.setUpperMargin(gap); axis.setLowerMargin(gap); }
From source file:com.googlecode.logVisualizer.chart.HorizontalIntervallBarChartBuilder.java
private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart(getTitle(), xLable, yLable, dataset, PlotOrientation.HORIZONTAL, isIncludeLegend(), true, false); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); final CategoryAxis categoryAxis = plot.getDomainAxis(); final LayeredBarRenderer renderer = new LayeredBarRenderer(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinePaint(Color.black); setBarShadowVisible(chart, false);// w w w . j a v a 2s.c o m plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getRangeAxis().setLowerBound(-35); plot.getRangeAxis().setUpperBound(35); renderer.setDrawBarOutline(false); renderer.setSeriesPaint(0, Color.blue); renderer.setSeriesPaint(1, Color.green); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER)); renderer.setSeriesPositiveItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE2, TextAnchor.CENTER)); renderer.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER)); renderer.setSeriesNegativeItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.CENTER)); renderer.setItemLabelAnchorOffset(9.0); renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance())); plot.setRenderer(renderer); plot.setRowRenderingOrder(SortOrder.DESCENDING); categoryAxis.setCategoryMargin(0.15); categoryAxis.setUpperMargin(0.0175); categoryAxis.setLowerMargin(0.0175); return chart; }