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

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

Introduction

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

Prototype

public Font getItemFont() 

Source Link

Document

Returns the item font.

Usage

From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java

public static JFreeChart createXYChart(String title, XYDataset data, String xLabel, String yLabel,
        int pointRadius, int lineThickness, ColorTheme theme) {
    JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, data, PlotOrientation.VERTICAL,
            true, false, false);/* w  w  w. j  a  v  a  2  s.c  o m*/

    formatColorTheme(chart, theme);

    XYPlot plot = (XYPlot) chart.getPlot();
    Shape icon = new Ellipse2D.Double(-pointRadius, -pointRadius, pointRadius * 2, pointRadius * 2);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);

    Color[] colors = generateJetSpectrum(data.getSeriesCount());
    for (int i = 0; i < data.getSeriesCount(); i++) {
        plot.getRenderer().setSeriesStroke(i, new BasicStroke(lineThickness));
        plot.getRenderer().setSeriesShape(i, icon);
        ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesVisible(i, true);
        ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesFilled(i, true);
        plot.getRenderer().setSeriesPaint(i, colors[i]);
    }

    LegendTitle legend = chart.getLegend();
    Font legendFont = legend.getItemFont();
    float legendFontSize = legendFont.getSize();
    Font newLegendFont = legendFont.deriveFont(legendFontSize * 0.6f);
    legend.setItemFont(newLegendFont);

    ValueAxis domainAxis = ((XYPlot) chart.getPlot()).getDomainAxis();
    Font domainAxisLabelFont = domainAxis.getLabelFont();
    float domainAxisLabelFontSize = domainAxisLabelFont.getSize();
    domainAxis.setLabelFont(domainAxisLabelFont.deriveFont(domainAxisLabelFontSize * 0.6f));

    Font domainAxisTickLabelFont = domainAxis.getTickLabelFont();
    float domainAxisTickLabelFontSize = domainAxisTickLabelFont.getSize();
    domainAxis.setTickLabelFont(domainAxisTickLabelFont.deriveFont(domainAxisTickLabelFontSize * 0.6f));

    ValueAxis rangeAxis = ((XYPlot) chart.getPlot()).getRangeAxis();
    Font rangeAxisLabelFont = rangeAxis.getLabelFont();
    float rangeAxisLabelFontSize = rangeAxisLabelFont.getSize();
    rangeAxis.setLabelFont(rangeAxisLabelFont.deriveFont(rangeAxisLabelFontSize * 0.6f));

    Font rangeAxisTickLabelFont = rangeAxis.getTickLabelFont();
    float rangeAxisTickLabelFontSize = rangeAxisTickLabelFont.getSize();
    rangeAxis.setTickLabelFont(rangeAxisTickLabelFont.deriveFont(rangeAxisTickLabelFontSize * 0.6f));

    return chart;
}

From source file:jmemorize.gui.swing.panels.CardCounterPanel.java

private void setupPieLegend(JFreeChart chart) {
    LegendTitle legend = chart.getLegend();
    Font legendFont = legend.getItemFont();
    legend.setItemFont(legendFont.deriveFont(Font.BOLD, 20));
}

From source file:net.sf.dynamicreports.test.jasper.chart.ChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);//ww  w.j  a v a  2s.  c om

    chartCountTest("summary.chart1", 1);
    JFreeChart chart = getChart("summary.chart1", 0);

    TextTitle title = chart.getTitle();
    Assert.assertEquals("title", "title", title.getText());
    Assert.assertEquals("title color", Color.BLUE, title.getPaint());
    Assert.assertEquals("title font", new Font("Arial", Font.BOLD, 10), title.getFont());
    Assert.assertEquals("title position", RectangleEdge.RIGHT, title.getPosition());

    TextTitle subtitle = (TextTitle) chart.getSubtitle(1);
    Assert.assertEquals("subtitle", "subtitle", subtitle.getText());
    Assert.assertEquals("subtitle color", Color.CYAN, subtitle.getPaint());
    Assert.assertEquals("subtitle font", new Font("Arial", Font.PLAIN, 10), subtitle.getFont());

    LegendTitle legend = (LegendTitle) chart.getSubtitle(0);
    Assert.assertEquals("legend color", Color.BLUE, legend.getItemPaint());
    Assert.assertEquals("legend backgroundcolor", Color.LIGHT_GRAY, legend.getBackgroundPaint());
    Assert.assertEquals("legend font", new Font("Courier New", Font.PLAIN, 10), legend.getItemFont());
    Assert.assertEquals("legend position", RectangleEdge.LEFT, legend.getPosition());

    chartCountTest("summary.chart2", 1);
    chart = getChart("summary.chart2", 0);
    Assert.assertNull("legend", chart.getLegend());
    Assert.assertEquals("plot orientation", PlotOrientation.HORIZONTAL,
            chart.getCategoryPlot().getOrientation());
    Assert.assertEquals("plot series colors", Color.BLUE, chart.getPlot().getDrawingSupplier().getNextPaint());
    Assert.assertEquals("plot series colors", Color.GREEN, chart.getPlot().getDrawingSupplier().getNextPaint());
    Assert.assertEquals("plot series colors", Color.RED, chart.getPlot().getDrawingSupplier().getNextPaint());
}

