Example usage for org.jfree.chart.title LegendTitle setVerticalAlignment

List of usage examples for org.jfree.chart.title LegendTitle setVerticalAlignment

Introduction

In this page you can find the example usage for org.jfree.chart.title LegendTitle setVerticalAlignment.

Prototype

public void setVerticalAlignment(VerticalAlignment alignment) 

Source Link

Document

Sets the vertical alignment for the title, and notifies any registered listeners of the change.

Usage

From source file:y.graphs.ChartHelperELF.java

private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config,
        ArrayList<ConfigSerie> series) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleMagGraph"),
            Config.getResource("TitleDate"), Config.getResource("MsgTitleMagGraphYAxis"), dataset, true, // include legend
            true, // tooltips
            false // urls
    );//from  www.  j a v a  2s .co  m

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 12));
    lt.setBackgroundPaint(Color.white);
    lt.setFrame(new BlockBorder(Color.white));
    lt.setVerticalAlignment(VerticalAlignment.CENTER);
    XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt,
            RectangleAnchor.TOP_RIGHT);
    ta.setMaxWidth(config.getLegendSize());
    plot.addAnnotation(ta);
    chart.removeLegend();

    plot.setBackgroundPaint(config.getColorBackgroundELF());
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    final Stroke lineStroke = new BasicStroke((float) config.getLineWidthELF());

    for (int si = 0; si < series.size(); si++) {
        final ConfigSerie cs = series.get(si);
        renderer.setSeriesLinesVisible(si, cs.isDrawLine());

        final float size = cs.getShapeSize();
        renderer.setSeriesShapesVisible(si, size > 0);
        if (size > 0)
            renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size));

        renderer.setSeriesStroke(si, lineStroke);
        //            renderer.setSeriesOutlineStroke(si, lineStroke);
        renderer.setSeriesPaint(si, cs.getColor());
    }
    plot.setRenderer(renderer);

    // x axis
    final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis();
    //        rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to
    rangeAxis.setAutoRange(true);
    //        rangeAxis.setRange(from, to);
    rangeAxis.setLowerMargin(0.01);
    rangeAxis.setUpperMargin(0.01);

    {
        final Font axisFont = config.getAxisFont();
        if (axisFont != null) {
            rangeAxis.setLabelFont(axisFont);
            plot.getRangeAxis().setLabelFont(axisFont);
        }
    }

    final String xaxisFmt = config.getAxisFormat();

    if (xaxisFmt == null || xaxisFmt.isEmpty()) {
        double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0);
        if (diffInDays < 2)
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance()));
        else
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance()));
    } else
        rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance()));

    final ValueAxis domain = plot.getRangeAxis();
    if (config.getForceYmin() != 0 || config.getForceYmax() != 0)
        domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()),
                ElfValue.valueIntToDouble(config.getForceYmax()));

    // title
    final Font titleFont = config.getTitleFont();
    if (titleFont != null)
        chart.getTitle().setFont(titleFont);

    return chart;
}

From source file:y.graphs.ChartHelperSRB.java

