Example usage for org.jfree.chart.title TextTitle setFont

List of usage examples for org.jfree.chart.title TextTitle setFont

Introduction

In this page you can find the example usage for org.jfree.chart.title TextTitle setFont.

Prototype

public void setFont(Font font) 

Source Link

Document

Sets the font used to display the title string.

Usage

From source file:org.operamasks.faces.render.graph.ChartRenderer.java

private TextTitle createTitle(UITitle titlecomp) {
    FacesContext context = FacesContext.getCurrentInstance();
    String text = FacesUtils.getFormattedValue(context, titlecomp, titlecomp.getValue());
    TextTitle title = new TextTitle(text);

    Font font = titlecomp.getFont();
    if (font != null) {
        title.setFont(font);
    }//from  ww  w .  j a v a 2  s .  co  m

    Paint color = titlecomp.getColor();
    if (color != null) {
        title.setPaint(color);
    }

    Paint bgcolor = titlecomp.getBackgroundColor();
    if (bgcolor != null) {
        title.setBackgroundPaint(bgcolor);
    }

    PositionType position = titlecomp.getPosition();
    if (position != null) {
        setTitlePosition(title, position);
    }

    return title;
}

From source file:ro.nextreports.engine.chart.JFreeChartExporter.java

private void setTitle(JFreeChart jfreechart) {
    TextTitle title = new TextTitle(StringUtil.getI18nString(replaceParameters(chart.getTitle().getTitle()),
            I18nUtil.getLanguageByName(chart, language)));
    title.setFont(chart.getTitle().getFont());
    title.setPaint(chart.getTitle().getColor());
    if (chart.getTitle().getAlignment() == ChartTitle.LEFT_ALIGNMENT) {
        title.setHorizontalAlignment(HorizontalAlignment.LEFT);
    } else if (chart.getTitle().getAlignment() == ChartTitle.RIGHT_ALIGNMENT) {
        title.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    } else {//from  w ww .ja v  a2s .  co m
        title.setHorizontalAlignment(HorizontalAlignment.CENTER);
    }
    jfreechart.setTitle(title);
}

From source file:lucee.runtime.tag.Chart.java

private void setFont(JFreeChart chart, Font font) {
    // title//  w  ww. j  a v a 2  s  .  c  o m
    TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(font);
        title.setPaint(foregroundcolor);
        chart.setTitle(title);
    }

    // axis fonts
    Plot plot = chart.getPlot();
    if (plot instanceof CategoryPlot) {
        CategoryPlot cp = (CategoryPlot) plot;
        setAxis(cp.getRangeAxis(), font);
        setAxis(cp.getDomainAxis(), font);
    }
    if (plot instanceof XYPlot) {
        XYPlot cp = (XYPlot) plot;
        setAxis(cp.getRangeAxis(), font);
        setAxis(cp.getDomainAxis(), font);
    }

}

From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java

/**
 *
 *//*from  w ww  .  ja va 2s.c  o m*/
protected void configureChart(JFreeChart jfreeChart) throws JRException {
    if (getChart().getModeValue() == ModeEnum.OPAQUE) {
        jfreeChart.setBackgroundPaint(getChart().getBackcolor());
    } else {
        jfreeChart.setBackgroundPaint(null);
    }

    RectangleEdge titleEdge = getEdge(getChart().getTitlePositionValue(), RectangleEdge.TOP);

    if (jfreeChart.getTitle() != null) {
        TextTitle title = jfreeChart.getTitle();
        title.setPaint(getChart().getTitleColor());

        title.setFont(fontUtil.getAwtFont(getFont(getChart().getTitleFont()), getLocale()));
        title.setPosition(titleEdge);
    }

    String subtitleText = evaluateTextExpression(getChart().getSubtitleExpression());
    if (subtitleText != null) {
        TextTitle subtitle = new TextTitle(subtitleText);
        subtitle.setPaint(getChart().getSubtitleColor());

        subtitle.setFont(fontUtil.getAwtFont(getFont(getChart().getSubtitleFont()), getLocale()));
        subtitle.setPosition(titleEdge);

        jfreeChart.addSubtitle(subtitle);
    }

    // Apply all of the legend formatting options
    LegendTitle legend = jfreeChart.getLegend();
    if (legend != null) {
        legend.setItemPaint(getChart().getLegendColor());

        if (getChart().getOwnLegendBackgroundColor() == null)// in a way, legend backcolor inheritance from chart is useless
        {
            legend.setBackgroundPaint(null);
        } else {
            legend.setBackgroundPaint(getChart().getLegendBackgroundColor());
        }

        legend.setItemFont(fontUtil.getAwtFont(getFont(getChart().getLegendFont()), getLocale()));
        legend.setPosition(getEdge(getChart().getLegendPositionValue(), RectangleEdge.BOTTOM));
    }

    configurePlot(jfreeChart.getPlot());
}