From source file:jmemorize.gui.swing.panels.DeckChartPanel.java

private JFreeChart createChart() {
    m_dataset = createDefaultDataSet();//from  w ww.  j  a  v  a  2s.  c o m

    JFreeChart chart = ChartFactory.createStackedBarChart3D(null, // chart title
            null, // domain axis label
            Localization.get("DeckChart.CARDS"), // range axis label //$NON-NLS-1$
            m_dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    // setup legend
    // TODO we used to do this for the old jfreechar version, but it's not clear why.
    // can we get rid of it?
    LegendTitle legend = chart.getLegend();
    //        legend.setsetRenderingOrder(LegendRenderingOrder.REVERSE);
    legend.setItemFont(legend.getItemFont().deriveFont(11f));

    // setup plot
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    TickUnitSource tickUnits = NumberAxis.createIntegerTickUnits();
    plot.getRangeAxis().setStandardTickUnits(tickUnits); //CHECK use locale
    plot.setForegroundAlpha(0.99f);

    // setup renderer
    m_barRenderer = new MyBarRenderer();
    m_barRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    m_barRenderer.setItemLabelsVisible(true);
    m_barRenderer
            .setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    plot.setRenderer(m_barRenderer);
    setSeriesPaint();

    return chart;
}

From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java

/** Generate CGI chart output. */
@Override/*from   www  .  j  a v a2 s.c o m*/
protected void writeContents() throws IOException {
    buildData(); // get the data for display

    chromeless = (parameters.get("chromeless") != null);
    JFreeChart chart = createChart();

    int width = getIntSetting("width");
    int height = getIntSetting("height");
    Color initGradColor = getColorSetting("initGradColor");
    Color finalGradColor = getColorSetting("finalGradColor");
    chart.setBackgroundPaint(new GradientPaint(0, 0, initGradColor, width, height, finalGradColor));
    if (parameters.get("hideOutline") != null)
        chart.getPlot().setOutlinePaint(INVISIBLE);

    String title = getSetting("title");
    if (chromeless || title == null || title.length() == 0)
        chart.setTitle((TextTitle) null);
    else {
        chart.setTitle(Translator.translate(title));
        String titleFontSize = getSetting("titleFontSize");
        if (titleFontSize != null)
            try {
                float fontSize = Float.parseFloat(titleFontSize);
                TextTitle t = chart.getTitle();
                t.setFont(t.getFont().deriveFont(fontSize));
            } catch (Exception tfe) {
            }
    }

    if (chromeless || parameters.get("hideLegend") != null)
        chart.removeLegend();
    else {
        LegendTitle l = chart.getLegend();
        String legendFontSize = getSetting("legendFontSize");
        if (l != null && legendFontSize != null)
            try {
                float fontSize = Float.parseFloat(legendFontSize);
                l.setItemFont(l.getItemFont().deriveFont(fontSize));
            } catch (Exception lfe) {
            }
    }

    chart.getPlot().setNoDataMessage(resources.getString("No_Data_Message"));

    Axis xAxis = getHorizontalAxis(chart);
    if (xAxis != null) {
        if (parameters.get("hideTickLabels") != null || parameters.get("hideXTickLabels") != null) {
            xAxis.setTickLabelsVisible(false);
        } else if (parameters.get("tickLabelFontSize") != null
                || parameters.get("xTickLabelFontSize") != null) {
            String tfs = getParameter("xTickLabelFontSize");
            if (tfs == null)
                tfs = getParameter("tickLabelFontSize");
            float fontSize = Float.parseFloat(tfs);
            xAxis.setTickLabelFont(xAxis.getTickLabelFont().deriveFont(fontSize));
        }
    }

    Axis yAxis = getVerticalAxis(chart);
    if (yAxis != null) {
        if (parameters.get("hideTickLabels") != null || parameters.get("hideYTickLabels") != null) {
            yAxis.setTickLabelsVisible(false);
        } else if (parameters.get("tickLabelFontSize") != null
                || parameters.get("yTickLabelFontSize") != null) {
            String tfs = getParameter("yTickLabelFontSize");
            if (tfs == null)
                tfs = getParameter("tickLabelFontSize");
            float fontSize = Float.parseFloat(tfs);
            yAxis.setTickLabelFont(yAxis.getTickLabelFont().deriveFont(fontSize));
        }
    }

    String axisFontSize = getSetting("axisLabelFontSize");
    if (axisFontSize != null)
        try {
            float fontSize = Float.parseFloat(axisFontSize);
            if (xAxis != null)
                xAxis.setLabelFont(xAxis.getLabelFont().deriveFont(fontSize));
            if (yAxis != null)
                yAxis.setLabelFont(yAxis.getLabelFont().deriveFont(fontSize));
        } catch (Exception afs) {
        }

    ChartRenderingInfo info = (isHtmlMode() ? new ChartRenderingInfo() : null);
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = img.createGraphics();
    if ("auto".equals(getSetting("titleFontSize")))
        maybeAdjustTitleFontSize(chart, g2, width);
    chart.draw(g2, new Rectangle2D.Double(0, 0, width, height), info);
    g2.dispose();

    String outputFormat = getSetting("outputFormat");
    OutputStream imgOut;
    if (isHtmlMode()) {
        imgOut = PngCache.getOutputStream();
    } else {
        imgOut = outStream;
    }
    ImageIO.write(img, outputFormat, imgOut);
    imgOut.flush();
    imgOut.close();
    if (isHtmlMode())
        writeImageHtml(width, height, imgOut.hashCode(), info);
}

From source file:com.chart.SwingChart.java

/**
 * Send node to printer//from w w w  .  j a  v  a2 s  .c  o m
 * @param node JavaFX node
 */
public final void print(final Node node) {
    LegendTitle legend = new LegendTitle(chart.getPlot());
    legend.setItemFont(legend.getItemFont().deriveFont(fontSize));
    chart.addLegend(legend);
    legend.setPosition(RectangleEdge.BOTTOM);
    chart.setTitle(name);
    chartPanel.createChartPrintJob();
    chart.removeLegend();
    chart.setTitle("");
}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, double shiftX, double shiftY) {
    //       g2.setPaint(Color.white);
    //      g2.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
    //      if (getChart() != null) {
    ////         Image chartImage = getChart().createBufferedImage((int) area.getWidth(),
    ////               (int) area.getHeight());
    ////         g2.drawImage(chartImage, (int) area.getMinX(), (int) area.getMinY(), 
    ////               this);
    //         getChart().draw(g2, area, getAnchor(), null);
    //         ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), maskList, 
    //               null, getChart());
    //      }//from ww  w  .j a va  2 s.c om
    double widthRatio = area.getWidth() / getWidth();
    double heightRatio = area.getHeight() / getHeight();
    double overallRatio = 1;
    overallRatio = widthRatio < heightRatio ? widthRatio : heightRatio;

    XYPlot plot = (XYPlot) getChart().getPlot();
    Font domainFont = plot.getDomainAxis().getLabelFont();
    int domainSize = domainFont.getSize();
    Font rangeFont = plot.getRangeAxis().getLabelFont();
    int rangeSize = rangeFont.getSize();
    TextTitle titleBlock = getChart().getTitle();
    Font titleFont = null;
    int titleSize = 0;
    if (titleBlock != null) {
        titleFont = titleBlock.getFont();
        titleSize = titleFont.getSize();
        getChart().getTitle().setFont(titleFont.deriveFont((float) (titleSize * overallRatio)));
    }
    Font domainScaleFont = plot.getDomainAxis().getTickLabelFont();
    int domainScaleSize = domainScaleFont.getSize();
    Font rangeScaleFont = plot.getRangeAxis().getTickLabelFont();
    int rangeScaleSize = rangeScaleFont.getSize();
    plot.getDomainAxis().setLabelFont(domainFont.deriveFont((float) (domainSize * overallRatio)));
    plot.getRangeAxis().setLabelFont(rangeFont.deriveFont((float) (rangeSize * overallRatio)));
    plot.getDomainAxis().setTickLabelFont(domainScaleFont.deriveFont((float) (domainScaleSize * overallRatio)));
    plot.getRangeAxis().setTickLabelFont(rangeScaleFont.deriveFont((float) (rangeScaleSize * overallRatio)));
    LegendTitle legend = getChart().getLegend();
    Font legendFont = null;
    int legendFontSize = 0;
    if (legend != null) {
        legendFont = legend.getItemFont();
        legendFontSize = legendFont.getSize();
        legend.setItemFont(legendFont.deriveFont((float) (legendFontSize * overallRatio)));
    }

    Rectangle2D chartArea = (Rectangle2D) area.clone();
    getChart().getPadding().trim(chartArea);
    if (titleBlock != null) {
        AxisUtilities.trimTitle(chartArea, g2, titleBlock, titleBlock.getPosition());
    }

    Axis scaleAxis = null;
    Font scaleAxisFont = null;
    int scaleAxisFontSize = 0;
    for (Object object : getChart().getSubtitles()) {
        Title title = (Title) object;
        if (title instanceof PaintScaleLegend) {
            scaleAxis = ((PaintScaleLegend) title).getAxis();
            scaleAxisFont = scaleAxis.getTickLabelFont();
            scaleAxisFontSize = scaleAxisFont.getSize();
            scaleAxis.setTickLabelFont(scaleAxisFont.deriveFont((float) (scaleAxisFontSize * overallRatio)));
        }
        AxisUtilities.trimTitle(chartArea, g2, title, title.getPosition());
    }
    AxisSpace axisSpace = AxisUtilities.calculateAxisSpace(getChart().getXYPlot(), g2, chartArea);
    Rectangle2D dataArea = axisSpace.shrink(chartArea, null);
    getChart().getXYPlot().getInsets().trim(dataArea);
    getChart().getXYPlot().getAxisOffset().trim(dataArea);

    //        Rectangle2D screenArea = getScreenDataArea();
    //        Rectangle2D visibleArea = getVisibleRect();
    //        Rectangle2D printScreenArea = new Rectangle2D.Double(screenArea.getMinX() * overallRatio + x, 
    //              screenArea.getMinY() * overallRatio + y, 
    //              printArea.getWidth() - visibleArea.getWidth() + screenArea.getWidth(), 
    //              printArea.getHeight() - visibleArea.getHeight() + screenArea.getHeight());

    getChart().draw(g2, area, getAnchor(), null);
    ChartMaskingUtilities.drawMasks(g2, dataArea, maskList, null, getChart(), overallRatio);
    ChartMaskingUtilities.drawShapes(g2, dataArea, shapeMap, getChart());
    ChartMaskingUtilities.drawText(g2, dataArea, textContentMap, getChart());
    plot.getDomainAxis().setLabelFont(domainFont);
    plot.getRangeAxis().setLabelFont(rangeFont);
    if (titleBlock != null) {
        titleBlock.setFont(titleFont);
    }
    if (legend != null) {
        legend.setItemFont(legendFont);
    }
    plot.getDomainAxis().setTickLabelFont(domainScaleFont);
    plot.getRangeAxis().setTickLabelFont(rangeScaleFont);
    if (scaleAxis != null) {
        scaleAxis.setTickLabelFont(scaleAxisFont);
    }
    //        System.out.println("print " + titleBlock.getText() + 
    //              " at [" + area.getX() + ", " + area.getY() + ", " + 
    //              area.getWidth() + ", " + area.getHeight() + "]");
}

