Java 类org.jfree.chart.axis.CategoryAxis 实例源码

项目:parabuild-ci    文件:IntervalBarRenderer.java   
/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @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).
 */
public void drawItem(Graphics2D g2,
                     CategoryItemRendererState state,
                     Rectangle2D dataArea,
                     CategoryPlot plot,
                     CategoryAxis domainAxis,
                     ValueAxis rangeAxis,
                     CategoryDataset dataset,
                     int row,
                     int column) {

     if (dataset instanceof IntervalCategoryDataset) {
         IntervalCategoryDataset d = (IntervalCategoryDataset) dataset;
         drawInterval(g2, state, dataArea, plot, domainAxis, rangeAxis, d, row, column);
     }
     else {
         super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column);
     } 

 }
项目:parabuild-ci    文件:StackedBarRenderer3D.java   
/**
 * Calculates the bar width and stores it in the renderer state.
 * 
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
protected void calculateBarWidth(CategoryPlot plot, 
                                 Rectangle2D dataArea, 
                                 int rendererIndex,
                                 CategoryItemRendererState state) {

    // calculate the bar width
    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset data = plot.getDataset(rendererIndex);
    if (data != null) {
        PlotOrientation orientation = plot.getOrientation();
        double space = 0.0;
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaxBarWidth();
        int columns = data.getColumnCount();
        double categoryMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }

        double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin()
                                 - categoryMargin);
        if (columns > 0) {
            state.setBarWidth(Math.min(used / columns, maxWidth));
        }
        else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }

}
项目:parabuild-ci    文件:GanttRenderer.java   
/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @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).
 */
public void drawItem(Graphics2D g2,
                     CategoryItemRendererState state,
                     Rectangle2D dataArea,
                     CategoryPlot plot,
                     CategoryAxis domainAxis,
                     ValueAxis rangeAxis,
                     CategoryDataset dataset,
                     int row,
                     int column) {

     if (dataset instanceof GanttCategoryDataset) {
         GanttCategoryDataset gcd = (GanttCategoryDataset) dataset;
         drawTasks(g2, state, dataArea, plot, domainAxis, rangeAxis, gcd, row, column);
     }
     else {  // let the superclass handle it...
         super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column);
     }

 }
项目:parabuild-ci    文件:LevelRenderer.java   
/**
 * Calculates the bar width and stores it in the renderer state.
 * 
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
protected void calculateItemWidth(CategoryPlot plot, 
                                  Rectangle2D dataArea, 
                                  int rendererIndex,
                                  CategoryItemRendererState state) {

    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaxItemWidth();
        double categoryMargin = 0.0;
        double currentItemMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        if (rows > 1) {
            currentItemMargin = getItemMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin()
                                 - categoryMargin - currentItemMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(Math.min(used / (rows * columns), maxWidth));
        }
        else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
}
项目:parabuild-ci    文件:LayeredBarRenderer.java   
/**
 * Draws the bar for one item in the dataset.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain (category) axis.
 * @param rangeAxis  the range (value) axis.
 * @param data  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 */
public void drawItem(Graphics2D g2,
                     CategoryItemRendererState state,
                     Rectangle2D dataArea,
                     CategoryPlot plot,
                     CategoryAxis domainAxis,
                     ValueAxis rangeAxis,
                     CategoryDataset data,
                     int row,
                     int column) {

    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        drawHorizontalItem(g2, state, dataArea,
                           plot, domainAxis, rangeAxis, data, row, column);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        drawVerticalItem(g2, state, dataArea,
                         plot, domainAxis, rangeAxis, data, row, column);
    }

}
项目:parabuild-ci    文件:CombinedDomainCategoryPlotTests.java   
/**
 * Creates a sample plot.
 * 
 * @return A sample plot.
 */
private CombinedDomainCategoryPlot createPlot() {

    CategoryDataset dataset1 = createDataset1();
    NumberAxis rangeAxis1 = new NumberAxis("Value");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
    subplot1.setDomainGridlinesVisible(true);

    CategoryDataset dataset2 = createDataset2();
    NumberAxis rangeAxis2 = new NumberAxis("Value");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
    subplot2.setDomainGridlinesVisible(true);

    CategoryAxis domainAxis = new CategoryAxis("Category");
    CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
    plot.add(subplot1, 2);
    plot.add(subplot2, 1);
    return plot;

}
项目:parabuild-ci    文件:CombinedDomainCategoryPlot.java   
/**
 * Adds a subplot to the combined chart and sends a {@link PlotChangeEvent} to all
 * registered listeners.
 *
 * @param subplot  the subplot (<code>null</code> not permitted).
 * @param weight  the weight (must be >= 1).
 */
