Search in sources :

Example 26 with ItemLabelPosition

use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class ChartFactory method createWaterfallChart.

/**
 * 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} permitted).
 * @param categoryAxisLabel  the label for the category axis
 *                           ({@code null} permitted).
 * @param valueAxisLabel  the label for the value axis ({@code null}
 *                        permitted).
 * @param dataset  the dataset for the chart ({@code null} permitted).
 * @param orientation  the plot orientation (horizontal or vertical)
 *                     ({@code null} 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) {
    Args.nullNotPermitted(orientation, "orientation");
    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    categoryAxis.setCategoryMargin(0.0);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
    WaterfallBarRenderer renderer = new WaterfallBarRenderer();
    ItemLabelPosition position = setPosition(orientation);
    setItemLabelPosition(renderer, position);
    if (tooltips) {
        StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator();
        renderer.setDefaultToolTipGenerator(generator);
    }
    if (urls) {
        renderer.setDefaultItemURLGenerator(new StandardCategoryURLGenerator());
    }
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    Marker baseline = new ValueMarker(0.0);
    baseline.setPaint(Color.BLACK);
    plotFacilitator(plot, baseline, orientation);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) WaterfallBarRenderer(org.jfree.chart.renderer.category.WaterfallBarRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) ValueAxis(org.jfree.chart.axis.ValueAxis) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) StandardCategoryURLGenerator(org.jfree.chart.urls.StandardCategoryURLGenerator) ValueMarker(org.jfree.chart.plot.ValueMarker) Marker(org.jfree.chart.plot.Marker) ValueMarker(org.jfree.chart.plot.ValueMarker) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 27 with ItemLabelPosition

use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class AbstractRendererTest method testEquals_ObjectList4.

@Test
public void testEquals_ObjectList4() {
    BarRenderer r1 = new BarRenderer();
    r1.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    BarRenderer r2 = new BarRenderer();
    r2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertEquals(r1, r2);
    r2.setSeriesNegativeItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertNotEquals(r1, r2);
}
Also used : BarRenderer(org.jfree.chart.renderer.category.BarRenderer) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) Test(org.junit.jupiter.api.Test)

Example 28 with ItemLabelPosition

use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class AbstractRendererTest method testEventNotification.

/**
 * Tests each setter method to ensure that it sends an event notification.
 */
@Test
public void testEventNotification() {
    RendererChangeDetector detector = new RendererChangeDetector();
    // have to use a subclass of
    BarRenderer r1 = new BarRenderer();
    // AbstractRenderer
    r1.addChangeListener(detector);
    // PAINT
    detector.setNotified(false);
    r1.setSeriesPaint(0, Color.RED);
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultPaint(Color.RED);
    assertTrue(detector.getNotified());
    // OUTLINE PAINT
    detector.setNotified(false);
    r1.setSeriesOutlinePaint(0, Color.RED);
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultOutlinePaint(Color.RED);
    assertTrue(detector.getNotified());
    // STROKE
    detector.setNotified(false);
    r1.setSeriesStroke(0, new BasicStroke(1.0f));
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultStroke(new BasicStroke(1.0f));
    assertTrue(detector.getNotified());
    // OUTLINE STROKE
    detector.setNotified(false);
    r1.setSeriesOutlineStroke(0, new BasicStroke(1.0f));
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultOutlineStroke(new BasicStroke(1.0f));
    assertTrue(detector.getNotified());
    // SHAPE
    detector.setNotified(false);
    r1.setSeriesShape(0, new Rectangle2D.Float());
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultShape(new Rectangle2D.Float());
    assertTrue(detector.getNotified());
    // ITEM_LABELS_VISIBLE
    detector.setNotified(false);
    r1.setSeriesItemLabelsVisible(0, Boolean.TRUE);
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultItemLabelsVisible(Boolean.TRUE);
    assertTrue(detector.getNotified());
    // ITEM_LABEL_FONT
    detector.setNotified(false);
    r1.setSeriesItemLabelFont(0, new Font("Serif", Font.PLAIN, 12));
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultItemLabelFont(new Font("Serif", Font.PLAIN, 12));
    assertTrue(detector.getNotified());
    // ITEM_LABEL_PAINT
    detector.setNotified(false);
    r1.setSeriesItemLabelPaint(0, Color.BLUE);
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultItemLabelPaint(Color.BLUE);
    assertTrue(detector.getNotified());
    // POSITIVE ITEM LABEL POSITION
    detector.setNotified(false);
    r1.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertTrue(detector.getNotified());
    // NEGATIVE ITEM LABEL ANCHOR
    detector.setNotified(false);
    r1.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertTrue(detector.getNotified());
}
Also used : BasicStroke(java.awt.BasicStroke) Rectangle2D(java.awt.geom.Rectangle2D) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) Font(java.awt.Font) Test(org.junit.jupiter.api.Test)

Example 29 with ItemLabelPosition

use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class AbstractRendererTest method testEquals_ObjectList3.

@Test
public void testEquals_ObjectList3() {
    BarRenderer r1 = new BarRenderer();
    r1.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    BarRenderer r2 = new BarRenderer();
    r2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertEquals(r1, r2);
    r2.setSeriesPositiveItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertNotEquals(r1, r2);
}
Also used : BarRenderer(org.jfree.chart.renderer.category.BarRenderer) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) Test(org.junit.jupiter.api.Test)

Example 30 with ItemLabelPosition

use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class XYBarRendererTest method testSerialization2.

/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization2() {
    XYBarRenderer r1 = new XYBarRenderer();
    r1.setPositiveItemLabelPositionFallback(new ItemLabelPosition());
    XYBarRenderer r2 = TestUtils.serialised(r1);
    assertEquals(r1, r2);
}
Also used : ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) Test(org.junit.jupiter.api.Test)

Aggregations

ItemLabelPosition (org.jfree.chart.labels.ItemLabelPosition)72 Font (java.awt.Font)30 Paint (java.awt.Paint)26 Point2D (java.awt.geom.Point2D)22 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)21 NumberAxis (org.jfree.chart.axis.NumberAxis)20 CategoryPlot (org.jfree.chart.plot.CategoryPlot)18 CategoryAxis (org.jfree.chart.axis.CategoryAxis)15 JFreeChart (org.jfree.chart.JFreeChart)13 GradientPaint (java.awt.GradientPaint)11 ValueAxis (org.jfree.chart.axis.ValueAxis)11 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)11 StackedBarRenderer (org.jfree.chart.renderer.category.StackedBarRenderer)11 Color (java.awt.Color)10 Test (org.junit.Test)10 Shape (java.awt.Shape)8 WaterfallBarRenderer (org.jfree.chart.renderer.category.WaterfallBarRenderer)8 StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)8 Test (org.junit.jupiter.api.Test)8 BasicStroke (java.awt.BasicStroke)7