Search in sources :

Example 16 with LegendTitle

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;
}
Also used : BasicStroke(java.awt.BasicStroke) DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) DecimalFormat(java.text.DecimalFormat) CombinedXYPlot(org.jfree.experimental.chart.plot.CombinedXYPlot) LegendTitle(org.jfree.chart.title.LegendTitle) JFreeChart(org.jfree.chart.JFreeChart) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) CombinedXYPlot(org.jfree.experimental.chart.plot.CombinedXYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) XYDataset(org.jfree.data.xy.XYDataset) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) SimpleDateFormat(java.text.SimpleDateFormat) XYBarRenderer(org.jfree.chart.renderer.xy.XYBarRenderer)

Example 17 with LegendTitle

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);
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) LegendTitle(org.jfree.chart.title.LegendTitle) Test(org.junit.Test)

Example 18 with LegendTitle

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;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) LegendTitle(org.jfree.chart.title.LegendTitle) JFreeChart(org.jfree.chart.JFreeChart)

Example 19 with LegendTitle

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));
        }
    }
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) LegendTitle(org.jfree.chart.title.LegendTitle)

Example 20 with LegendTitle

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);
    }
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) XYBarRenderer(org.jfree.chart.renderer.xy.XYBarRenderer) TalendBarRenderer(org.talend.dataprofiler.chart.TalendBarRenderer) LegendTitle(org.jfree.chart.title.LegendTitle) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) Font(java.awt.Font) Paint(java.awt.Paint)

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