Java Code Examples for org.jfree.chart.plot.CategoryPlot#setInsets()

The following examples show how to use org.jfree.chart.plot.CategoryPlot#setInsets() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValueAxisTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for bug 3555275 (where the fixed axis space is calculated 
 * incorrectly).
 */
@Test
public void test3555275() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setFixedDimension(100.0);
    BufferedImage image = new BufferedImage(500, 300, 
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    ChartRenderingInfo info = new ChartRenderingInfo();
    chart.draw(g2, new Rectangle2D.Double(0, 0, 500, 300), info);
    g2.dispose();
    Rectangle2D rect = info.getPlotInfo().getDataArea();
    double x = rect.getMinX();
    assertEquals(100.0, x, 1.0);
}
 
Example 2
Source File: ValueAxisTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for bug 3555275 (where the fixed axis space is calculated 
 * incorrectly).
 */
@Test
public void test3555275() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setFixedDimension(100.0);
    BufferedImage image = new BufferedImage(500, 300, 
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    ChartRenderingInfo info = new ChartRenderingInfo();
    chart.draw(g2, new Rectangle2D.Double(0, 0, 500, 300), info);
    g2.dispose();
    Rectangle2D rect = info.getPlotInfo().getDataArea();
    double x = rect.getMinX();
    assertEquals(100.0, x, 1.0);
}
 
Example 3
Source File: ValueAxisTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A test for bug 3555275 (where the fixed axis space is calculated 
 * incorrectly).
 */
@Test
public void test3555275() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setFixedDimension(100.0);
    BufferedImage image = new BufferedImage(500, 300, 
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    ChartRenderingInfo info = new ChartRenderingInfo();
    chart.draw(g2, new Rectangle2D.Double(0, 0, 500, 300), info);
    g2.dispose();
    Rectangle2D rect = info.getPlotInfo().getDataArea();
    double x = rect.getMinX();
    assertEquals(100.0, x, 1.0);
}
 
Example 4
Source File: ValueAxisTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for bug 3555275 (where the fixed axis space is calculated 
 * incorrectly).
 */
@Test
public void test3555275() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setFixedDimension(100.0);
    BufferedImage image = new BufferedImage(500, 300, 
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    ChartRenderingInfo info = new ChartRenderingInfo();
    chart.draw(g2, new Rectangle2D.Double(0, 0, 500, 300), info);
    g2.dispose();
    Rectangle2D rect = info.getPlotInfo().getDataArea();
    double x = rect.getMinX();
    assertEquals(100.0, x, 1.0);
}
 
Example 5
Source File: ValueAxisTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for bug 3555275 (where the fixed axis space is calculated 
 * incorrectly).
 */
@Test
public void test3555275() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setFixedDimension(100.0);
    BufferedImage image = new BufferedImage(500, 300, 
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    ChartRenderingInfo info = new ChartRenderingInfo();
    chart.draw(g2, new Rectangle2D.Double(0, 0, 500, 300), info);
    g2.dispose();
    Rectangle2D rect = info.getPlotInfo().getDataArea();
    double x = rect.getMinX();
    assertEquals(100.0, x, 1.0);
}
 
Example 6
Source File: AWSDeviceFarmGraph.java    From aws-device-farm-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Create graph based on the given dataset and constraints.
 *
 * @return The JFreeChart graph.
 */
protected JFreeChart createGraph() {
    // Create chart.
    JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.WHITE);

    // Create chart legend.
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);

    // Create chart plot.
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setForegroundAlpha(0.7f);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.darkGray);

    // Create domain (x) axis.
    CategoryAxis domain = new ShiftedCategoryAxis(xLabel);
    domain.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setCategoryMargin(0.0);
    plot.setDomainAxis(domain);

    // Create range (y) axis.
    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setAutoRange(true);
    range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Create renderer and paint the chart.
    CategoryItemRenderer renderer = plot.getRenderer();
    plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0));

    // Set chart colors for sections.
    for (int i = 0; i < colors.length; i++) {
        renderer.setSeriesPaint(i, colors[i]);
    }
    return chart;
}
 
Example 7
Source File: MonitoringPage.java    From webanno with Apache License 2.0 4 votes vote down vote up
private JFreeChart createProgressChart(Map<String, Integer> chartValues, int aMaxValue,
        boolean aIsPercentage)
{
    // fill dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if (aMaxValue > 0) {
        for (String chartValue : chartValues.keySet()) {
            dataset.setValue(chartValues.get(chartValue), "Completion", chartValue);
        }
    }
    
    // create chart
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset,
            PlotOrientation.HORIZONTAL, false, false, false);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(null);
    plot.setNoDataMessage("No data");
    plot.setInsets(new RectangleInsets(0, 20, 0, 20));
    if (aMaxValue > 0) {
        plot.getRangeAxis().setRange(0.0, aMaxValue);
        ((NumberAxis) plot.getRangeAxis()).setNumberFormatOverride(new DecimalFormat("0"));
        // For documents less than 10, avoid repeating the number of documents such
        // as 0 0 1 1 1 - NumberTickUnit automatically determines the range
        if (!aIsPercentage && aMaxValue <= 10) {
            TickUnits standardUnits = new TickUnits();
            NumberAxis tick = new NumberAxis();
            tick.setTickUnit(new NumberTickUnit(1));
            standardUnits.add(tick.getTickUnit());
            plot.getRangeAxis().setStandardTickUnits(standardUnits);
        }
    }
    else {
        plot.getRangeAxis().setVisible(false);
        plot.getDomainAxis().setVisible(false);
    }

    BarRenderer renderer = new BarRenderer();
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    // renderer.setGradientPaintTransformer(new
    // StandardGradientPaintTransformer(
    // GradientPaintTransformType.HORIZONTAL));
    renderer.setSeriesPaint(0, Color.BLUE);
    chart.getCategoryPlot().setRenderer(renderer);

    return chart;
}