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;
}
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());
}
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);
}
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);
}
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);
}
Aggregations