use of org.jfree.chart.title.LegendTitle in project SIMVA-SoS by SESoS.
the class CombinedXYPlotDemo1 method createCombinedChart.
/**
* Creates an overlaid chart.
*
* @return The chart.
*/
private static JFreeChart createCombinedChart() {
// create plot ...
IntervalXYDataset data1 = createDataset1();
XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
renderer1.setSeriesStroke(0, new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
renderer1.setSeriesPaint(0, Color.blue);
DateAxis domainAxis = new DateAxis("Year");
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.02);
ValueAxis rangeAxis = new NumberAxis("$billion");
XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1);
plot1.setBackgroundPaint(Color.lightGray);
plot1.setDomainGridlinePaint(Color.white);
plot1.setRangeGridlinePaint(Color.white);
// add a second dataset and renderer...
IntervalXYDataset data2 = createDataset2();
XYBarRenderer renderer2 = new XYBarRenderer() {
public Paint getItemPaint(int series, int item) {
XYDataset dataset = getPlot().getDataset();
if (dataset.getYValue(series, item) >= 0.0) {
return Color.red;
} else {
return Color.green;
}
}
};
renderer2.setSeriesPaint(0, Color.red);
renderer2.setDrawBarOutline(false);
renderer2.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"), renderer2);
plot2.setBackgroundPaint(Color.lightGray);
plot2.setDomainGridlinePaint(Color.white);
plot2.setRangeGridlinePaint(Color.white);
CombinedXYPlot cplot = new CombinedXYPlot(domainAxis, rangeAxis);
cplot.add(plot1, 3);
cplot.add(plot2, 2);
cplot.setGap(8.0);
cplot.setDomainGridlinePaint(Color.white);
cplot.setDomainGridlinesVisible(true);
// return a new chart containing the overlaid plot...
JFreeChart chart = new JFreeChart("CombinedXYPlotDemo1", JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
chart.setBackgroundPaint(Color.white);
LegendTitle legend = new LegendTitle(cplot);
chart.addSubtitle(legend);
return chart;
}
use of org.jfree.chart.title.LegendTitle in project SIMVA-SoS by SESoS.
the class JFreeChartTest method testLegendEvents.
/**
* Some checks for the default legend firing change events.
*/
@Test
public void testLegendEvents() {
DefaultPieDataset dataset = new DefaultPieDataset();
JFreeChart chart = ChartFactory.createPieChart("title", dataset);
chart.addChangeListener(this);
this.lastChartChangeEvent = null;
LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.TOP);
assertNotNull(this.lastChartChangeEvent);
}
use of org.jfree.chart.title.LegendTitle in project n2a by frothga.
the class Plot method createChart.
public JFreeChart createChart(final XYDataset dataset) {
final JFreeChart chart = ChartFactory.createXYLineChart(// chart title
null, // x axis label
null, // y axis label
null, // data
dataset, PlotOrientation.VERTICAL, // include legend
true, // tooltips
true, // urls
false);
LegendTitle legend = chart.getLegend();
legend.setVisible(dataset.getSeriesCount() <= 5);
XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.lightGray);
plot.setDomainPannable(true);
plot.setRangePannable(true);
ValueAxis axis = plot.getRangeAxis();
if (axis instanceof NumberAxis)
((NumberAxis) axis).setAutoRangeIncludesZero(false);
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
for (int i = 0; i < dataset.getSeriesCount(); i++) renderer.setSeriesShapesVisible(i, false);
plot.setRenderer(renderer);
return chart;
}
use of org.jfree.chart.title.LegendTitle in project xwiki-platform by xwiki.
the class ChartCustomizer method customizeChart.
public static void customizeChart(JFreeChart jfchart, ChartParams params) {
// title
if (params.get(ChartParams.TITLE_PREFIX + ChartParams.TITLE_SUFFIX) != null) {
TextTitle title = new TextTitle(params.getString(ChartParams.TITLE_PREFIX + ChartParams.TITLE_SUFFIX));
customizeTitle(title, params, ChartParams.TITLE_PREFIX);
jfchart.setTitle(title);
}
// subtitle
if (params.get(ChartParams.SUBTITLE_PREFIX + ChartParams.TITLE_SUFFIX) != null) {
TextTitle subtitle = new TextTitle(params.getString(ChartParams.SUBTITLE_PREFIX + ChartParams.TITLE_SUFFIX));
customizeTitle(subtitle, params, ChartParams.SUBTITLE_PREFIX);
jfchart.addSubtitle(subtitle);
}
// legend
LegendTitle legend = jfchart.getLegend();
customizeLegend(legend, params);
// anti-alias
if (params.get(ChartParams.ANTI_ALIAS) != null) {
jfchart.setAntiAlias(params.getBoolean(ChartParams.ANTI_ALIAS).booleanValue());
}
// background color
if (params.get(ChartParams.BACKGROUND_COLOR) != null) {
jfchart.setBackgroundPaint(params.getColor(ChartParams.BACKGROUND_COLOR));
}
// border
if (params.get(ChartParams.BORDER_VISIBLE) != null && params.getBoolean(ChartParams.BORDER_VISIBLE).booleanValue()) {
jfchart.setBorderVisible(true);
if (params.get(ChartParams.BORDER_COLOR) != null) {
jfchart.setBorderPaint(params.getColor(ChartParams.BORDER_COLOR));
}
if (params.get(ChartParams.BORDER_STROKE) != null) {
jfchart.setBorderStroke(params.getStroke(ChartParams.BORDER_STROKE));
}
}
}
use of org.jfree.chart.title.LegendTitle in project tdq-studio-se by Talend.
the class TopChartFactory method decorateCategoryPlot.
private static void decorateCategoryPlot(JFreeChart chart) {
XYPlot plot = chart.getXYPlot();
XYItemRenderer render = plot.getRenderer();
ValueAxis domainAxis = plot.getDomainAxis();
ValueAxis valueAxis = plot.getRangeAxis();
// $NON-NLS-1$
Font font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE);
render.setBaseItemLabelFont(font);
// $NON-NLS-1$
font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);
domainAxis.setLabelFont(font);
// $NON-NLS-1$
font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);
valueAxis.setLabelFont(font);
// $NON-NLS-1$
font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE);
domainAxis.setTickLabelFont(font);
valueAxis.setTickLabelFont(font);
// $NON-NLS-1$
font = new Font("Tahoma", Font.PLAIN, BASE_LEGEND_LABEL_SIZE);
LegendTitle legend = chart.getLegend();
if (legend != null) {
legend.setItemFont(font);
}
// $NON-NLS-1$
font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);
TextTitle title = chart.getTitle();
if (title != null) {
title.setFont(font);
}
font = null;
if (render instanceof BarRenderer) {
int rowCount = chart.getCategoryPlot().getDataset().getRowCount();
domainAxis.setUpperMargin(0.1);
// domainAxis.setMaximumCategoryLabelLines(10);
((BarRenderer) render).setItemMargin(-0.40 * rowCount);
}
// set color
int rowCount = chart.getXYPlot().getDataset().getSeriesCount();
for (int i = 0; i < rowCount; i++) {
plot.getRenderer().setSeriesPaint(i, Color.RED);
}
}
Aggregations