From source file:userinterface.graph.Histogram.java

/**
 * Update the settings of the graph if the settings changed
 *///  w  w w  . jav  a 2s  .c o m
public void updateGraph() {

    /* Update title if necessary. */
    if (!this.chart.getTitle().equals(graphTitle)) {
        this.chart.setTitle(graphTitle.getStringValue());
    }

    /* Update title font if necessary. */
    if (!titleFont.getFontColorValue().f.equals(this.chart.getTitle().getFont())) {
        this.chart.getTitle().setFont(titleFont.getFontColorValue().f);
    }

    /* Update title colour if necessary. */
    if (!titleFont.getFontColorValue().c.equals(this.chart.getTitle().getPaint())) {
        this.chart.getTitle().setPaint(titleFont.getFontColorValue().c);
    }

    if (legendVisible.getBooleanValue() != (this.chart.getLegend() != null)) {
        if (!legendVisible.getBooleanValue()) {
            this.chart.removeLegend();
        } else {
            LegendTitle legend = new LegendTitle(plot.getRenderer());
            legend.setBackgroundPaint(Color.white);
            legend.setBorder(1, 1, 1, 1);

            this.chart.addLegend(legend);
        }
    }

    if (this.chart.getLegend() != null) {
        LegendTitle legend = this.chart.getLegend();

        /* Put legend on the left if appropriate. */
        if ((legendPosition.getCurrentIndex() == Graph.LEFT)
                && !legend.getPosition().equals(RectangleEdge.LEFT)) {
            legend.setPosition(RectangleEdge.LEFT);
        }
        /* Put legend on the right if appropriate. */
        if ((legendPosition.getCurrentIndex() == Graph.RIGHT)
                && !legend.getPosition().equals(RectangleEdge.RIGHT)) {
            legend.setPosition(RectangleEdge.RIGHT);
        }
        /* Put legend on the top if appropriate. */
        if ((legendPosition.getCurrentIndex() == Graph.TOP)
                && !legend.getPosition().equals(RectangleEdge.TOP)) {
            legend.setPosition(RectangleEdge.TOP);
        }
        /* Put legend on the bottom if appropriate. */
        if ((legendPosition.getCurrentIndex() == Graph.BOTTOM)
                && !legend.getPosition().equals(RectangleEdge.BOTTOM)) {
            legend.setPosition(RectangleEdge.BOTTOM);
        }

        /* Set legend font. */
        if (!legend.getItemFont().equals(legendFont.getFontColorValue().f)) {
            legend.setItemFont(legendFont.getFontColorValue().f);
        }
        /* Set legend font colour. */
        if (!legend.getItemPaint().equals(legendFont.getFontColorValue().c)) {
            legend.setItemPaint(legendFont.getFontColorValue().c);
        }
    }

    super.repaint();
    doEnables();
}