public void add(CategoryPlot subplot, int weight) {
    if (subplot == null) {
        throw new IllegalArgumentException("Null 'subplot' argument.");
    }
    if (weight < 1) {
        throw new IllegalArgumentException("Require weight >= 1.");
    }
    subplot.setParent(this);
    subplot.setWeight(weight);
    subplot.setInsets(new Insets(0, 0, 0, 0));
    subplot.setDomainAxis(null);
    subplot.setOrientation(getOrientation());
    subplot.addChangeListener(this);
    this.subplots.add(subplot);
    this.totalWeight += weight;
    CategoryAxis axis = getDomainAxis();
    if (axis != null) {
        axis.configure();
    }
    notifyListeners(new PlotChangeEvent(this));
}
项目:parabuild-ci    文件:CategoryPlot.java   
/**
 * Sets a domain axis.
 *
 * @param index  the axis index.
 * @param axis  the axis.
 */
public void setDomainAxis(int index, CategoryAxis axis) {

    CategoryAxis existing = (CategoryAxis) this.domainAxes.get(index);
    if (existing != null) {
        existing.removeChangeListener(this);
    }

    if (axis != null) {
        axis.setPlot(this);
    }

    this.domainAxes.set(index, axis);
    if (axis != null) {
        axis.configure();
        axis.addChangeListener(this);
    }
    notifyListeners(new PlotChangeEvent(this));

}
项目:parabuild-ci    文件:GroupedStackedBarRendererTests.java   
/**
 * Draws the chart with a <code>null</code> info object to make sure that 
 * no exceptions are thrown (particularly by code in the renderer).
 */
public void testDrawWithNullInfo() {
    boolean success = false;
    try {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(1.0, "S1", "C1");
        dataset.addValue(2.0, "S1", "C2");
        dataset.addValue(3.0, "S2", "C1");
        dataset.addValue(4.0, "S2", "C2");
        GroupedStackedBarRenderer renderer 
            = new GroupedStackedBarRenderer();
        CategoryPlot plot = new CategoryPlot(dataset, 
                new CategoryAxis("Category"), new NumberAxis("Value"), 
                renderer);
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200, 
                null);
        success = true;
    }
    catch (NullPointerException e) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}
项目:parabuild-ci    文件:LevelRendererTests.java   
/**
 * Draws the chart with a <code>null</code> info object to make sure that 
 * no exceptions are thrown (particularly by code in the renderer).
 */
public void testDrawWithNullInfo() {
    boolean success = false;
    try {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(1.0, "S1", "C1");
        CategoryPlot plot = new CategoryPlot(dataset, 
                new CategoryAxis("Category"), new NumberAxis("Value"), 
                new LevelRenderer());
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200, 
                null);
        success = true;
    }
    catch (NullPointerException e) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}
项目:parabuild-ci    文件:BoxAndWhiskerRendererTests.java   
/**
 * Draws the chart with a <code>null</code> info object to make sure that 
 * no exceptions are thrown (particularly by code in the renderer).
 */
public void testDrawWithNullInfo() {
    boolean success = false;
    try {
        DefaultBoxAndWhiskerCategoryDataset dataset 
            = new DefaultBoxAndWhiskerCategoryDataset();
        dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0),
                new Double(0.0), new Double(4.0), new Double(0.5), 
                new Double(4.5), new Double(-0.5), new Double(5.5), 
                null), "S1", "C1");
        CategoryPlot plot = new CategoryPlot(dataset, 
                new CategoryAxis("Category"), new NumberAxis("Value"), 
                new BoxAndWhiskerRenderer());
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200, 
                null);
        success = true;
    }
    catch (NullPointerException e) {
        success = false;
    }
    assertTrue(success);
}
项目:parabuild-ci    文件:CategoryPlot.java   
/**
 * Draws the domain markers (if any) for an axis and layer.  This method is 
 * typically called from within the draw() method.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param index  the renderer index.
 * @param layer  the layer (foreground or background).
 * 
 * @see #drawRangeMarkers(Graphics2D, Rectangle2D, int, Layer)
 */