From source file:semaforo.Semaforo.java

public static void SemaforoGrafico(JFreeChart chart) {

    // set a custom background for the chart
    chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), Color.BLACK, new Point(400, 200), Color.BLACK));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 0));
    PiePlot plot = null;// w w  w  .  j  ava2 s  .  com
    plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.00);
    plot.setOutlineVisible(true);

    // use gradients and white borders for the section colours

    plot.setBaseSectionOutlinePaint(Color.BLACK);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(0.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 0));
    plot.setLabelLinkPaint(Color.BLACK);
    plot.setLabelLinkStroke(new BasicStroke(0.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.BLACK);
    plot.setLabelBackgroundPaint(null);
    plot.setLabelBackgroundPaint(Color.BLACK);
    plot.setLabelShadowPaint(Color.BLACK);

    // add a subtitle giving the data source       

    // Mostramos la grafica dentro del jPanel1
    panel = new ChartPanel(chart);
    panel.setBackground(Color.BLACK);
    panel.repaint();

    jPanel3.setLayout(null);
    jPanel3.setLayout(new java.awt.BorderLayout());
    jPanel3.remove(panel);
    jPanel3.add(panel);

    jPanel3.repaint();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    jTabbedPane1.setPreferredSize(new Dimension(screenSize.width, screenSize.height));
}

From source file:semaforo.Semaforo.java

public static void editGrafico() {
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);//from w  w w  .j av  a  2  s.  co  m
    double cfd = 0.0;
    double bull = 0.0;
    double bear = 0.0;
    if (countCfd != 0)
        cfd = (countCfd * 100) / (countBear + countBull + countCfd);
    if (countBull != 0)
        bull = ((countBull * 100) / (countBear + countBull + countCfd));
    if (countBear != 0)
        bear = ((countBear * 100) / (countBear + countBull + countCfd));
    Semaforo.l1.setText("CFD (" + String.format("%.2f", cfd) + "%)");
    Semaforo.l2.setText("BULL (" + String.format("%.2f", bull) + "%)");
    Semaforo.l3.setText("BEAR (" + String.format("%.2f", bear) + "%)");
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    pieDataset.setValue("CFD (" + cfd + "%)", new Integer((int) countCfd));
    pieDataset.setValue("BULL (" + bull + "%)", new Integer((int) countBull));
    pieDataset.setValue("BEAR (" + bear + "%)", new Integer((int) countBear));
    JFreeChart chart = null;
    chart = ChartFactory.createPieChart("", // chart title
            pieDataset, // data
            false, // no legend
            false, // tooltips
            false // no URL generation
    );

    // set a custom background for the chart
    chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), Color.BLACK, new Point(400, 200), Color.BLACK));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 0));
    PiePlot plot = null;
    plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.00);
    plot.setOutlineVisible(true);

    // use gradients and white borders for the section colours

    plot.setBaseSectionOutlinePaint(Color.BLACK);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(0.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 0));
    plot.setLabelLinkPaint(Color.BLACK);
    plot.setLabelLinkStroke(new BasicStroke(0.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.BLACK);
    plot.setLabelBackgroundPaint(null);
    plot.setLabelBackgroundPaint(Color.BLACK);
    plot.setLabelShadowPaint(Color.BLACK);

    // add a subtitle giving the data source       

    // Mostramos la grafica dentro del jPanel1
    Semaforo.panel.setChart(chart);
}

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

