Java 类org.jfree.chart.renderer.category.GroupedStackedBarRenderer 实例源码

项目:parabuild-ci    文件:GroupedStackedBarRendererTests.java   
/**
 * Test that the equals() method distinguishes all fields.
 */
public void testEquals() {
    GroupedStackedBarRenderer r1 = new GroupedStackedBarRenderer();
    GroupedStackedBarRenderer r2 = new GroupedStackedBarRenderer();
    assertTrue(r1.equals(r2));
    assertTrue(r2.equals(r1));

    // map
    KeyToGroupMap m1 = new KeyToGroupMap("G1");
    m1.mapKeyToGroup("S1", "G2");
    r1.setSeriesToGroupMap(m1);
    assertFalse(r1.equals(r2));
    KeyToGroupMap m2 = new KeyToGroupMap("G1");
    m2.mapKeyToGroup("S1", "G2");
    r2.setSeriesToGroupMap(m2);
    assertTrue(r1.equals(r2));
}
项目:parabuild-ci    文件:GroupedStackedBarRendererTests.java   
/**
 * Test that the equals() method distinguishes all fields.
 */
public void testEquals() {
    GroupedStackedBarRenderer r1 = new GroupedStackedBarRenderer();
    GroupedStackedBarRenderer r2 = new GroupedStackedBarRenderer();
    assertTrue(r1.equals(r2));
    assertTrue(r2.equals(r1));

    // map
    KeyToGroupMap m1 = new KeyToGroupMap("G1");
    m1.mapKeyToGroup("S1", "G2");
    r1.setSeriesToGroupMap(m1);
    assertFalse(r1.equals(r2));
    KeyToGroupMap m2 = new KeyToGroupMap("G1");
    m2.mapKeyToGroup("S1", "G2");
    r2.setSeriesToGroupMap(m2);
    assertTrue(r1.equals(r2));
}
项目: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);
}
项目:nabs    文件:GroupedStackedBarRendererTests.java   
/**
 * Test that the equals() method distinguishes all fields.
 */
public void testEquals() {
    GroupedStackedBarRenderer r1 = new GroupedStackedBarRenderer();
    GroupedStackedBarRenderer r2 = new GroupedStackedBarRenderer();
    assertTrue(r1.equals(r2));
    assertTrue(r2.equals(r1));

    // map
    KeyToGroupMap m1 = new KeyToGroupMap("G1");
    m1.mapKeyToGroup("S1", "G2");
    r1.setSeriesToGroupMap(m1);
    assertFalse(r1.equals(r2));
    KeyToGroupMap m2 = new KeyToGroupMap("G1");
    m2.mapKeyToGroup("S1", "G2");
    r2.setSeriesToGroupMap(m2);
    assertTrue(r1.equals(r2));
}
项目:nabs    文件: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);
}
项目:astor    文件:GroupedStackedBarRendererTests.java   
/**
 * Test that the equals() method distinguishes all fields.
 */