protected void drawDomainMarkers(Graphics2D g2, Rectangle2D dataArea, 
                                 int index, Layer layer) {

    CategoryItemRenderer r = getRenderer(index);
    if (r == null) {
        return;
    }

    Collection markers = getDomainMarkers(index, layer);
    CategoryAxis axis = getDomainAxisForDataset(index);
    if (markers != null && axis != null) {
        Iterator iterator = markers.iterator();
        while (iterator.hasNext()) {
            CategoryMarker marker = (CategoryMarker) iterator.next();
            r.drawDomainMarker(g2, this, axis, marker, dataArea);
        }
    }

}
项目:parabuild-ci    文件:StatisticalBarRendererTests.java   
/**
 * Draws the chart with a <code>null</code> info object to make sure that 
 * no exceptions are thrown (particularly by code in the renderer).
 */
public void testDrawWithNullInfo() {
    boolean success = false;
    try {
        DefaultStatisticalCategoryDataset dataset 
            = new DefaultStatisticalCategoryDataset();
        dataset.add(1.0, 2.0, "S1", "C1");
        dataset.add(3.0, 4.0, "S1", "C2");
        CategoryPlot plot = new CategoryPlot(dataset, 
                new CategoryAxis("Category"), new NumberAxis("Value"), 
                new StatisticalBarRenderer());
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200, 
                null);
        success = true;
    }
    catch (NullPointerException e) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}
项目:parabuild-ci    文件:IntervalBarRendererTests.java   
/**
 * Draws the chart with a <code>null</code> info object to make sure that 
 * no exceptions are thrown (particularly by code in the renderer).
 */
public void testDrawWithNullInfo() {
    boolean success = false;
    try {
        double[][] starts = new double[][] {{0.1, 0.2, 0.3}, 
                {0.3, 0.4, 0.5}};
        double[][] ends = new double[][] {{0.5, 0.6, 0.7}, {0.7, 0.8, 0.9}};
        DefaultIntervalCategoryDataset dataset 
            = new DefaultIntervalCategoryDataset(starts, ends);        
        IntervalBarRenderer renderer = new IntervalBarRenderer();
        CategoryPlot plot = new CategoryPlot(dataset, 
                new CategoryAxis("Category"), new NumberAxis("Value"), 
                renderer);
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200, 
                null);
        success = true;
    }
    catch (NullPointerException e) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}
项目:parabuild-ci    文件:MinMaxCategoryRendererTests.java   
/**
 * Draws the chart with a <code>null</code> info object to make sure that 
 * no exceptions are thrown (particularly by code in the renderer).
 */
public void testDrawWithNullInfo() {
    boolean success = false;
    try {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(1.0, "S1", "C1");
        CategoryPlot plot = new CategoryPlot(dataset, 
                new CategoryAxis("Category"), new NumberAxis("Value"), 
                new MinMaxCategoryRenderer());
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200, 
                null);
        success = true;
    }
    catch (NullPointerException e) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}
项目:parabuild-ci    文件:LayeredBarRendererTests.java   
/**
 * Draws the chart with a <code>null</code> info object to make sure that 
 * no exceptions are thrown (particularly by code in the renderer).
 */
public void testDrawWithNullInfo() {
    boolean success = false;
    try {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(1.0, "S1", "C1");
        CategoryPlot plot = new CategoryPlot(dataset, 
                new CategoryAxis("Category"), new NumberAxis("Value"), 
                new LayeredBarRenderer());
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200, 
                null);
        success = true;
    }
    catch (NullPointerException e) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}
项目:parabuild-ci    文件:CombinedDomainCategoryPlot.java   
/**
 * Adds a subplot to the combined chart and sends a {@link PlotChangeEvent}
 * to all registered listeners.
 * <br><br>
 * The domain axis for the subplot will be set to <code>null</code>.  You
 * must ensure that the subplot has a non-null range axis.
 *
 * @param subplot  the subplot (<code>null</code> not permitted).
 * @param weight  the weight (must be >= 1).
 */
public void add(CategoryPlot subplot, int weight) {
    if (subplot == null) {
        throw new IllegalArgumentException("Null 'subplot' argument.");
    }
    if (weight < 1) {
        throw new IllegalArgumentException("Require weight >= 1.");
    }
    subplot.setParent(this);
    subplot.setWeight(weight);
    subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    subplot.setDomainAxis(null);
    subplot.setOrientation(getOrientation());
    subplot.addChangeListener(this);
    this.subplots.add(subplot);
    this.totalWeight += weight;
    CategoryAxis axis = getDomainAxis();
    if (axis != null) {
        axis.configure();
    }
    notifyListeners(new PlotChangeEvent(this));
}
项目:parabuild-ci    文件:ChartFactory.java   
/**
 * Creates and returns a default instance of a box and whisker chart
 * based on data from a {@link BoxAndWhiskerCategoryDataset}.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel  a label for the category axis 
 *     (<code>null</code> permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code> 
 *     permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A box and whisker chart.
 * 
 * @since 1.0.4
 */