protected void setChartSubtitles(JFreeChart jfreeChart, Integer baseFontSize) throws JRException {
    Boolean subtitleVisibility = (Boolean) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.SUBTITLE_VISIBLE);

    if (subtitleVisibility != null && subtitleVisibility.booleanValue()) {
        String subtitleText = (String) evaluateExpression(getChart().getSubtitleExpression());
        if (subtitleText != null) {
            TextTitle subtitle = new TextTitle(subtitleText);

            Font themeSubtitleFont = getFont(
                    (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_FONT),
                    getChart().getSubtitleFont(), baseFontSize);
            subtitle.setFont(themeSubtitleFont);

            HorizontalAlignment defaultSubtitleHAlignment = (HorizontalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_HORIZONTAL_ALIGNMENT);
            if (defaultSubtitleHAlignment != null)
                subtitle.setHorizontalAlignment(defaultSubtitleHAlignment);

            VerticalAlignment defaultSubtitleVAlignment = (VerticalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_VERTICAL_ALIGNMENT);
            if (defaultSubtitleVAlignment != null)
                subtitle.setVerticalAlignment(defaultSubtitleVAlignment);

            RectangleInsets defaultSubtitlePadding = (RectangleInsets) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_PADDING);
            RectangleInsets subtitlePadding = subtitle.getPadding() != null ? subtitle.getPadding()
                    : defaultSubtitlePadding;
            if (subtitlePadding != null)
                subtitle.setPadding(subtitlePadding);

            Color subtitleForecolor = getChart().getOwnSubtitleColor() != null
                    ? getChart().getOwnSubtitleColor()
                    : (getDefaultValue(defaultChartPropertiesMap,
                            ChartThemesConstants.SUBTITLE_FORECOLOR) != null
                                    ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                            ChartThemesConstants.SUBTITLE_FORECOLOR)
                                    : getChart().getSubtitleColor());
            if (subtitleForecolor != null)
                subtitle.setPaint(subtitleForecolor);

            Color subtitleBackcolor = getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.SUBTITLE_BACKCOLOR) != null
                            ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                    ChartThemesConstants.SUBTITLE_BACKCOLOR)
                            : null;//from   w w  w .  ja  v  a 2  s  .co  m
            if (subtitleBackcolor != null)
                subtitle.setBackgroundPaint(subtitleBackcolor);

            RectangleEdge defaultSubtitlePosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.SUBTITLE_POSITION);
            //Subtitle has not its own position set, and by default this will be set the same as title position
            RectangleEdge subtitleEdge = null;
            if (defaultSubtitlePosition == null) {
                subtitleEdge = jfreeChart.getTitle().getPosition();
            } else {
                subtitleEdge = defaultSubtitlePosition;
            }
            if (subtitleEdge != null)
                subtitle.setPosition(subtitleEdge);

            jfreeChart.addSubtitle(subtitle);
        }
    }
}

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

protected void handleTitleSettings(TextTitle title, TitleSettings titleSettings, JRFont titleFont,
        Paint titleForegroundPaint, RectangleEdge titleEdge) {
    JRBaseFont font = new JRBaseFont();
    JRFontUtil.copyNonNullOwnProperties(titleSettings.getFont(), font);
    JRFontUtil.copyNonNullOwnProperties(titleFont, font);
    font = new JRBaseFont(getChart(), font);
    title.setFont(JRFontUtil.getAwtFont(font, getLocale()));

    HorizontalAlignment hAlign = titleSettings.getHorizontalAlignment();
    if (hAlign != null)
        title.setHorizontalAlignment(hAlign);

    VerticalAlignment vAlign = titleSettings.getVerticalAlignment();
    if (vAlign != null)
        title.setVerticalAlignment(vAlign);

    RectangleInsets padding = titleSettings.getPadding();
    if (padding != null)
        title.setPadding(padding);//from   w ww .  ja va 2  s .  c o m

    if (titleForegroundPaint != null)
        title.setPaint(titleForegroundPaint);

    Paint backPaint = titleSettings.getBackgroundPaint() != null ? titleSettings.getBackgroundPaint().getPaint()
            : null;
    if (backPaint != null)
        title.setBackgroundPaint(backPaint);
    if (titleEdge != null)
        title.setPosition(titleEdge);
}

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

