Search in sources :

Example 21 with PiePlot

use of org.jfree.chart.plot.PiePlot in project SIMVA-SoS by SESoS.

the class MouseWheelHandler method mouseWheelMoved.

/**
 * Handles a mouse wheel event from the underlying chart panel.
 *
 * @param e  the event.
 */
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
    JFreeChart chart = this.chartPanel.getChart();
    if (chart == null) {
        return;
    }
    Plot plot = chart.getPlot();
    if (plot instanceof Zoomable) {
        Zoomable zoomable = (Zoomable) plot;
        handleZoomable(zoomable, e);
    } else if (plot instanceof PiePlot) {
        PiePlot pp = (PiePlot) plot;
        pp.handleMouseWheelRotation(e.getWheelRotation());
    }
}
Also used : Plot(org.jfree.chart.plot.Plot) PiePlot(org.jfree.chart.plot.PiePlot) Zoomable(org.jfree.chart.plot.Zoomable) PiePlot(org.jfree.chart.plot.PiePlot)

Example 22 with PiePlot

use of org.jfree.chart.plot.PiePlot in project SIMVA-SoS by SESoS.

the class PieChartDemo1 method createChart.

/**
 * Creates a chart.
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {
    JFreeChart chart = ChartFactory.createPieChart(// chart title
    "Smart Phones Manufactured / Q3 2011", // data
    dataset, // no legend
    false, // tooltips
    true, // no URL generation
    false);
    // set a custom background for the chart
    chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));
    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);
    // use gradients and white borders for the section colours
    plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));
    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);
    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) TextTitle(org.jfree.chart.title.TextTitle) Color(java.awt.Color) RadialGradientPaint(java.awt.RadialGradientPaint) GradientPaint(java.awt.GradientPaint) PiePlot(org.jfree.chart.plot.PiePlot) Point(java.awt.Point) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font)

Example 23 with PiePlot

use of org.jfree.chart.plot.PiePlot in project SIMVA-SoS by SESoS.

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));
    assertFalse(chart1.equals(chart2));
    chart2.setRenderingHints(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
    assertEquals(chart1, chart2);
    // borderVisible
    chart1.setBorderVisible(true);
    assertFalse(chart1.equals(chart2));
    chart2.setBorderVisible(true);
    assertEquals(chart1, chart2);
    // borderStroke
    BasicStroke s = new BasicStroke(2.0f);
    chart1.setBorderStroke(s);
    assertFalse(chart1.equals(chart2));
    chart2.setBorderStroke(s);
    assertEquals(chart1, chart2);
    // borderPaint
    chart1.setBorderPaint(Color.red);
    assertFalse(chart1.equals(chart2));
    chart2.setBorderPaint(Color.red);
    assertEquals(chart1, chart2);
    // padding
    chart1.setPadding(new RectangleInsets(1, 2, 3, 4));
    assertFalse(chart1.equals(chart2));
    chart2.setPadding(new RectangleInsets(1, 2, 3, 4));
    assertEquals(chart1, chart2);
    // title
    chart1.setTitle("XYZ");
    assertFalse(chart1.equals(chart2));
    chart2.setTitle("XYZ");
    assertEquals(chart1, chart2);
    // subtitles
    chart1.addSubtitle(new TextTitle("Subtitle"));
    assertFalse(chart1.equals(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);
    assertFalse(chart1.equals(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));
    assertFalse(chart1.equals(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(Align.BOTTOM_LEFT);
    assertFalse(chart1.equals(chart2));
    chart2.setBackgroundImageAlignment(Align.BOTTOM_LEFT);
    assertEquals(chart1, chart2);
    // backgroundImageAlpha
    chart1.setBackgroundImageAlpha(0.1f);
    assertFalse(chart1.equals(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.PiePlot) RectangleInsets(org.jfree.ui.RectangleInsets) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font) RenderingHints(java.awt.RenderingHints) Test(org.junit.Test)

Example 24 with PiePlot

use of org.jfree.chart.plot.PiePlot in project SIMVA-SoS by SESoS.

the class PieChart3DTest 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);
    assertEquals(true, l.flag);
    assertNull(plot.getDataset());
}
Also used : PiePlot(org.jfree.chart.plot.PiePlot) Test(org.junit.Test)

Example 25 with PiePlot

use of org.jfree.chart.plot.PiePlot in project SIMVA-SoS by SESoS.

the class SWTPieChartDemo1 method createChart.

/**
 * Creates a chart.
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {
    JFreeChart chart = ChartFactory.createPieChart(// chart title
    "Pie Chart Demo 1", // data
    dataset, // include legend
    true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
}
Also used : PiePlot(org.jfree.chart.plot.PiePlot) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font)

Aggregations

PiePlot (org.jfree.chart.plot.PiePlot)40 JFreeChart (org.jfree.chart.JFreeChart)22 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)16 Font (java.awt.Font)14 TextTitle (org.jfree.chart.title.TextTitle)11 MultiplePiePlot (org.jfree.chart.plot.MultiplePiePlot)10 DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)9 RectangleInsets (org.jfree.ui.RectangleInsets)9 Color (java.awt.Color)8 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)8 DecimalFormat (java.text.DecimalFormat)6 PieDataset (org.jfree.data.general.PieDataset)6 BasicStroke (java.awt.BasicStroke)5 Plot (org.jfree.chart.plot.Plot)5 StandardPieURLGenerator (org.jfree.chart.urls.StandardPieURLGenerator)5 ChartPanel (org.jfree.chart.ChartPanel)4 Test (org.junit.Test)4 GradientPaint (java.awt.GradientPaint)3 Paint (java.awt.Paint)3 Iterator (java.util.Iterator)3