public static JFreeChart createBoxAndWhiskerChart(String title,
        String categoryAxisLabel, String valueAxisLabel,
        BoxAndWhiskerCategoryDataset dataset, boolean legend) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);

    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 
            renderer);
    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, 
            legend);
}
项目:parabuild-ci    文件:CategoryPlot.java   
/**
 * Sets a domain axis and, if requested, sends a {@link PlotChangeEvent} to 
 * all registered listeners.
 *
 * @param index  the axis index.
 * @param axis  the axis (<code>null</code> permitted).
 * @param notify  notify listeners?
 */
public void setDomainAxis(int index, CategoryAxis axis, boolean notify) {
    CategoryAxis existing = (CategoryAxis) this.domainAxes.get(index);
    if (existing != null) {
        existing.removeChangeListener(this);
    }
    if (axis != null) {
        axis.setPlot(this);
    }
    this.domainAxes.set(index, axis);
    if (axis != null) {
        axis.configure();
        axis.addChangeListener(this);
    }
    if (notify) {
        notifyListeners(new PlotChangeEvent(this));
    }
}
项目:parabuild-ci    文件:GanttRenderer.java   
/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @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).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2,
                     CategoryItemRendererState state,
                     Rectangle2D dataArea,
                     CategoryPlot plot,
                     CategoryAxis domainAxis,
                     ValueAxis rangeAxis,
                     CategoryDataset dataset,
                     int row,
                     int column,
                     int pass) {

     if (dataset instanceof GanttCategoryDataset) {
         GanttCategoryDataset gcd = (GanttCategoryDataset) dataset;
         drawTasks(g2, state, dataArea, plot, domainAxis, rangeAxis, gcd, 
                 row, column);
     }
     else {  // let the superclass handle it...
         super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, 
                 dataset, row, column, pass);
     }

 }
