Search in sources :

Example 1 with PiePlot

use of org.jfree.chart.plot.pie.PiePlot in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class ChartFactory method createPieChart.

/**
 * Creates a pie chart with default settings.
 * <P>
 * The chart object returned by this method uses a {@link PiePlot} instance
 * as the plot.
 *
 * @param title  the chart title ({@code null} permitted).
 * @param dataset  the dataset for the chart ({@code null} permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param locale  the locale ({@code null} not permitted).
 *
 * @return A pie chart.
 */
public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, Locale locale) {
    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale));
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
    }
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) MultiplePiePlot(org.jfree.chart.plot.pie.MultiplePiePlot) PiePlot(org.jfree.chart.plot.pie.PiePlot) RectangleInsets(org.jfree.chart.api.RectangleInsets) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator)

Example 2 with PiePlot

use of org.jfree.chart.plot.pie.PiePlot in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class PieChartTest method testReplaceDatasetOnPieChart.

/**
 * Using a regular pie chart, we replace the dataset with null.  Expect to
 * receive notification of a chart change event, and (of course) the
 * dataset should be null.
 */
@Test
public void testReplaceDatasetOnPieChart() {
    LocalListener l = new LocalListener();
    this.pieChart.addChangeListener(l);
    PiePlot plot = (PiePlot) this.pieChart.getPlot();
    plot.setDataset(null);
    assertTrue(l.flag);
    assertNull(plot.getDataset());
}
Also used : PiePlot(org.jfree.chart.plot.pie.PiePlot) Test(org.junit.jupiter.api.Test)

Example 3 with PiePlot

use of org.jfree.chart.plot.pie.PiePlot in project EditCalculateAndChart by mathhobbit.

the class piePlt method createAndShow.

/**
 * @throws Exception
 */
@Override
public void createAndShow() throws Exception {
    piePlt frameToShow;
    // toShow = toShow.replace(" ","");
    if (!toShow.startsWith("piePlt") || toShow.length() < 7)
        return;
    String tt = jc.getInside(toShow.substring(7), '(', ')');
    String title = null, exploded = null, bf = "";
    if (tt.indexOf('{') == -1)
        throw new Exception("piePlot is not defined correctly!");
    String txt = tt.substring(0, tt.indexOf('{'));
    for (int i = 0; i < txt.length(); i++) {
        if (txt.charAt(i) == ',') {
            if (bf.contentEquals(""))
                throw new Exception("piePlot is not defined correctly!");
            if (bf.indexOf('=') != -1) {
                switch(bf.substring(0, bf.indexOf('=')).toLowerCase().trim()) {
                    case "title":
                        if (title != null)
                            throw new Exception("piePlot is not defined correctly!");
                        title = bf.substring(bf.indexOf('=') + 1);
                        bf = "";
                        break;
                    default:
                        if (exploded != null)
                            throw new Exception("piePlot is not defined correctly!");
                        exploded = bf;
                        bf = "";
                        break;
                }
            } else {
                if (title == null) {
                    title = bf;
                    bf = "";
                } else
                    throw new Exception("piePlot is not defined correctly!");
            }
        } else
            bf = bf + txt.charAt(i);
    }
    if (tt.endsWith("{"))
        throw new Exception("barPlot is not defined correctly!");
    txt = tt.substring(tt.indexOf('{') + 1);
    frameToShow = new piePlt(title, jc.getInside(txt, '{', '}'));
    ChartPanel chartP = new ChartPanel(frameToShow.getChart());
    chartP.setPreferredSize(new java.awt.Dimension(500, 500));
    chartP.setEnforceFileExtensions(false);
    if (exploded != null) {
        PiePlot plot = (PiePlot) frameToShow.getChart().getPlot();
        plot.setExplodePercent(exploded.substring(0, exploded.indexOf('=')), Double.valueOf(jc.eval("2dbl(" + jc.eval(exploded.substring(exploded.indexOf('=') + 1)) + ")")));
    }
    frameToShow.setContentPane(chartP);
    frameToShow.setJMenuBar(barPlt.getMenu(frameToShow.getChart(), frameToShow));
    frameToShow.pack();
    UIUtils.centerFrameOnScreen(frameToShow);
    frameToShow.setVisible(true);
}
Also used : ChartPanel(org.jfree.chart.swing.ChartPanel) PiePlot(org.jfree.chart.plot.pie.PiePlot)

Example 4 with PiePlot

use of org.jfree.chart.plot.pie.PiePlot in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class JFreeChartTest method testEquals2.

/**
 * A test to make sure that the legend is being picked up in the
 * equals() testing.
 */
