Search in sources :

Example 26 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project SIMVA-SoS by SESoS.

the class JFreeChartTest method testSerialization1.

/**
 * Serialize a pie chart, restore it, and check for equality.
 */
@Test
public void testSerialization1() {
    DefaultPieDataset data = new DefaultPieDataset();
    data.setValue("Type 1", 54.5);
    data.setValue("Type 2", 23.9);
    data.setValue("Type 3", 45.8);
    JFreeChart c1 = ChartFactory.createPieChart("Test", data);
    JFreeChart c2 = (JFreeChart) TestUtilities.serialised(c1);
    assertEquals(c1, c2);
    LegendTitle lt2 = c2.getLegend();
    assertSame(lt2.getSources()[0], c2.getPlot());
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) LegendTitle(org.jfree.chart.title.LegendTitle) Test(org.junit.Test)

Example 27 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project SIMVA-SoS by SESoS.

the class JFreeChartTest method testGetSubtitle.

/**
 * Some checks for the getSubtitle() method.
 */
@Test
public void testGetSubtitle() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    JFreeChart chart = ChartFactory.createPieChart("title", dataset);
    Title t = chart.getSubtitle(0);
    assertTrue(t instanceof LegendTitle);
    try {
        chart.getSubtitle(-1);
        fail("Should have thrown an IllegalArgumentException on negative number");
    } catch (IllegalArgumentException e) {
        assertEquals("Index out of range.", e.getMessage());
    }
    try {
        chart.getSubtitle(1);
        fail("Should have thrown an IllegalArgumentException on excesive number");
    } catch (IllegalArgumentException e) {
        assertEquals("Index out of range.", e.getMessage());
    }
    try {
        chart.getSubtitle(2);
        fail("Should have thrown an IllegalArgumentException on number being out of range");
    } catch (IllegalArgumentException e) {
        assertEquals("Index out of range.", e.getMessage());
    }
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) Title(org.jfree.chart.title.Title) TextTitle(org.jfree.chart.title.TextTitle) LegendTitle(org.jfree.chart.title.LegendTitle) LegendTitle(org.jfree.chart.title.LegendTitle) Test(org.junit.Test)

Example 28 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project SIMVA-SoS by SESoS.

the class JFreeChartInfo method getLegend.

/**
 * Returns the nth legend for a chart, or <code>null</code>.
 *
 * @param index  the legend index (zero-based).
 *
 * @return The legend (possibly <code>null</code>).
 *
 * @see #addLegend(LegendTitle)
 */
public LegendTitle getLegend(int index) {
    int seen = 0;
    Iterator iterator = this.subtitles.iterator();
    while (iterator.hasNext()) {
        Title subtitle = (Title) iterator.next();
        if (subtitle instanceof LegendTitle) {
            if (seen == index) {
                return (LegendTitle) subtitle;
            } else {
                seen++;
            }
        }
    }
    return null;
}
Also used : Iterator(java.util.Iterator) Title(org.jfree.chart.title.Title) TextTitle(org.jfree.chart.title.TextTitle) LegendTitle(org.jfree.chart.title.LegendTitle) LegendTitle(org.jfree.chart.title.LegendTitle) RectangleConstraint(org.jfree.chart.block.RectangleConstraint) Paint(java.awt.Paint)

Example 29 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project dbeaver by dbeaver.

the class DashboardRendererBase method createDefaultLegend.

protected void createDefaultLegend(DashboardItemViewConfiguration viewConfig, JFreeChart chart) {
    Color gridColor = AWTUtils.makeAWTColor(UIStyles.getDefaultTextForeground());
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.BOTTOM);
    legend.setBorder(0, 0, 0, 0);
    legend.setBackgroundPaint(chart.getBackgroundPaint());
    legend.setItemPaint(gridColor);
    legend.setItemFont(DEFAULT_LEGEND_FONT);
    if (viewConfig != null && !viewConfig.isLegendVisible()) {
        legend.setVisible(false);
    }
}
Also used : LegendTitle(org.jfree.chart.title.LegendTitle)

Example 30 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project MassBank-web by MassBank.

the class Contents method drawDataset.

private static JFreeChart drawDataset(PieDataset dataset, String title) {
    // JFreeChartオブジェクト生成
    JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, true, false);
    // グラフ全体背景色設定
    chart.setBackgroundPaint(new ChartColor(242, 246, 255));
    // グラフ全体境界線設定
    chart.setBorderVisible(true);
    // グラフエリアパディング設定
    chart.setPadding(new RectangleInsets(10, 10, 10, 10));
    // グラフタイトルフォント設定
    chart.getTitle().setFont(new Font("Arial", Font.BOLD, 22));
    // 凡例の表示位置設定
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);
    // 凡例パディング設定
    legend.setPadding(10, 10, 10, 10);
    // 凡例マージン設定
    legend.setMargin(0, 10, 0, 5);
    // 凡例表示位置上寄せ
    legend.setVerticalAlignment(VerticalAlignment.TOP);
    // グラフの描画領域を取得
    PiePlot plot = (PiePlot) chart.getPlot();
    // グラフの楕円表示を許可する
    plot.setCircular(true);
    // グラフ境界線色設定
    plot.setDefaultSectionOutlinePaint(ChartColor.BLACK);
    // グラフラベル背景色設定
    plot.setLabelBackgroundPaint(new Color(240, 255, 255));
    // グラフラベルフォント設定
    plot.setLabelFont(new Font("Arial", Font.PLAIN, 12));
    // グラフラベル幅設定
    plot.setMaximumLabelWidth(0.3);
    // グラフラベル間距離設定
    plot.setLabelGap(0.05);
    // グラフ前景色透明度設定
    plot.setForegroundAlpha(0.9f);
    return chart;
}
Also used : ChartColor(org.jfree.chart.ChartColor) Color(java.awt.Color) ChartColor(org.jfree.chart.ChartColor) RectangleInsets(org.jfree.chart.ui.RectangleInsets) PiePlot(org.jfree.chart.plot.PiePlot) LegendTitle(org.jfree.chart.title.LegendTitle) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font)

Aggregations

LegendTitle (org.jfree.chart.title.LegendTitle)31 JFreeChart (org.jfree.chart.JFreeChart)19 NumberAxis (org.jfree.chart.axis.NumberAxis)17 XYPlot (org.jfree.chart.plot.XYPlot)15 Color (java.awt.Color)14 Font (java.awt.Font)13 TextTitle (org.jfree.chart.title.TextTitle)12 ValueAxis (org.jfree.chart.axis.ValueAxis)11 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)11 XYDataset (org.jfree.data.xy.XYDataset)10 BasicStroke (java.awt.BasicStroke)9 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)9 Paint (java.awt.Paint)8 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)8 DecimalFormat (java.text.DecimalFormat)7 GridBagConstraints (java.awt.GridBagConstraints)6 Stroke (java.awt.Stroke)6 ChartPanel (org.jfree.chart.ChartPanel)6 XYSeries (org.jfree.data.xy.XYSeries)6 StandardXYSeriesLabelGenerator (org.jfree.chart.labels.StandardXYSeriesLabelGenerator)5