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