public void testEquals() {
    GroupedStackedBarRenderer r1 = new GroupedStackedBarRenderer();
    GroupedStackedBarRenderer r2 = new GroupedStackedBarRenderer();
    assertTrue(r1.equals(r2));
    assertTrue(r2.equals(r1));

    // map
    KeyToGroupMap m1 = new KeyToGroupMap("G1");
    m1.mapKeyToGroup("S1", "G2");
    r1.setSeriesToGroupMap(m1);
    assertFalse(r1.equals(r2));
    KeyToGroupMap m2 = new KeyToGroupMap("G1");
    m2.mapKeyToGroup("S1", "G2");
    r2.setSeriesToGroupMap(m2);
    assertTrue(r1.equals(r2));
}
项目:astor    文件: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);
}
项目:dynamicreports-jasper    文件:ShowPercentagesCustomizer.java   
@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    if (chart.getPlot() instanceof CategoryPlot) {
        if (chart.getCategoryPlot().getDataset() != null) {
            CategoryDataset dataset;
            if (!(chart.getCategoryPlot().getRenderer() instanceof GroupedStackedBarRenderer)) {
                dataset = new PercentageCategoryDataset(chart.getCategoryPlot().getDataset());
            }
            else {
                dataset = new PercentageGroupedCategoryDataset(chart.getCategoryPlot().getDataset());
            }
            chart.getCategoryPlot().setDataset(dataset);
        }
        if (StringUtils.isBlank(chart.getCategoryPlot().getRangeAxis().getLabel())) {
            chart.getCategoryPlot().getRangeAxis().setLabel("%");
        }
    }
}
项目:dynamicreports-jasper    文件:GroupedStackedBarChartData3Test.java   
private void testMap(JFreeChart chart, String ...groups) {
    GroupedStackedBarRenderer renderer = (GroupedStackedBarRenderer) chart.getCategoryPlot().getRenderer();
    try {
        Field field = renderer.getClass().getDeclaredField("seriesToGroupMap");
        field.setAccessible(true);
        KeyToGroupMap map = (KeyToGroupMap) field.get(renderer);
        Assert.assertEquals("map", groups.length, map.getGroupCount());
        List<?> groups2 = map.getGroups();
        for (int i = 0; i < groups2.size(); i++) {
            Assert.assertEquals("map", groups[i], groups2.get(i));
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
项目:astor    文件:GroupedStackedBarRendererTests.java   
/**
 * Some checks for the findRangeBounds() method.
 */
public void testFindRangeBounds() {
    GroupedStackedBarRenderer r = new GroupedStackedBarRenderer();
    assertNull(r.findRangeBounds(null));

    // an empty dataset should return a null range
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    assertNull(r.findRangeBounds(dataset));

    dataset.addValue(1.0, "R1", "C1");
    assertEquals(new Range(0.0, 1.0), r.findRangeBounds(dataset));

    dataset.addValue(-2.0, "R1", "C2");
    assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset));

    dataset.addValue(null, "R1", "C3");
    assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset));

    KeyToGroupMap m = new KeyToGroupMap("G1");
    m.mapKeyToGroup("R1", "G1");
    m.mapKeyToGroup("R2", "G1");
    m.mapKeyToGroup("R3", "G2");
    r.setSeriesToGroupMap(m);

    dataset.addValue(0.5, "R3", "C1");
    assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset));

    dataset.addValue(5.0, "R3", "C2");
    assertEquals(new Range(-2.0, 5.0), r.findRangeBounds(dataset));
}
项目:aorra    文件:WetlandLoss.java   
public static Drawable createChart(ADCDataset dataset, Dimension dimension) {
    final JFreeChart chart = ChartFactory.createBarChart(
            dataset.get(Attribute.TITLE),       // chart title
            dataset.get(Attribute.X_AXIS_LABEL),// domain axis label
            dataset.get(Attribute.Y_AXIS_LABEL),// range axis label
            dataset,                  // data
            PlotOrientation.VERTICAL, // orientation
            true,                    // include legend
            false,                     // tooltips?
            false                     // URLs?
        );
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap();
    map.mapKeyToGroup(dataset.getRowKey(0), "Y1");
    map.mapKeyToGroup(dataset.getRowKey(1), "Y1");
    map.mapKeyToGroup(dataset.getRowKey(2), "Y2");
    map.mapKeyToGroup(dataset.getRowKey(3), "Y2");
    renderer.setSeriesToGroupMap(map);
    Colors.setSeriesPaint(renderer, dataset.get(Attribute.SERIES_COLORS));
    renderer.setItemMargin(0);
    renderer.setBarPainter(new StandardBarPainter());
    plot.setRenderer(renderer);
    final CategoryAxis cAxis = plot.getDomainAxis();
    cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    chart.getTitle().setFont(cAxis.getLabelFont());
    chart.getLegend().setMargin(2, 60, 2, 20);
    return new JFreeChartDrawable(chart, dimension);
}
项目:dynamicreports-jasper    文件:GroupedStackedBarChartTest.java   
@Override
public void test() {
    super.test();

    numberOfPagesTest(1);

    JFreeChart chart = getChart("summary.chart1", 0);
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    Assert.assertEquals("renderer", GroupedStackedBarRenderer.class, categoryPlot.getRenderer().getClass());
    Assert.assertTrue("show labels", categoryPlot.getRenderer().getBaseItemLabelsVisible());
    Assert.assertFalse("show tick labels", categoryPlot.getDomainAxis().isTickLabelsVisible());
    Assert.assertFalse("show tick marks", categoryPlot.getDomainAxis().isTickMarksVisible());

    chart = getChart("summary.chart2", 0);
    Axis axis = chart.getCategoryPlot().getDomainAxis();
    Assert.assertEquals("category label", "category", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    CategoryLabelPosition labelPosition = chart.getCategoryPlot().getDomainAxis().getCategoryLabelPositions().getLabelPosition(RectangleEdge.LEFT);
    Assert.assertEquals("plot label rotation", (45d / 180) * Math.PI, labelPosition.getAngle());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());

    chart = getChart("summary.chart3", 0);
    axis = chart.getCategoryPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
}
项目:HTML5_WebSite    文件:StackedBarChartDemo4.java   
protected JFreeChart createLegend(CategoryDataset dataset) {

//  JFreeChart chart = ChartFactory.createAreaChart(
    JFreeChart chart = ChartFactory.createStackedBarChart(
              chartTitle,  // chart title
              domainLabel,                  // domain axis label
              rangeLabel,                     // range axis label
              dataset,                     // data
              PlotOrientation.VERTICAL,    // the plot orientation
              true,                        // legend
              true,                        // tooltips
              false                        // urls
          );

       // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
     GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
       KeyToGroupMap map = new KeyToGroupMap("G1");
       map.mapKeyToGroup("Product 1 (US)", "G1");
       map.mapKeyToGroup("Product 1 (Europe)", "G1");
       map.mapKeyToGroup("Product 1 (Asia)", "G1");
       map.mapKeyToGroup("Product 1 (Middle East)", "G1");
       map.mapKeyToGroup("Product 2 (US)", "G2");
       map.mapKeyToGroup("Product 2 (Europe)", "G2");
       map.mapKeyToGroup("Product 2 (Asia)", "G2");
       map.mapKeyToGroup("Product 2 (Middle East)", "G2");
       map.mapKeyToGroup("Product 3 (US)", "G3");
       map.mapKeyToGroup("Product 3 (Europe)", "G3");
       map.mapKeyToGroup("Product 3 (Asia)", "G3");
       map.mapKeyToGroup("Product 3 (Middle East)", "G3");
       renderer.setSeriesToGroupMap(map); 

       renderer.setItemMargin(0.10);
       renderer.setDrawBarOutline(false);
       Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 
               0.0f, 0.0f, new Color(0x88, 0x88, 0xFF));
       renderer.setSeriesPaint(0, p1);
       renderer.setSeriesPaint(4, p1);
       renderer.setSeriesPaint(8, p1);

       Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 
               0.0f, 0.0f, new Color(0x88, 0xFF, 0x88));
       renderer.setSeriesPaint(1, p2); 
       renderer.setSeriesPaint(5, p2); 
       renderer.setSeriesPaint(9, p2); 

       Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 
               0.0f, 0.0f, new Color(0xFF, 0x88, 0x88));
       renderer.setSeriesPaint(2, p3);
       renderer.setSeriesPaint(6, p3);
       renderer.setSeriesPaint(10, p3);

       Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 
               0.0f, 0.0f, new Color(0xFF, 0xFF, 0x88));
       renderer.setSeriesPaint(3, p4);
       renderer.setSeriesPaint(7, p4);
       renderer.setSeriesPaint(11, p4);
       renderer.setGradientPaintTransformer(
               new StandardGradientPaintTransformer(
                       GradientPaintTransformType.HORIZONTAL));

    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

       SubCategoryAxis domainAxis = new SubCategoryAxis("Product / Month");
       domainAxis.setCategoryMargin(0.05);
       domainAxis.addSubCategory("Product 1");
       domainAxis.addSubCategory("Product 2");
       domainAxis.addSubCategory("Product 3");

       CategoryPlot plot = (CategoryPlot) chart.getPlot();
       plot.setDomainAxis(domainAxis);
       //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
       plot.setRenderer(renderer);
       return chart;

   }