项目:parabuild-ci    文件:LayeredBarRenderer.java   
/**
 * Draws the bar for one item in the dataset.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain (category) axis.
 * @param rangeAxis  the range (value) axis.
 * @param data  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2,
                     CategoryItemRendererState state,
                     Rectangle2D dataArea,
                     CategoryPlot plot,
                     CategoryAxis domainAxis,
                     ValueAxis rangeAxis,
                     CategoryDataset data,
                     int row,
                     int column,
                     int pass) {

    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        drawHorizontalItem(g2, state, dataArea, plot, domainAxis, rangeAxis, 
            data, row, column);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        drawVerticalItem(g2, state, dataArea, plot, domainAxis, rangeAxis, 
            data, row, column);
    }

}
项目:financehelper    文件:BarChart.java   
public BarChart() {
    CategoryDataset dataset = getDataSet();
    JFreeChart chart = ChartFactory.createBarChart3D(
            "水果", // 图表标题
            "水果种类", // 目录轴的显示标签
            "数量", // 数值轴的显示标签
            dataset, // 数据集
            PlotOrientation.VERTICAL, // 图表方向:水平、垂直
            true,           // 是否显示图例(对于简单的柱状图必须是false)
            false,          // 是否生成工具
            false           // 是否生成URL链接
    );

    //从这里开始
    CategoryPlot plot = chart.getCategoryPlot();//获取图表区域对象
    CategoryAxis domainAxis = plot.getDomainAxis();         //水平底部列表
    domainAxis.setLabelFont(new Font("黑体", Font.BOLD, 14));         //水平底部标题
    domainAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 12));  //垂直标题
    ValueAxis rangeAxis = plot.getRangeAxis();//获取柱状
    rangeAxis.setLabelFont(new Font("黑体", Font.BOLD, 15));
    chart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 15));
    chart.getTitle().setFont(new Font("宋体", Font.BOLD, 20));//设置标题字体

    //到这里结束,虽然代码有点多,但只为一个目的,解决汉字乱码问题

    frame1 = new ChartPanel(chart, true);        //这里也可以用chartFrame,可以直接生成一个独立的Frame

}
项目:parabuild-ci    文件:CodeAnalysisChartGenerator.java   
public void createChart(final SortedMap stats, final OutputStream out) throws IOException {

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (final Iterator iter = stats.entrySet().iterator(); iter.hasNext();) {
      final Map.Entry entry = (Map.Entry)iter.next();
      final Integer buildNumber = (Integer)entry.getKey();
      final Integer violations = (Integer)entry.getValue();
      dataset.addValue(violations, categoryDescription, buildNumber);
    }

    // create the chart object

    // This generates a stacked bar - more suitable
    final JFreeChart chart = ChartFactory.createLineChart(null,
      "Recent builds", valueAxisLabel, dataset,
      PlotOrientation.VERTICAL,
      true, false, false);
    chart.setBackgroundPaint(Color.white);

    // change the auto tick unit selection to integer units only
    final CategoryPlot plot = chart.getCategoryPlot();
    final NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // rotate X dates
    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    // set bar colors

    final LineAndShapeRenderer line = (LineAndShapeRenderer)plot.getRenderer();
    line.setSeriesPaint(0, Color.RED);
    line.setStroke(StatisticsUtils.DEFAULT_LINE_STROKE);

    // write to reposnce
    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    ChartUtilities.writeChartAsPNG(out, chart, StatisticsUtils.IMG_WIDTH, StatisticsUtils.IMG_HEIGHT, info);
  }
项目:Proyecto-DASI    文件:VisualizacionJfreechart.java   
void crearChartCombinadoAsignRescateVict(CategoryDataset dataset1,CategoryDataset dataset2) {

//        CategoryDataset dataset1 = createDataset1();
        NumberAxis rangeAxis1 = new NumberAxis("Tiempos en milisegundos");
        rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
        renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
        CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
        subplot1.setDomainGridlinesVisible(true);
//        CategoryDataset dataset2 = createDataset2();
        NumberAxis rangeAxis2 = new NumberAxis("Unidades de energ�a");
        rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        BarRenderer renderer2 = new BarRenderer();
        renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
        CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
        subplot2.setDomainGridlinesVisible(true);
        CategoryAxis domainAxis = new CategoryAxis("Victimas ordenadas por tiempos de rescate");
        CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
        plot.add(subplot1, 2);
        plot.add(subplot2, 1);
        JFreeChart result = new JFreeChart(
        "Tiempos de Rescate y Energ�a consumida para salvar las victimas",
        new Font("SansSerif", Font.BOLD, 12),
        plot,
        true
        );
        ChartPanel chartPanel = new ChartPanel(result);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        this.visualizar(chartPanel);
//        setContentPane(chartPanel);
//        this.pack();
//        RefineryUtilities.centerFrameOnScreen(this);
//        this.setVisible(true);
     }
项目:parabuild-ci    文件:CategoryPlot.java   
/**
 * Draws the gridlines for the plot.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * 
 * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea) {

    // draw the domain grid lines, if any...
    if (isDomainGridlinesVisible()) {
        CategoryAnchor anchor = getDomainGridlinePosition();
        RectangleEdge domainAxisEdge = getDomainAxisEdge();
        Stroke gridStroke = getDomainGridlineStroke();
        Paint gridPaint = getDomainGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            // iterate over the categories
            CategoryDataset data = getDataset();
            if (data != null) {
                CategoryAxis axis = getDomainAxis();
                if (axis != null) {
                    int columnCount = data.getColumnCount();
                    for (int c = 0; c < columnCount; c++) {
                        double xx = axis.getCategoryJava2DCoordinate(
                                anchor, c, columnCount, dataArea, 
                                domainAxisEdge);
                        CategoryItemRenderer renderer1 = getRenderer();
                        if (renderer1 != null) {
                            renderer1.drawDomainGridline(g2, this, 
                                    dataArea, xx);
                        }
                    }
                }
            }
        }
    }
}
项目:parabuild-ci    文件:ChartFactory.java   
/**
 * Creates a bar chart with a 3D effect.
 * <P>
 * The chart object returned by this method uses a {@link CategoryPlot} instance as the
 * plot, with a {@link CategoryAxis3D} for the domain axis, a {@link NumberAxis3D} as the
 * range axis, and a {@link BarRenderer3D} 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).
 * @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 bar chart with a 3D effect.
 */