From source file:userinterface.graph.Graph.java

private void updateGraph() {
    /* Update title if necessary. */
    if (!this.chart.getTitle().equals(graphTitle)) {
        this.chart.setTitle(graphTitle.getStringValue());
    }//ww  w . j a  v  a2 s  .co  m

    /* Update title font if necessary. */
    if (!titleFont.getFontColorValue().f.equals(this.chart.getTitle().getFont())) {
        this.chart.getTitle().setFont(titleFont.getFontColorValue().f);
    }

    /* Update title colour if necessary. */
    if (!titleFont.getFontColorValue().c.equals(this.chart.getTitle().getPaint())) {
        this.chart.getTitle().setPaint(titleFont.getFontColorValue().c);
    }

    if (legendVisible.getBooleanValue() != (this.chart.getLegend() != null)) {
        if (!legendVisible.getBooleanValue()) {
            this.chart.removeLegend();
        } else {
            LegendTitle legend = new LegendTitle(plot.getRenderer());
            legend.setBackgroundPaint(Color.white);
            legend.setBorder(1, 1, 1, 1);

            this.chart.addLegend(legend);
        }
    }

    if (this.chart.getLegend() != null) {
        LegendTitle legend = this.chart.getLegend();

        /* Put legend on the left if appropriate. */
        if ((legendPosition.getCurrentIndex() == LEFT) && !legend.getPosition().equals(RectangleEdge.LEFT)) {
            legend.setPosition(RectangleEdge.LEFT);
        }
        /* Put legend on the right if appropriate. */
        if ((legendPosition.getCurrentIndex() == RIGHT) && !legend.getPosition().equals(RectangleEdge.RIGHT)) {
            legend.setPosition(RectangleEdge.RIGHT);
        }
        /* Put legend on the top if appropriate. */
        if ((legendPosition.getCurrentIndex() == TOP) && !legend.getPosition().equals(RectangleEdge.TOP)) {
            legend.setPosition(RectangleEdge.TOP);
        }
        /* Put legend on the bottom if appropriate. */
        if ((legendPosition.getCurrentIndex() == BOTTOM)
                && !legend.getPosition().equals(RectangleEdge.BOTTOM)) {
            legend.setPosition(RectangleEdge.BOTTOM);
        }

        /* Set legend font. */
        if (!legend.getItemFont().equals(legendFont.getFontColorValue().f)) {
            legend.setItemFont(legendFont.getFontColorValue().f);
        }
        /* Set legend font colour. */
        if (!legend.getItemPaint().equals(legendFont.getFontColorValue().c)) {
            legend.setItemPaint(legendFont.getFontColorValue().c);
        }
    }

    super.repaint();
    doEnables();
}