private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config,
        ArrayList<ConfigSerie> series) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleSrbGraph"),
            Config.getResource("TitleDate"), Config.getResource("MsgTitleSrbGraphYAxis"), dataset, true, // include legend
            true, // tooltips
            false // urls
    );//from  w  w  w. j  av  a  2 s .c om

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 12));
    lt.setBackgroundPaint(Color.white);
    lt.setFrame(new BlockBorder(Color.white));
    lt.setVerticalAlignment(VerticalAlignment.CENTER);
    XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt,
            RectangleAnchor.TOP_RIGHT);
    ta.setMaxWidth(config.getLegendSize());
    plot.addAnnotation(ta);
    chart.removeLegend();

    plot.setBackgroundPaint(config.getColorBackgroundSRB());
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    final Stroke lineStroke = new BasicStroke((float) config.getLineWidthSRB());

    for (int si = 0; si < series.size(); si++) {
        final ConfigSerie cs = series.get(si);
        renderer.setSeriesLinesVisible(si, cs.isDrawLine());

        final float size = cs.getShapeSize();
        renderer.setSeriesShapesVisible(si, size > 0);
        if (size > 0)
            renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size));

        renderer.setSeriesStroke(si, lineStroke);
        //          renderer.setSeriesOutlineStroke(si, lineStroke);
        renderer.setSeriesPaint(si, cs.getColor());
    }
    plot.setRenderer(renderer);

    // x axis
    final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis();
    //      rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to
    rangeAxis.setAutoRange(true);
    //        rangeAxis.setRange(from, to);
    rangeAxis.setLowerMargin(0.01);
    rangeAxis.setUpperMargin(0.01);

    {
        final Font axisFont = config.getAxisFont();
        if (axisFont != null) {
            rangeAxis.setLabelFont(axisFont);
            plot.getRangeAxis().setLabelFont(axisFont);
        }
    }

    final String xaxisFmt = config.getAxisFormat();

    if (xaxisFmt == null || xaxisFmt.isEmpty()) {
        double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0);
        if (diffInDays < 2)
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance()));
        else
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance()));
    } else
        rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance()));

    final ValueAxis domain = plot.getRangeAxis();
    if (config.getForceYmin() != 0 || config.getForceYmax() != 0)
        domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()),
                ElfValue.valueIntToDouble(config.getForceYmax()));

    // title
    final Font titleFont = config.getTitleFont();
    if (titleFont != null)
        chart.getTitle().setFont(titleFont);

    return chart;
}

From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java

protected void setChartLegend(JFreeChart jfreeChart) {
    //The legend visibility is already taken into account in the jfreeChart object's constructor
    LegendTitle legend = jfreeChart.getLegend();
    if (legend != null) {
        LegendSettings legendSettings = getLegendSettings();
        JRBaseFont font = new JRBaseFont();
        JRFontUtil.copyNonNullOwnProperties(legendSettings.getFont(), font);
        JRFontUtil.copyNonNullOwnProperties(getChart().getLegendFont(), font);
        font = new JRBaseFont(getChart(), font);
        legend.setItemFont(JRFontUtil.getAwtFont(font, getLocale()));

        Paint forePaint = getChart().getOwnLegendColor();
        if (forePaint == null && legendSettings.getForegroundPaint() != null) {
            forePaint = legendSettings.getForegroundPaint().getPaint();
        }/* w w w . j  av  a2s  .  c o m*/
        if (forePaint == null) {
            forePaint = getChart().getLegendColor();
        }
        if (forePaint != null)
            legend.setItemPaint(forePaint);

        Paint backPaint = getChart().getOwnLegendBackgroundColor();
        if (backPaint == null && legendSettings.getBackgroundPaint() != null) {
            backPaint = legendSettings.getBackgroundPaint().getPaint();
        }
        if (backPaint == null) {
            backPaint = getChart().getLegendBackgroundColor();
        }
        if (backPaint != null)
            legend.setBackgroundPaint(backPaint);

        BlockFrame blockFrame = legendSettings.getBlockFrame();
        if (blockFrame != null)
            legend.setFrame(blockFrame);

        HorizontalAlignment hAlign = legendSettings.getHorizontalAlignment();
        if (hAlign != null)
            legend.setHorizontalAlignment(hAlign);

        VerticalAlignment vAlign = legendSettings.getVerticalAlignment();
        if (vAlign != null)
            legend.setVerticalAlignment(vAlign);

        RectangleInsets padding = legendSettings.getPadding();
        if (padding != null)
            legend.setPadding(padding);

        legend.setPosition(getEdge(getChart().getLegendPositionValue(),
                getEdge(legendSettings.getPositionValue(), RectangleEdge.BOTTOM)));
    }
}

From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