public static JFreeChart createBarChart3D(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 CategoryAxis3D(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);

    BarRenderer3D renderer = new BarRenderer3D();
    if (tooltips) {
        renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setItemURLGenerator(new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    if (orientation == PlotOrientation.HORIZONTAL) {
        // change rendering order to ensure that bar overlapping is the right way around
        plot.setRowRenderingOrder(SortOrder.DESCENDING);
        plot.setColumnRenderingOrder(SortOrder.DESCENDING);
    }
    plot.setForegroundAlpha(0.75f);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}
项目:parabuild-ci    文件:ChartFactory.java   
/**
 * Creates a stacked bar chart with a 3D effect and default settings.
 * <P>
 * The chart object returned by this method uses a {@link CategoryPlot} instance as the
 * plot, with a {@link CategoryAxis3D} for the domain axis, a {@link NumberAxis3D} as the
 * range axis, and a {@link StackedBarRenderer3D} 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).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the 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 bar chart with a 3D effect.
 */
public static JFreeChart createStackedBarChart3D(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 CategoryAxis3D(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);

    // create the renderer...
    CategoryItemRenderer renderer = new StackedBarRenderer3D();
    if (tooltips) {
        renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setItemURLGenerator(new StandardCategoryURLGenerator());
    }

    // create the plot...
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    if (orientation == PlotOrientation.HORIZONTAL) {
        // change rendering order to ensure that bar overlapping is the right way around
        plot.setColumnRenderingOrder(SortOrder.DESCENDING);
    }

    // create the chart...
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}
项目:parabuild-ci    文件:ChartFactory.java   
/**
 * Creates an area chart with default settings.
 * <P>
 * 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).
 * @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.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setItemURLGenerator(new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}
项目:parabuild-ci    文件:ChartFactory.java   
/**
 * Creates a stacked area chart with default settings.
 * <P>
 * 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.
 *
 * @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);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    StackedAreaRenderer renderer = new StackedAreaRenderer();
    if (tooltips) {
        renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setItemURLGenerator(new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}
项目:parabuild-ci    文件:ChartFactory.java   
/**
 * Creates a line chart with default settings.
 * <P>
 * 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 LineAndShapeRenderer} 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).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the chart 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 line chart.
 */
public static JFreeChart createLineChart(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);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    LineAndShapeRenderer renderer = new LineAndShapeRenderer();
    renderer.setDrawLines(true);
    renderer.setDrawShapes(false);
    if (tooltips) {
        renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setItemURLGenerator(new StandardCategoryURLGenerator());
    }
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}
项目:parabuild-ci    文件:CategoryPlot.java   
/**
 * Clears the domain axes from the plot and sends a {@link PlotChangeEvent}
 * to all registered listeners.
 */
public void clearDomainAxes() {
    for (int i = 0; i < this.domainAxes.size(); i++) {
        CategoryAxis axis = (CategoryAxis) this.domainAxes.get(i);
        if (axis != null) {
            axis.removeChangeListener(this);
        }
    }
    this.domainAxes.clear();
    notifyListeners(new PlotChangeEvent(this));
}
项目:parabuild-ci    文件:StackedBarRenderer.java   
/**
 * Calculates the bar width and stores it in the renderer state.
 * 
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
protected void calculateBarWidth(CategoryPlot plot, 
                                 Rectangle2D dataArea, 
                                 int rendererIndex,
                                 CategoryItemRendererState state) {

    // calculate the bar width
    CategoryAxis xAxis = plot.getDomainAxisForDataset(rendererIndex);
    CategoryDataset data = plot.getDataset(rendererIndex);
    if (data != null) {
        PlotOrientation orientation = plot.getOrientation();
        double space = 0.0;
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumBarWidth();
        int columns = data.getColumnCount();
        double categoryMargin = 0.0;
        if (columns > 1) {
            categoryMargin = xAxis.getCategoryMargin();
        }

        double used = space * (1 - xAxis.getLowerMargin() 
                                 - xAxis.getUpperMargin()
                                 - categoryMargin);
        if (columns > 0) {
            state.setBarWidth(Math.min(used / columns, maxWidth));
        }
        else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }

}
项目:parabuild-ci    文件:StatisticalBarRenderer.java   
/**
 * Draws the bar with its standard deviation line range for a single (series, category) data
 * item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param data  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 */
public void drawItem(Graphics2D g2,
                     CategoryItemRendererState state,
                     Rectangle2D dataArea,
                     CategoryPlot plot,
                     CategoryAxis domainAxis,
                     ValueAxis rangeAxis,
                     CategoryDataset data,
                     int row,
                     int column) {


    // defensive check
    if (!(data instanceof StatisticalCategoryDataset)) {
        throw new IllegalArgumentException("StatisticalBarRenderer.drawCategoryItem()"
            + " : the data should be of type StatisticalCategoryDataset only.");
    }
    StatisticalCategoryDataset statData = (StatisticalCategoryDataset) data;

    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        drawHorizontalItem(g2, state, dataArea, plot, domainAxis, rangeAxis, statData, 
                           row, column);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        drawVerticalItem(g2, state, dataArea, plot, domainAxis, rangeAxis, statData, 
                         row, column);
    }
}
项目:parabuild-ci    文件:LevelRenderer.java   
/**
 * Calculates the coordinate of the first "side" of a bar.  This will be the minimum 
 * x-coordinate for a vertical bar, and the minimum y-coordinate for a horizontal bar.
 * 
 * @param plot  the plot.
 * @param orientation  the plot orientation.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param state  the renderer state (has the bar width precalculated).
 * @param row  the row index.
 * @param column  the column index.
 * 
 * @return the coordinate.
 */