protected void setChartTitle(JFreeChart jfreeChart, Integer baseFontSize) {
    Boolean titleVisibility = (Boolean) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.TITLE_VISIBLE);
    if (titleVisibility != null && titleVisibility.booleanValue()) {
        TextTitle title = jfreeChart.getTitle();

        RectangleEdge titleEdge = null;/*from  w  ww .j  a  v  a  2 s  . c  o  m*/

        if (title != null) {
            JRFont titleFont = getChart().getTitleFont();

            Font themeTitleFont = getFont(
                    (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_FONT),
                    titleFont, baseFontSize);
            title.setFont(themeTitleFont);

            HorizontalAlignment defaultTitleHAlignment = (HorizontalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.TITLE_HORIZONTAL_ALIGNMENT);
            if (defaultTitleHAlignment != null)
                title.setHorizontalAlignment(defaultTitleHAlignment);

            VerticalAlignment defaultTitleVAlignment = (VerticalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.TITLE_VERTICAL_ALIGNMENT);
            if (defaultTitleVAlignment != null)
                title.setVerticalAlignment(defaultTitleVAlignment);

            RectangleInsets defaultTitlePadding = (RectangleInsets) getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.TITLE_PADDING);
            RectangleInsets titlePadding = title.getPadding() != null ? title.getPadding()
                    : defaultTitlePadding;
            if (titlePadding != null)
                title.setPadding(titlePadding);

            Color titleForecolor = getChart().getOwnTitleColor() != null ? getChart().getOwnTitleColor()
                    : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_FORECOLOR) != null
                            ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                    ChartThemesConstants.TITLE_FORECOLOR)
                            : getChart().getTitleColor());
            if (titleForecolor != null)
                title.setPaint(titleForecolor);

            Color titleBackcolor = (Color) getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.TITLE_BACKCOLOR);
            if (titleBackcolor != null)
                title.setBackgroundPaint(titleBackcolor);

            RectangleEdge defaultTitlePosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.TITLE_POSITION);
            titleEdge = getEdge(getChart().getTitlePositionValue(), defaultTitlePosition);
            if (titleEdge != null)
                title.setPosition(titleEdge);
        }
    } else {
        TextTitle title = null;
        jfreeChart.setTitle(title);
    }
}

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

protected void setChartSubtitles(JFreeChart jfreeChart, Integer baseFontSize) throws JRException {
    Boolean subtitleVisibility = (Boolean) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.SUBTITLE_VISIBLE);

    if (subtitleVisibility != null && subtitleVisibility) {
        String subtitleText = evaluateTextExpression(getChart().getSubtitleExpression());
        if (subtitleText != null) {
            TextTitle subtitle = new TextTitle(subtitleText);

            Font themeSubtitleFont = getFont(
                    (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_FONT),
                    getChart().getSubtitleFont(), baseFontSize);
            subtitle.setFont(themeSubtitleFont);

            HorizontalAlignment defaultSubtitleHAlignment = (HorizontalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_HORIZONTAL_ALIGNMENT);
            if (defaultSubtitleHAlignment != null)
                subtitle.setHorizontalAlignment(defaultSubtitleHAlignment);

            VerticalAlignment defaultSubtitleVAlignment = (VerticalAlignment) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_VERTICAL_ALIGNMENT);
            if (defaultSubtitleVAlignment != null)
                subtitle.setVerticalAlignment(defaultSubtitleVAlignment);

            RectangleInsets defaultSubtitlePadding = (RectangleInsets) getDefaultValue(
                    defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_PADDING);
            RectangleInsets subtitlePadding = subtitle.getPadding() != null ? subtitle.getPadding()
                    : defaultSubtitlePadding;
            if (subtitlePadding != null)
                subtitle.setPadding(subtitlePadding);

            Color subtitleForecolor = getChart().getOwnSubtitleColor() != null
                    ? getChart().getOwnSubtitleColor()
                    : (getDefaultValue(defaultChartPropertiesMap,
                            ChartThemesConstants.SUBTITLE_FORECOLOR) != null
                                    ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                            ChartThemesConstants.SUBTITLE_FORECOLOR)
                                    : getChart().getSubtitleColor());
            if (subtitleForecolor != null)
                subtitle.setPaint(subtitleForecolor);

            Color subtitleBackcolor = getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.SUBTITLE_BACKCOLOR) != null
                            ? (Color) getDefaultValue(defaultChartPropertiesMap,
                                    ChartThemesConstants.SUBTITLE_BACKCOLOR)
                            : null;/*ww w .j a v a2  s. c o m*/
            if (subtitleBackcolor != null)
                subtitle.setBackgroundPaint(subtitleBackcolor);

            RectangleEdge defaultSubtitlePosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap,
                    ChartThemesConstants.SUBTITLE_POSITION);
            //Subtitle has not its own position set, and by default this will be set the same as title position
            RectangleEdge subtitleEdge = null;
            if (defaultSubtitlePosition == null) {
                subtitleEdge = jfreeChart.getTitle().getPosition();
            } else {
                subtitleEdge = defaultSubtitlePosition;
            }
            if (subtitleEdge != null)
                subtitle.setPosition(subtitleEdge);

            jfreeChart.addSubtitle(subtitle);
        }
    }
}