protected void setChartLegend(JFreeChart jfreeChart) {
    //The legend visibility is already taken into account in the jfreeChart object's constructor
    LegendTitle legend = jfreeChart.getLegend();
    if (legend != null) {
        LegendSettings legendSettings = getLegendSettings();
        JRBaseFont font = new JRBaseFont();
        FontUtil.copyNonNullOwnProperties(legendSettings.getFont(), font);
        FontUtil.copyNonNullOwnProperties(getChart().getLegendFont(), font);
        font = new JRBaseFont(getChart(), font);
        legend.setItemFont(getFontUtil().getAwtFont(font, getLocale()));

        Paint forePaint = getChart().getOwnLegendColor();
        if (forePaint == null && legendSettings.getForegroundPaint() != null) {
            forePaint = legendSettings.getForegroundPaint().getPaint();
        }/*from w  w  w  .ja  v a2  s  .c o  m*/
        if (forePaint == null) {
            forePaint = getChart().getLegendColor();
        }
        if (forePaint != null)
            legend.setItemPaint(forePaint);

        Paint backPaint = getChart().getOwnLegendBackgroundColor();
        if (backPaint == null && legendSettings.getBackgroundPaint() != null) {
            backPaint = legendSettings.getBackgroundPaint().getPaint();
        }
        if (backPaint == null) {
            backPaint = getChart().getLegendBackgroundColor();
        }
        if (backPaint != null)
            legend.setBackgroundPaint(backPaint);

        BlockFrame blockFrame = legendSettings.getBlockFrame();
        if (blockFrame != null)
            legend.setFrame(blockFrame);

        HorizontalAlignment hAlign = legendSettings.getHorizontalAlignment();
        if (hAlign != null)
            legend.setHorizontalAlignment(hAlign);

        VerticalAlignment vAlign = legendSettings.getVerticalAlignment();
        if (vAlign != null)
            legend.setVerticalAlignment(vAlign);

        RectangleInsets padding = legendSettings.getPadding();
        if (padding != null)
            legend.setPadding(padding);

        legend.setPosition(getEdge(getChart().getLegendPositionValue(),
                getEdge(legendSettings.getPositionValue(), RectangleEdge.BOTTOM)));
    }
}

From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java

protected void setChartLegend(JFreeChart jfreeChart, Integer baseFontSize) {

    //The legend visibility is already taken into account in the jfreeChart object's constructor

    LegendTitle legend = jfreeChart.getLegend();
    if (legend != null) {
        Font themeLegendFont = getFont(
                (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FONT),
                getChart().getLegendFont(), baseFontSize);
        legend.setItemFont(themeLegendFont);

        Color legendForecolor = getChart().getOwnLegendColor() != null ? getChart().getOwnLegendColor()
                : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FORECOLOR) != null
                        ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                ChartThemesConstants.LEGEND_FORECOLOR)
                        : getChart().getLegendColor());
        if (legendForecolor != null)
            legend.setItemPaint(legendForecolor);

        Color legendBackcolor = getChart().getOwnLegendBackgroundColor() != null
                ? getChart().getOwnLegendBackgroundColor()
                : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_BACKCOLOR) != null
                        ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                ChartThemesConstants.LEGEND_BACKCOLOR)
                        : getChart().getLegendBackgroundColor());
        if (legendBackcolor != null)
            legend.setBackgroundPaint(legendBackcolor);

        BlockFrame frame = (BlockFrame) getDefaultValue(defaultChartPropertiesMap,
                ChartThemesConstants.LEGEND_FRAME);
        if (frame != null)
            legend.setFrame(frame);//from  w w w  . j  a  v  a  2s  .  c o m

        HorizontalAlignment defaultLegendHAlignment = (HorizontalAlignment) getDefaultValue(
                defaultChartPropertiesMap, ChartThemesConstants.LEGEND_HORIZONTAL_ALIGNMENT);
        if (defaultLegendHAlignment != null)
            legend.setHorizontalAlignment(defaultLegendHAlignment);

        VerticalAlignment defaultLegendVAlignment = (VerticalAlignment) getDefaultValue(
                defaultChartPropertiesMap, ChartThemesConstants.LEGEND_VERTICAL_ALIGNMENT);
        if (defaultLegendVAlignment != null)
            legend.setVerticalAlignment(defaultLegendVAlignment);

        RectangleInsets defaultLegendPadding = (RectangleInsets) getDefaultValue(defaultChartPropertiesMap,
                ChartThemesConstants.LEGEND_PADDING);
        RectangleInsets legendPadding = legend.getPadding() != null ? legend.getPadding()
                : defaultLegendPadding;
        if (legendPadding != null)
            legend.setPadding(legendPadding);

        RectangleEdge defaultLegendPosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap,
                ChartThemesConstants.LEGEND_POSITION);
        if (getEdge(getChart().getLegendPositionValue(), defaultLegendPosition) != null)
            legend.setPosition(getEdge(getChart().getLegendPositionValue(), defaultLegendPosition));

    }
}