protected double calculateBarW0(CategoryPlot plot, 
                                PlotOrientation orientation, 
                                Rectangle2D dataArea,
                                CategoryAxis domainAxis,
                                CategoryItemRendererState state,
                                int row,
                                int column) {
    // calculate bar width...
    double space = 0.0;
    if (orientation == PlotOrientation.HORIZONTAL) {
        space = dataArea.getHeight();
    }
    else {
        space = dataArea.getWidth();
    }
    double barW0 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea,
                                               plot.getDomainAxisEdge());
    int seriesCount = getRowCount();
    int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        double seriesGap = space * getItemMargin() / (categoryCount * (seriesCount - 1));
        double seriesW = calculateSeriesWidth(space, domainAxis, categoryCount, seriesCount);
        barW0 = barW0 + row * (seriesW + seriesGap) 
                      + (seriesW / 2.0) - (state.getBarWidth() / 2.0);
    }
    else {
        barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea,
                                             plot.getDomainAxisEdge())
                - state.getBarWidth() / 2.0;
    }
    return barW0;
}
项目:parabuild-ci    文件:BarRenderer.java   
/**
 * Calculates the bar width and stores it in the renderer state.
 * 
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
protected void calculateBarWidth(CategoryPlot plot, 
                                 Rectangle2D dataArea, 
                                 int rendererIndex,
                                 CategoryItemRendererState state) {

    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaxBarWidth();
        double categoryMargin = 0.0;
        double currentItemMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        if (rows > 1) {
            currentItemMargin = getItemMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin()
                                 - categoryMargin - currentItemMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(Math.min(used / (rows * columns), maxWidth));
        }
        else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
}
项目:parabuild-ci    文件:BarRenderer.java   
/**
 * Calculates the coordinate of the first "side" of a bar.  This will be the minimum 
 * x-coordinate for a vertical bar, and the minimum y-coordinate for a horizontal bar.
 * 
 * @param plot  the plot.
 * @param orientation  the plot orientation.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param state  the renderer state (has the bar width precalculated).
 * @param row  the row index.
 * @param column  the column index.
 * 
 * @return the coordinate.
 */
protected double calculateBarW0(CategoryPlot plot, 
                                PlotOrientation orientation, 
                                Rectangle2D dataArea,
                                CategoryAxis domainAxis,
                                CategoryItemRendererState state,
                                int row,
                                int column) {
    // calculate bar width...
    double space = 0.0;
    if (orientation == PlotOrientation.HORIZONTAL) {
        space = dataArea.getHeight();
    }
    else {
        space = dataArea.getWidth();
    }
    double barW0 = domainAxis.getCategoryStart(
        column, getColumnCount(), dataArea, plot.getDomainAxisEdge()
    );
    int seriesCount = getRowCount();
    int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        double seriesGap = space * getItemMargin() / (categoryCount * (seriesCount - 1));
        double seriesW = calculateSeriesWidth(space, domainAxis, categoryCount, seriesCount);
        barW0 = barW0 + row * (seriesW + seriesGap) 
                      + (seriesW / 2.0) - (state.getBarWidth() / 2.0);
    }
    else {
        barW0 = domainAxis.getCategoryMiddle(
            column, getColumnCount(), dataArea, plot.getDomainAxisEdge()
        ) - state.getBarWidth() / 2.0;
    }
    return barW0;
}
项目:parabuild-ci    文件:LayeredBarRenderer.java   
/**
 * Calculates the bar width and stores it in the renderer state.
 * 
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
protected void calculateBarWidth(CategoryPlot plot, 
                                 Rectangle2D dataArea, 
                                 int rendererIndex,
                                 CategoryItemRendererState state) {

    // calculate the bar width
    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double categoryMargin = 0.0;
        double currentItemMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        if (rows > 1) {
            currentItemMargin = getItemMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin()
                                 - categoryMargin - currentItemMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(used / (dataset.getColumnCount()));
        } 
        else {
            state.setBarWidth(used);
        }
    }
}
项目:parabuild-ci    文件:GroupedStackedBarRenderer.java   
/**
 * Calculates the coordinate of the first "side" of a bar.  This will be the minimum 
 * x-coordinate for a vertical bar, and the minimum y-coordinate for a horizontal bar.
 * 
 * @param plot  the plot.
 * @param orientation  the plot orientation.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param state  the renderer state (has the bar width precalculated).
 * @param row  the row index.
 * @param column  the column index.
 * 
 * @return the coordinate.
 */