项目:astor    文件:GroupedStackedBarRendererTests.java   
/**
 * Check that this class implements PublicCloneable.
 */
public void testPublicCloneable() {
    GroupedStackedBarRenderer r1 = new GroupedStackedBarRenderer();
    assertTrue(r1 instanceof PublicCloneable);
}
项目:aorra    文件:LandPracticeSystems.java   
@Override
public Drawable createChart(ADCDataset dataset, Dimension dimension) {
    JFreeChart chart = ChartFactory.createStackedBarChart(
        dataset.get(Attribute.TITLE),  // chart title
        "",  // domain axis label
        "",  // range axis label
        dataset,                     // data
        PlotOrientation.VERTICAL,    // the plot orientation
        false,                       // legend
        false,                        // tooltips
        false                        // urls
    );
    chart.addLegend(createLegend());
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setOutlineVisible(false);
    plot.setAxisOffset(new RectangleInsets(0,0,0,0));
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeGridlineStroke(new BasicStroke(2));

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoTickUnitSelection(true);
    rangeAxis.setTickUnit(new NumberTickUnit(0.2, percentFormatter()));
    rangeAxis.setAxisLineVisible(true);
    rangeAxis.setLabel(dataset.get(Attribute.Y_AXIS_LABEL));
    rangeAxis.setAxisLineStroke(new BasicStroke(2));
    rangeAxis.setAxisLinePaint(Color.black);
    rangeAxis.setTickMarksVisible(false);
    rangeAxis.setLabelPaint(AXIS_LABEL_COLOR);
    rangeAxis.setLabelFont(AXIS_LABEL_FONT);
    rangeAxis.setLabelInsets(new RectangleInsets(0,0,0,0));
    rangeAxis.setUpperMargin(0);
    rangeAxis.setRange(0, 1);

    CategoryAxis cAxis = plot.getDomainAxis();
    cAxis.setTickMarksVisible(false);
    cAxis.setAxisLinePaint(Color.black);
    cAxis.setAxisLineStroke(new BasicStroke(2));
    cAxis.setLabel(dataset.get(Attribute.X_AXIS_LABEL));
    cAxis.setTickLabelsVisible(false);
    cAxis.setCategoryMargin(0.05);
    cAxis.setUpperMargin(0.1);
    cAxis.setLowerMargin(0);
    GroupedStackedBarRenderer renderer = new BarLabelRenderer();
    plot.setRenderer(renderer);
    for(int i=0;i<seriesPaint.length;i++) {
      renderer.setSeriesPaint(i, seriesPaint[i]);
    }
    renderer.setRenderAsPercentages(true);
    renderer.setDrawBarOutline(false);
    renderer.setBaseItemLabelsVisible(false);
    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setItemMargin(0.10);
    renderer.setSeriesToGroupMap(createKeyToGroupMap(dataset));
    return new JFreeChartDrawable(chart, dimension);
}