Example usage for org.jfree.chart.plot PieLabelLinkStyle CUBIC_CURVE

List of usage examples for org.jfree.chart.plot PieLabelLinkStyle CUBIC_CURVE

Introduction

In this page you can find the example usage for org.jfree.chart.plot PieLabelLinkStyle CUBIC_CURVE.

Prototype

PieLabelLinkStyle CUBIC_CURVE

To view the source code for org.jfree.chart.plot PieLabelLinkStyle CUBIC_CURVE.

Click Source Link

Document

CUBIC_CURVE.

Usage

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartPieGraphSource.java

@SuppressWarnings("unchecked")
@Override/*from w w w  .j  av a2s  .co m*/
public void initialize() throws GraphException {
    String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE);
    boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND);
    boolean graphToolTip = getParam(GraphSource.GRAPH_TOOL_TIP, Boolean.class, DEFAULT_GRAPH_TOOL_TIP);
    boolean graphDisplayLabel = getParam(GraphSource.GRAPH_DISPLAY_LABEL, Boolean.class, false);
    boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER);
    boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER);
    Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT);
    String noDataMessage = getParam(GraphSource.GRAPH_NO_DATA_MESSAGE, String.class,
            DEFAULT_GRAPH_NO_DATA_MESSAGE);
    PieGraphData pieGraphData = makeDataSet();
    Map<Comparable, Paint> colors = pieGraphData.colors;

    this.chart = ChartFactory.createPieChart(title, pieGraphData.data, false, graphToolTip, false);

    Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR);
    Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor);
    Paint labelColor = getParam(JFreeChartTimeSeriesGraphSource.GRAPH_LABEL_BACKGROUND_COLOR, Paint.class,
            DEFAULT_BACKGROUND_COLOR);

    this.chart.setBackgroundPaint(backgroundColor);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(plotColor);
    plot.setNoDataMessage(noDataMessage);

    if (!graphDisplayLabel) {
        plot.setLabelGenerator(null);
    } else {
        plot.setInteriorGap(0.001);
        plot.setMaximumLabelWidth(.3);
        //           plot.setIgnoreNullValues(true);
        plot.setIgnoreZeroValues(true);
        plot.setShadowPaint(null);
        //           plot.setOutlineVisible(false);
        //TODO use title font?
        Font font = plot.getLabelFont();
        plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE);
        plot.setLabelFont(font.deriveFont(font.getSize2D() * .75f));
        plot.setLabelBackgroundPaint(labelColor);
        plot.setLabelShadowPaint(null);
        plot.setLabelOutlinePaint(null);
        plot.setLabelGap(0.001);
        plot.setLabelLinkMargin(0.0);
        plot.setLabelLinksVisible(true);
        //           plot.setSimpleLabels(true);
        //           plot.setCircular(true);
    }

    if (!graphBorder) {
        plot.setOutlineVisible(false);
    }

    if (title != null && !"".equals(title)) {
        TextTitle title1 = new TextTitle();
        title1.setText(title);
        title1.setFont(titleFont);
        title1.setPadding(3, 2, 5, 2);
        chart.setTitle(title1);
    } else {
        chart.setTitle((TextTitle) null);
    }
    plot.setLabelPadding(new RectangleInsets(1, 1, 1, 1));
    //Makes a wrapper for the legend to remove the border around it
    if (legend) {
        LegendTitle legend1 = new LegendTitle(chart.getPlot());
        BlockContainer wrapper = new BlockContainer(new BorderArrangement());

        if (legendBorder) {
            wrapper.setFrame(new BlockBorder(1, 1, 1, 1));
        } else {
            wrapper.setFrame(new BlockBorder(0, 0, 0, 0));
        }

        BlockContainer items = legend1.getItemContainer();
        items.setPadding(2, 10, 5, 2);
        wrapper.add(items);
        legend1.setWrapper(wrapper);
        legend1.setPosition(RectangleEdge.BOTTOM);
        legend1.setHorizontalAlignment(HorizontalAlignment.CENTER);

        if (params.get(GraphSource.LEGEND_FONT) instanceof Font) {
            legend1.setItemFont(((Font) params.get(GraphSource.LEGEND_FONT)));
        }

        chart.addSubtitle(legend1);
        plot.setLegendLabelGenerator(new PieGraphLabelGenerator());
    }

    for (Comparable category : colors.keySet()) {
        plot.setSectionPaint(category, colors.get(category));
    }

    plot.setToolTipGenerator(new PieGraphToolTipGenerator(pieGraphData));
    plot.setURLGenerator(new PieGraphURLGenerator(pieGraphData));

    initialized = true;
}

From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java

/**
 * This is a helper method for creating charts and is split off as it does
 * only the chart creation and tweaking of a category chart. All of the
 * decisions for what columns are defined as what and how the data is stored
 * should be done in the method that calls this.
 * <p>//from w w w .  j av  a 2s.c  o  m
 * Given a dataset and other chart properties this will create an
 * appropriate JFreeChart.
 * @param c 
 * 
 * @param dataset
 *            The data to create a chart from.
 * @param chartType
 *            The type of chart to create for the category dataset.
 * @param legendPosition
 *            The position where the legend should appear.
 * @param chartName
 *            The title of the chart.
 * @param yaxisName
 *            The title of the Y axis.
 * @param xaxisName
 *            The title of the X axis.
 * @return A JFreeChart that represents the dataset given.
 */
private static JFreeChart createCategoryChartFromDataset(Chart c, CategoryDataset dataset, ChartType chartType,
        LegendPosition legendPosition, String chartName, String yaxisName, String xaxisName) {

    if (chartType == null || dataset == null) {
        return null;
    }
    boolean showLegend = !legendPosition.equals(LegendPosition.NONE);

    JFreeChart chart;
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    BarRenderer.setDefaultBarPainter(new StandardBarPainter());

    if (chartType == ChartType.BAR) {
        chart = ChartFactory.createBarChart(chartName, xaxisName, yaxisName, dataset, PlotOrientation.VERTICAL,
                showLegend, true, false);

    } else if (chartType == ChartType.PIE) {
        chart = createPieChart(chartName, dataset, TableOrder.BY_ROW, showLegend, true, false);

    } else if (chartType == ChartType.CATEGORY_LINE) {
        chart = ChartFactory.createLineChart(chartName, xaxisName, yaxisName, dataset, PlotOrientation.VERTICAL,
                showLegend, true, false);
    } else {
        throw new IllegalArgumentException("Unknown chart type " + chartType + " for a category dataset.");
    }
    if (chart == null)
        return null;

    if (legendPosition != LegendPosition.NONE) {
        chart.getLegend().setPosition(legendPosition.getRectangleEdge());
        //chart.getTitle().setPadding(4,4,15,4);
    }

    if (chart.getPlot() instanceof MultiplePiePlot) {
        MultiplePiePlot mplot = (MultiplePiePlot) chart.getPlot();
        PiePlot plot = (PiePlot) mplot.getPieChart().getPlot();
        plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE);
        if (showLegend) {
            // for now, legend and items labels are mutually exclusive. Could make this a user pref.
            plot.setLabelGenerator(null);
        }
    }

    if (!c.isAutoYAxisRange()) {
        CategoryPlot plot = chart.getCategoryPlot();
        ValueAxis axis = plot.getRangeAxis();
        axis.setAutoRange(false);
        axis.setRange(c.getYAxisMinRange(), c.getYAxisMaxRange());
    }

    return chart;
}