Search in sources :

Example 1 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project bamboobsc by billchen198318.

the class CommonPieChartAction method fillChart.

private void fillChart(String title, List<String> names, List<String> colors, List<Float> values) throws Exception {
    DefaultPieDataset data = new DefaultPieDataset();
    for (int ix = 0; ix < names.size(); ix++) {
        data.setValue(names.get(ix), values.get(ix));
    }
    this.chart = ChartFactory.createPieChart3D(title, data, true, true, false);
    LegendTitle legend = this.chart.getLegend();
    legend.setItemFont(new Font("", Font.TRUETYPE_FONT, 9));
    PiePlot plot = (PiePlot) this.chart.getPlot();
    plot.setCircular(true);
    plot.setBackgroundAlpha(0.9f);
    plot.setForegroundAlpha(0.5f);
    plot.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
    this.setPlotColor(plot, names, colors);
    this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9)));
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) PiePlot(org.jfree.chart.plot.PiePlot) LegendTitle(org.jfree.chart.title.LegendTitle) Font(java.awt.Font)

Example 2 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project processdash by dtuma.

the class CGIChartBase method writeContents.

/** Generate CGI chart output. */
@Override
protected void writeContents() throws IOException {
    // get the data for display
    buildData();
    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);
}
Also used : Color(java.awt.Color) OutputStream(java.io.OutputStream) Rectangle2D(java.awt.geom.Rectangle2D) GradientPaint(java.awt.GradientPaint) LegendTitle(org.jfree.chart.title.LegendTitle) JFreeChart(org.jfree.chart.JFreeChart) GradientPaint(java.awt.GradientPaint) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) TextTitle(org.jfree.chart.title.TextTitle) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) Axis(org.jfree.chart.axis.Axis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ValueAxis(org.jfree.chart.axis.ValueAxis)

Example 3 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project tdq-studio-se by Talend.

the class ChartDecorator method setLegendFont.

/**
 * if it contians CJK, set Font to "Arial Unicode MS".Or else, the Font is "Tahoma".
 *
 * @param chart
 */
private static void setLegendFont(JFreeChart chart) {
    Font font;
    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        // $NON-NLS-1$
        font = new Font("Tahoma", Font.PLAIN, BASE_LEGEND_LABEL_SIZE);
        // get legend label to judge if it contains CJK.
        LegendItemSource[] sources = legend.getSources();
        Set<String> itemLabels = new HashSet<String>();
        for (LegendItemSource source : sources) {
            LegendItemCollection legendItems = source.getLegendItems();
            for (int i = 0; i < legendItems.getItemCount(); i++) {
                String label = legendItems.get(i).getLabel();
                if (label != null) {
                    itemLabels.add(label);
                }
            }
        }
        if (isContainCJKCharacter(itemLabels.toArray())) {
            font = getCJKFont(Font.PLAIN, BASE_LEGEND_LABEL_SIZE);
        }
        legend.setItemFont(font);
    }
}
Also used : LegendItemSource(org.jfree.chart.LegendItemSource) LegendItemCollection(org.jfree.chart.LegendItemCollection) LegendTitle(org.jfree.chart.title.LegendTitle) Font(java.awt.Font) Paint(java.awt.Paint) HashSet(java.util.HashSet)

Example 4 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project nimbus by nimbus-org.

the class JFreeChartFactoryService method createChart.