protected double calculateBarW0(CategoryPlot plot, 
                                PlotOrientation orientation, 
                                Rectangle2D dataArea,
                                CategoryAxis domainAxis,
                                CategoryItemRendererState state,
                                int row,
                                int column) {
    // calculate bar width...
    double space = 0.0;
    if (orientation == PlotOrientation.HORIZONTAL) {
        space = dataArea.getHeight();
    }
    else {
        space = dataArea.getWidth();
    }
    double barW0 = domainAxis.getCategoryStart(
        column, getColumnCount(), dataArea, plot.getDomainAxisEdge()
    );
    int groupCount = this.seriesToGroupMap.getGroupCount();
    int groupIndex = this.seriesToGroupMap.getGroupIndex(
        this.seriesToGroupMap.getGroup(plot.getDataset().getRowKey(row))
    );
    int categoryCount = getColumnCount();
    if (groupCount > 1) {
        double groupGap = space * getItemMargin() / (categoryCount * (groupCount - 1));
        double groupW = calculateSeriesWidth(space, domainAxis, categoryCount, groupCount);
        barW0 = barW0 + groupIndex * (groupW + groupGap) 
                      + (groupW / 2.0) - (state.getBarWidth() / 2.0);
    }
    else {
        barW0 = domainAxis.getCategoryMiddle(
            column, getColumnCount(), dataArea, plot.getDomainAxisEdge()
        ) - state.getBarWidth() / 2.0;
    }
    return barW0;
}
项目:parabuild-ci    文件:StackedBarRenderer.java   
/**
 * Calculates the bar width and stores it in the renderer state.
 * 
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
protected void calculateBarWidth(CategoryPlot plot, 
                                 Rectangle2D dataArea, 
                                 int rendererIndex,
                                 CategoryItemRendererState state) {

    // calculate the bar width
    CategoryAxis xAxis = plot.getDomainAxisForDataset(rendererIndex);
    CategoryDataset data = plot.getDataset(rendererIndex);
    if (data != null) {
        PlotOrientation orientation = plot.getOrientation();
        double space = 0.0;
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaxBarWidth();
        int columns = data.getColumnCount();
        double categoryMargin = 0.0;
        if (columns > 1) {
            categoryMargin = xAxis.getCategoryMargin();
        }

        double used = space * (1 - xAxis.getLowerMargin() - xAxis.getUpperMargin()
                                 - categoryMargin);
        if (columns > 0) {
            state.setBarWidth(Math.min(used / columns, maxWidth));
        }
        else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }

}
项目:parabuild-ci    文件:CategoryPlotTests.java   
/**
 * A test for a bug reported in the forum.
 */
public void testAxisRange() {
    DefaultCategoryDataset datasetA = new DefaultCategoryDataset();
    DefaultCategoryDataset datasetB = new DefaultCategoryDataset();
    datasetB.addValue(50.0, "R1", "C1");
    datasetB.addValue(80.0, "R1", "C1");
    CategoryPlot plot = new CategoryPlot(
        datasetA, new CategoryAxis(null), new NumberAxis(null), new LineAndShapeRenderer()
    );
    plot.setDataset(1, datasetB);
    plot.setRenderer(1, new LineAndShapeRenderer());
    Range r = plot.getRangeAxis().getRange();
    assertEquals(84.0, r.getUpperBound(), 0.00001);
}