@Test
public void testEquals2() {
    JFreeChart chart1 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new PiePlot(), true);
    JFreeChart chart2 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new PiePlot(), false);
    assertNotEquals(chart1, chart2);
    assertNotEquals(chart2, chart1);
}
Also used : PiePlot(org.jfree.chart.plot.pie.PiePlot) Font(java.awt.Font) Test(org.junit.jupiter.api.Test)

Example 5 with PiePlot

use of org.jfree.chart.plot.pie.PiePlot in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class JFreeChartTest method testEquals.

/**
 * Check that the equals() method can distinguish all fields.
 */
@Test
public void testEquals() {
    JFreeChart chart1 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new PiePlot(), true);
    JFreeChart chart2 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new PiePlot(), true);
    assertEquals(chart1, chart2);
    assertEquals(chart2, chart1);
    // renderingHints
    chart1.setRenderingHints(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
    assertNotEquals(chart1, chart2);
    chart2.setRenderingHints(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
    assertEquals(chart1, chart2);
    // borderVisible
    chart1.setBorderVisible(true);
    assertNotEquals(chart1, chart2);
    chart2.setBorderVisible(true);
    assertEquals(chart1, chart2);
    // borderStroke
    BasicStroke s = new BasicStroke(2.0f);
    chart1.setBorderStroke(s);
    assertNotEquals(chart1, chart2);
    chart2.setBorderStroke(s);
    assertEquals(chart1, chart2);
    // borderPaint
    chart1.setBorderPaint(Color.RED);
    assertNotEquals(chart1, chart2);
    chart2.setBorderPaint(Color.RED);
    assertEquals(chart1, chart2);
    // padding
    chart1.setPadding(new RectangleInsets(1, 2, 3, 4));
    assertNotEquals(chart1, chart2);
    chart2.setPadding(new RectangleInsets(1, 2, 3, 4));
    assertEquals(chart1, chart2);
    // title
    chart1.setTitle("XYZ");
    assertNotEquals(chart1, chart2);
    chart2.setTitle("XYZ");
    assertEquals(chart1, chart2);
    // subtitles
    chart1.addSubtitle(new TextTitle("Subtitle"));
    assertNotEquals(chart1, chart2);
    chart2.addSubtitle(new TextTitle("Subtitle"));
    assertEquals(chart1, chart2);
    // plot
    chart1 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new RingPlot(), false);
    chart2 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new PiePlot(), false);
    assertNotEquals(chart1, chart2);
    chart2 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new RingPlot(), false);
    assertEquals(chart1, chart2);
    // backgroundPaint
    chart1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE));
    assertNotEquals(chart1, chart2);
    chart2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE));
    assertEquals(chart1, chart2);
    // // backgroundImage
    // chart1.setBackgroundImage(JFreeChart.INFO.getLogo());
    // assertFalse(chart1.equals(chart2));
    // chart2.setBackgroundImage(JFreeChart.INFO.getLogo());
    // assertEquals(chart1, chart2);
    // backgroundImageAlignment
    chart1.setBackgroundImageAlignment(RectangleAlignment.BOTTOM_LEFT);
    assertNotEquals(chart1, chart2);
    chart2.setBackgroundImageAlignment(RectangleAlignment.BOTTOM_LEFT);
    assertEquals(chart1, chart2);
    // backgroundImageAlpha
    chart1.setBackgroundImageAlpha(0.1f);
    assertNotEquals(chart1, chart2);
    chart2.setBackgroundImageAlpha(0.1f);
    assertEquals(chart1, chart2);
}
Also used : BasicStroke(java.awt.BasicStroke) TextTitle(org.jfree.chart.title.TextTitle) RingPlot(org.jfree.chart.plot.RingPlot) PiePlot(org.jfree.chart.plot.pie.PiePlot) RectangleInsets(org.jfree.chart.api.RectangleInsets) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font) RenderingHints(java.awt.RenderingHints) Test(org.junit.jupiter.api.Test)

Aggregations

PiePlot (org.jfree.chart.plot.pie.PiePlot)11 RectangleInsets (org.jfree.chart.api.RectangleInsets)6 Font (java.awt.Font)5 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)5 MultiplePiePlot (org.jfree.chart.plot.pie.MultiplePiePlot)5 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)4 Test (org.junit.jupiter.api.Test)4 TextTitle (org.jfree.chart.title.TextTitle)3 StandardPieURLGenerator (org.jfree.chart.urls.StandardPieURLGenerator)3 BasicStroke (java.awt.BasicStroke)2 Color (java.awt.Color)2 GradientPaint (java.awt.GradientPaint)2 Iterator (java.util.Iterator)2 List (java.util.List)2 DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)2 Paint (java.awt.Paint)1 Rectangle (java.awt.Rectangle)1 RenderingHints (java.awt.RenderingHints)1 Shape (java.awt.Shape)1 Stroke (java.awt.Stroke)1