// JFreeChartFactoryのJavaDoc
public JFreeChart createChart(ChartCondition chartCondition) throws JFreeChartCreateException {
    Plot plot = null;
    try {
        plot = plotFactory.createPlot(chartCondition.getPlotConditions());
    } catch (PlotCreateException e) {
        // プロット生成失敗
        throw new JFreeChartCreateException(e);
    }
    JFreeChart chart = copyJFreeChart(plot);
    // タイトルの設定
    if (chartCondition.getTitle() != null && (chartCondition.getTitleFontName() != null || chartCondition.getTitleFontStyle() != Integer.MIN_VALUE || chartCondition.getTitleFontSize() != Integer.MIN_VALUE)) {
        Font newFont = null;
        TextTitle orgTitle = chart.getTitle();
        if (orgTitle != null) {
            newFont = mergeFont(orgTitle.getFont(), chartCondition.getTitleFontName(), chartCondition.getTitleFontStyle(), chartCondition.getTitleFontSize());
        }
        if (newFont != null) {
            chart.setTitle(new TextTitle(chartCondition.getTitle(), newFont));
        } else {
            chart.setTitle(chartCondition.getTitle());
        }
    } else if (chartCondition.getTitle() != null) {
        // タイトル文字列のみ設定された
        chart.setTitle(chartCondition.getTitle());
    }
    if (chart.getSubtitleCount() > 0) {
        List subList = chart.getSubtitles();
        String defaultFontName = chartCondition.getDefaultSubtitleFontName();
        int defaultFontStyle = chartCondition.getDefaultSubtitleFontStyle();
        int defaultFontSize = chartCondition.getDefaultSubtitleFontSize();
        if (defaultFontName != null || defaultFontStyle != Integer.MIN_VALUE || defaultFontSize != Integer.MIN_VALUE) {
            // サブタイトルすべてにデフォルトのフォントを設定する。
            for (int i = 0; i < subList.size(); i++) {
                Object subtitle = subList.get(i);
                if (subtitle instanceof LegendTitle) {
                    LegendTitle legendTitle = (LegendTitle) subtitle;
                    legendTitle.setItemFont(mergeFont(legendTitle.getItemFont(), defaultFontName, defaultFontStyle, defaultFontSize));
                } else if (subtitle instanceof TextTitle) {
                    TextTitle textTitle = (TextTitle) subtitle;
                    textTitle.setFont(mergeFont(textTitle.getFont(), defaultFontName, defaultFontStyle, defaultFontSize));
                }
            }
        } else {
            // 個々のサブタイトルにフォントを設定
            for (int i = 0; i < subList.size(); i++) {
                String subFontName = chartCondition.getSubtitleFontName(i);
                int subFontStyle = chartCondition.getSubtitleFontStyle(i);
                int subFontSize = chartCondition.getSubtitleFontSize(i);
                if (subFontName == null && subFontStyle == Integer.MIN_VALUE && subFontSize == Integer.MIN_VALUE) {
                    continue;
                }
                Title subtitle = chart.getSubtitle(i);
                if (subtitle instanceof LegendTitle) {
                    LegendTitle legendTitle = (LegendTitle) subtitle;
                    legendTitle.setItemFont(mergeFont(legendTitle.getItemFont(), subFontName, subFontStyle, subFontSize));
                } else if (subtitle instanceof TextTitle) {
                    TextTitle textTitle = (TextTitle) subtitle;
                    textTitle.setFont(mergeFont(textTitle.getFont(), subFontName, subFontStyle, subFontSize));
                }
            }
        }
    }
    return chart;
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) Plot(org.jfree.chart.plot.Plot) XYPlot(org.jfree.chart.plot.XYPlot) Title(org.jfree.chart.title.Title) TextTitle(org.jfree.chart.title.TextTitle) LegendTitle(org.jfree.chart.title.LegendTitle) List(java.util.List) ArrayList(java.util.ArrayList) LegendTitle(org.jfree.chart.title.LegendTitle) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font)

Example 5 with LegendTitle

use of org.jfree.chart.title.LegendTitle in project mafscaling by vimsh.

the class MafRescale method createGraghPanel.

private void createGraghPanel(JPanel dataPanel) {
    JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
    chart.setBorderVisible(true);
    mafChartPanel = new MafChartPanel(chart, this);
    GridBagConstraints gbl_chartPanel = new GridBagConstraints();
    gbl_chartPanel.anchor = GridBagConstraints.PAGE_START;
    gbl_chartPanel.insets = insets0;
    gbl_chartPanel.fill = GridBagConstraints.BOTH;
    gbl_chartPanel.weightx = 1.0;
    gbl_chartPanel.weighty = 1.0;
    gbl_chartPanel.gridx = 0;
    gbl_chartPanel.gridy = 2;
    dataPanel.add(mafChartPanel.getChartPanel(), gbl_chartPanel);
    XYSplineRenderer lineRenderer = new XYSplineRenderer(3);
    lineRenderer.setUseFillPaint(true);
    lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
    Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
    lineRenderer.setSeriesStroke(0, stroke);
    lineRenderer.setSeriesStroke(1, stroke);
    lineRenderer.setSeriesPaint(0, new Color(201, 0, 0));
    lineRenderer.setSeriesPaint(1, new Color(0, 0, 255));
    lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
    lineRenderer.setSeriesShape(1, ShapeUtilities.createUpTriangle((float) 2.5));
    ValueAxis mafvDomain = new NumberAxis(XAxisName);
    ValueAxis mafgsRange = new NumberAxis(YAxisName);
    XYSeriesCollection lineDataset = new XYSeriesCollection();
    lineDataset.addSeries(currMafData);
    lineDataset.addSeries(corrMafData);
    XYPlot plot = chart.getXYPlot();
    plot.setRangePannable(true);
    plot.setDomainPannable(true);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    plot.setBackgroundPaint(new Color(224, 224, 224));
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
    plot.setDataset(0, lineDataset);
    plot.setRenderer(0, lineRenderer);
    plot.setDomainAxis(0, mafvDomain);
    plot.setRangeAxis(0, mafgsRange);
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);
    LegendTitle legend = new LegendTitle(plot.getRenderer());
    legend.setItemFont(new Font("Arial", 0, 10));
    legend.setPosition(RectangleEdge.TOP);
    chart.addLegend(legend);
}
Also used : BasicStroke(java.awt.BasicStroke) GridBagConstraints(java.awt.GridBagConstraints) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) NumberAxis(org.jfree.chart.axis.NumberAxis) XYSplineRenderer(org.jfree.chart.renderer.xy.XYSplineRenderer) DecimalFormat(java.text.DecimalFormat) Color(java.awt.Color) LegendTitle(org.jfree.chart.title.LegendTitle) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

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