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

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

Introduction

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

Prototype

public void setVisible(boolean visible) 

Source Link

Document

Sets a flag that controls whether or not the title should be drawn, and sends a TitleChangeEvent to all registered listeners.

Usage

From source file:net.sf.jasperreports.components.spiderchart.SpiderChartDesignEvaluator.java

/**
 * /*w  ww.j a v  a  2s .co m*/
 */
public static JRRenderable evaluateRenderer(ReportConverter reportConverter, JRComponentElement element) {
    SpiderChartComponent chartComponent = (SpiderChartComponent) element.getComponent();
    ChartSettings chartSettings = chartComponent.getChartSettings();
    SpiderPlot plot = chartComponent.getPlot();

    SpiderWebPlot spiderWebPlot = new SpiderWebPlot(getSampleDataset());

    if (plot.getAxisLineColor() != null) {
        spiderWebPlot.setAxisLinePaint(plot.getAxisLineColor());
    }
    if (plot.getAxisLineWidth() != null) {
        spiderWebPlot.setAxisLineStroke(new BasicStroke(plot.getAxisLineWidth()));
    }
    if (plot.getBackcolor() != null) {
        spiderWebPlot.setBackgroundPaint(plot.getBackcolor());
    }
    if (plot.getBackgroundAlpha() != null) {
        spiderWebPlot.setBackgroundAlpha(plot.getBackgroundAlpha());
    }
    if (plot.getForegroundAlpha() != null) {
        spiderWebPlot.setForegroundAlpha(plot.getForegroundAlpha());
    }
    if (plot.getHeadPercent() != null) {
        spiderWebPlot.setHeadPercent(plot.getHeadPercent());
    }
    if (plot.getInteriorGap() != null) {
        spiderWebPlot.setInteriorGap(plot.getInteriorGap());
    }
    if (plot.getLabelColor() != null) {
        spiderWebPlot.setLabelPaint(plot.getLabelColor());
    }
    if (plot.getLabelFont() != null) {
        spiderWebPlot.setLabelFont(JRFontUtil.getAwtFont(plot.getLabelFont(), Locale.getDefault()));
    }
    if (plot.getLabelGap() != null) {
        spiderWebPlot.setAxisLabelGap(plot.getLabelGap());
    }

    spiderWebPlot.setMaxValue(MAX_VALUE);

    if (plot.getRotation() != null) {
        spiderWebPlot.setDirection(plot.getRotation().getRotation());
    }
    if (plot.getStartAngle() != null) {
        spiderWebPlot.setStartAngle(plot.getStartAngle());
    }
    if (plot.getTableOrder() != null) {
        spiderWebPlot.setDataExtractOrder(plot.getTableOrder().getOrder());
    }
    if (plot.getWebFilled() != null) {
        spiderWebPlot.setWebFilled(plot.getWebFilled());
    }

    spiderWebPlot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    spiderWebPlot.setLabelGenerator(new StandardCategoryItemLabelGenerator());

    String titleText = JRExpressionUtil.getExpressionText(chartSettings.getTitleExpression());

    Font titleFont = chartSettings.getTitleFont() != null
            ? JRFontUtil.getAwtFont(chartSettings.getTitleFont(), Locale.getDefault())
            : TextTitle.DEFAULT_FONT;

    JFreeChart jfreechart = new JFreeChart(titleText, titleFont, spiderWebPlot, true);

    if (chartSettings.getBackcolor() != null) {
        jfreechart.setBackgroundPaint(chartSettings.getBackcolor());
    }

    RectangleEdge titleEdge = getEdge(chartSettings.getTitlePosition(), RectangleEdge.TOP);

    if (titleText != null) {
        TextTitle title = jfreechart.getTitle();
        title.setText(titleText);
        if (chartSettings.getTitleColor() != null) {
            title.setPaint(chartSettings.getTitleColor());
        }

        title.setFont(titleFont);
        title.setPosition(titleEdge);
        jfreechart.setTitle(title);
    }

    String subtitleText = JRExpressionUtil.getExpressionText(chartSettings.getSubtitleExpression());
    if (subtitleText != null) {
        TextTitle subtitle = new TextTitle(subtitleText);
        subtitle.setText(subtitleText);
        if (chartSettings.getSubtitleColor() != null) {
            subtitle.setPaint(chartSettings.getSubtitleColor());
        }

        if (chartSettings.getSubtitleColor() != null) {
            Font subtitleFont = chartSettings.getSubtitleFont() != null
                    ? JRFontUtil.getAwtFont(chartSettings.getSubtitleFont(), Locale.getDefault())
                    : TextTitle.DEFAULT_FONT;
            subtitle.setFont(subtitleFont);
        }

        subtitle.setPosition(titleEdge);

        jfreechart.addSubtitle(subtitle);
    }

    // Apply all of the legend formatting options
    LegendTitle legend = jfreechart.getLegend();
    if (legend != null) {
        legend.setVisible((chartSettings.getShowLegend() == null || chartSettings.getShowLegend()));
        if (legend.isVisible()) {
            if (chartSettings.getLegendColor() != null) {
                legend.setItemPaint(chartSettings.getLegendColor());
            }
            if (chartSettings.getLegendBackgroundColor() != null) {
                legend.setBackgroundPaint(chartSettings.getLegendBackgroundColor());
            }

            if (chartSettings.getLegendFont() != null) {
                legend.setItemFont(JRFontUtil.getAwtFont(chartSettings.getLegendFont(), Locale.getDefault()));
            }
            legend.setPosition(getEdge(chartSettings.getLegendPosition(), RectangleEdge.BOTTOM));
        }
    }

    Rectangle2D rectangle = new Rectangle2D.Double(0, 0, element.getWidth(), element.getHeight());

    String renderType = chartSettings.getRenderType();
    if (renderType == null) {
        renderType = JRProperties.getProperty(reportConverter.getReport(), JRChart.PROPERTY_CHART_RENDER_TYPE);
    }

    return ChartUtil.getChartRendererFactory(renderType).getRenderer(jfreechart, null, rectangle);
}

From source file:net.sf.jasperreports.components.spiderchart.SpiderChartRendererEvaluator.java

/**
 * //from w  ww . j  a v a 2s.com
 */
public static Renderable evaluateRenderable(JasperReportsContext jasperReportsContext,
        JRComponentElement element, SpiderChartSharedBean spiderchartBean, ChartCustomizer chartCustomizer,
        String defaultRenderType, String datasetType) {
    SpiderChartComponent chartComponent = (SpiderChartComponent) element.getComponent();
    ChartSettings chartSettings = chartComponent.getChartSettings();
    SpiderPlot plot = (SpiderPlot) chartComponent.getPlot();

    DefaultCategoryDataset dataset = null;
    StandardCategoryItemLabelGenerator labelGenerator = null;

    if (FILL_DATASET.equals(datasetType)) {
        dataset = ((FillSpiderDataset) spiderchartBean.getDataset()).getCustomDataset();
        labelGenerator = ((FillSpiderDataset) spiderchartBean.getDataset()).getLabelGenerator();
    } else {
        dataset = getSampleDataset();
        labelGenerator = new StandardCategoryItemLabelGenerator();
    }

    SpiderWebPlot spiderWebPlot = new SpiderWebPlot(dataset);

    if (plot.getAxisLineColor() != null) {
        spiderWebPlot.setAxisLinePaint(plot.getAxisLineColor());
    }
    if (plot.getAxisLineWidth() != null) {
        spiderWebPlot.setAxisLineStroke(new BasicStroke(plot.getAxisLineWidth()));
    }
    if (plot.getBackcolor() != null) {
        spiderWebPlot.setBackgroundPaint(plot.getBackcolor());
    }
    if (plot.getBackgroundAlpha() != null) {
        spiderWebPlot.setBackgroundAlpha(plot.getBackgroundAlpha());
    }
    if (plot.getForegroundAlpha() != null) {
        spiderWebPlot.setForegroundAlpha(plot.getForegroundAlpha());
    }
    if (plot.getHeadPercent() != null) {
        spiderWebPlot.setHeadPercent(plot.getHeadPercent());
    }
    if (plot.getInteriorGap() != null) {
        spiderWebPlot.setInteriorGap(plot.getInteriorGap());
    }
    if (plot.getLabelColor() != null) {
        spiderWebPlot.setLabelPaint(plot.getLabelColor());
    }
    if (plot.getLabelFont() != null) {
        spiderWebPlot.setLabelFont(FontUtil.getInstance(jasperReportsContext).getAwtFont(plot.getLabelFont(),
                Locale.getDefault()));
    }
    if (plot.getLabelGap() != null) {
        spiderWebPlot.setAxisLabelGap(plot.getLabelGap());
    }
    if (spiderchartBean.getMaxValue() != null) {
        spiderWebPlot.setMaxValue(spiderchartBean.getMaxValue());
    }
    if (plot.getRotation() != null) {
        spiderWebPlot.setDirection(plot.getRotation().getRotation());
    }
    if (plot.getStartAngle() != null) {
        spiderWebPlot.setStartAngle(plot.getStartAngle());
    }
    if (plot.getTableOrder() != null) {
        spiderWebPlot.setDataExtractOrder(plot.getTableOrder().getOrder());
    }
    if (plot.getWebFilled() != null) {
        spiderWebPlot.setWebFilled(plot.getWebFilled());
    }

    spiderWebPlot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    spiderWebPlot.setLabelGenerator(labelGenerator);

    Font titleFont = chartSettings.getTitleFont() != null ? FontUtil.getInstance(jasperReportsContext)
            .getAwtFont(chartSettings.getTitleFont(), Locale.getDefault()) : TextTitle.DEFAULT_FONT;

    String titleText = spiderchartBean.getTitleText();

    JFreeChart jfreechart = new JFreeChart(titleText, titleFont, spiderWebPlot, true);

    Color backcolor = chartSettings.getBackcolor() != null ? chartSettings.getBackcolor()
            : element.getBackcolor();
    if (backcolor != null) {
        jfreechart.setBackgroundPaint(backcolor);
    }

    RectangleEdge titleEdge = getEdge(chartSettings.getTitlePosition(), RectangleEdge.TOP);

    if (titleText != null) {
        TextTitle title = jfreechart.getTitle();
        title.setText(titleText);
        if (chartSettings.getTitleColor() != null) {
            title.setPaint(chartSettings.getTitleColor());
        }

        title.setFont(titleFont);
        title.setPosition(titleEdge);
        jfreechart.setTitle(title);
    }

    String subtitleText = spiderchartBean.getSubtitleText();
    if (subtitleText != null) {
        TextTitle subtitle = new TextTitle(subtitleText);
        subtitle.setText(subtitleText);
        if (chartSettings.getSubtitleColor() != null) {
            subtitle.setPaint(chartSettings.getSubtitleColor());
        }

        if (chartSettings.getSubtitleColor() != null) {
            Font subtitleFont = chartSettings.getSubtitleFont() != null
                    ? FontUtil.getInstance(jasperReportsContext).getAwtFont(chartSettings.getSubtitleFont(),
                            Locale.getDefault())
                    : TextTitle.DEFAULT_FONT;
            subtitle.setFont(subtitleFont);
        }

        subtitle.setPosition(titleEdge);

        jfreechart.addSubtitle(subtitle);
    }

    // Apply all of the legend formatting options
    LegendTitle legend = jfreechart.getLegend();

    if (legend != null) {
        legend.setVisible((chartSettings.getShowLegend() == null || chartSettings.getShowLegend()));
        if (legend.isVisible()) {
            if (chartSettings.getLegendColor() != null) {
                legend.setItemPaint(chartSettings.getLegendColor());
            }
            if (chartSettings.getLegendBackgroundColor() != null) {
                legend.setBackgroundPaint(chartSettings.getLegendBackgroundColor());
            }

            if (chartSettings.getLegendFont() != null) {
                legend.setItemFont(FontUtil.getInstance(jasperReportsContext)
                        .getAwtFont(chartSettings.getLegendFont(), Locale.getDefault()));
            }
            legend.setPosition(getEdge(chartSettings.getLegendPosition(), RectangleEdge.BOTTOM));
        }
    }

    String renderType = chartSettings.getRenderType() == null ? defaultRenderType
            : chartSettings.getRenderType();
    Rectangle2D rectangle = new Rectangle2D.Double(0, 0, element.getWidth(), element.getHeight());

    if (chartCustomizer != null) {
        chartCustomizer.customize(jfreechart, chartComponent);
    }

    return ChartUtil.getInstance(jasperReportsContext).getChartRenderableFactory(renderType)
            .getRenderable(jasperReportsContext, jfreechart, spiderchartBean.getHyperlinkProvider(), rectangle);
}

From source file:mrmc.chart.BarGraph.java

/**
 * Sole constructor. Creates a bar-graph style chart
 * // ww w  .  ja  va  2s .  c o  m
 * @param title Title of chart
 * @param xaxis Label for x-axis
 * @param yaxis Label for y-axis
 * @param treeMap Mapping of x-y data
 */
public BarGraph(final String title, String xaxis, String yaxis, TreeMap<String, Double> treeMap) {
    super(title);
    CategoryDataset dataset = createDataset(treeMap, xaxis);
    JFreeChart chart = createChart(dataset, title, xaxis, yaxis);
    LegendTitle legend = chart.getLegend();
    legend.setVisible(false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}

From source file:gov.sandia.umf.platform.ui.jobs.Plot.java

public JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from w  w  w .  j  ava 2s. c o  m*/

    chart.setBackgroundPaint(Color.white);

    LegendTitle legend = chart.getLegend();
    legend.setVisible(dataset.getSeriesCount() <= 5);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    ValueAxis axis = plot.getRangeAxis();
    if (axis instanceof NumberAxis)
        ((NumberAxis) axis).setAutoRangeIncludesZero(false);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < dataset.getSeriesCount(); i++)
        renderer.setSeriesShapesVisible(i, false);
    plot.setRenderer(renderer);

    return chart;
}

From source file:de.iteratec.iteraplan.presentation.dialog.GraphicalReporting.Line.JFreeChartLineGraphicCreator.java

/**
 * Creates the chart and applies some styling.
 * @return the JFreeChart wrapped in an iteratec API symbol.
 *//* ww  w  .  j  a v  a 2s. com*/
private JFreeChartSymbol createChart() {
    try {
        ChartFactory cf = new ChartFactory();
        cf.setTitle(title);
        cf.setxAxis(xAxis);
        cf.setyAxis(yAxis);
        JFreeChart chart = cf.createXYStepChart(dataset);
        LegendTitle legend = chart.getLegend();
        legend.setPosition(RectangleEdge.RIGHT);
        legend.setVisible(!emptyDataset); // don't show a legend, if the dataset is empty
        XYPlot xyplot = (XYPlot) chart.getPlot();
        xyplot.setBackgroundAlpha(0.4f);
        JFreeChartSymbol jfcs = new JFreeChartSymbol(chart);
        jfcs.setWidth(xResolution);
        jfcs.setHeight(yResolution);
        return jfcs;
    } catch (Exception e) {
        throw new IteraplanBusinessException(e);
    }
}

From source file:wsattacker.plugin.dos.dosExtension.chart.ChartObject.java

public JFreeChart createOverlaidChart() {

    // ----------------------------
    // Data and X-Y-Axis - Response Time Testprobes
    // - Y-Achse 0
    final DateAxis yAxis = new DateAxis("Time");
    yAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    // - X-Achse 0
    final NumberAxis xAxis0 = new NumberAxis("Response Time in ms");
    xAxis0.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    // xAxis0.setTickUnit( new NumberTickUnit(1) );
    // - dataset//  ww w.ja v  a  2s  .  c om
    // - renderer
    final XYDataset dataResponseTimeProbes = createDatasetResponseTime("testprobe");
    final XYLineAndShapeRenderer rendererResponseTimeProbes = new XYLineAndShapeRenderer(); // StandardXYItemRenderer();
                                                                                            // ->
                                                                                            // should
                                                                                            // not
                                                                                            // be
                                                                                            // used
    rendererResponseTimeProbes.setSeriesPaint(0, Color.blue);
    rendererResponseTimeProbes.setSeriesShape(0, new Ellipse2D.Double(-1.5, -1.5, 3.0, 3.0));
    rendererResponseTimeProbes.setSeriesLinesVisible(0, true);
    rendererResponseTimeProbes.setSeriesShapesVisible(0, true);
    rendererResponseTimeProbes.setUseOutlinePaint(false);
    rendererResponseTimeProbes.setSeriesOutlinePaint(0, Color.black);
    rendererResponseTimeProbes.setUseFillPaint(true);
    rendererResponseTimeProbes.setSeriesFillPaint(0, Color.blue);

    // ----------------------------
    // NEW XYPlot (new "Data and X-Y-Axis" from above added as default)
    final XYPlot plot = new XYPlot(dataResponseTimeProbes, yAxis, xAxis0, rendererResponseTimeProbes);

    // ----------------------------
    // Data and Axis 1 - Response time UNtampered
    // - Dataset
    // - Renderer.
    // - Dataset zu X-Axis 0 mappen
    final XYDataset dataResponseTimeUntampered = createDatasetResponseTime("untampered");
    final XYLineAndShapeRenderer rendererResponseTimeUntampered = new XYLineAndShapeRenderer(); // StandardXYItemRenderer();
                                                                                                // ->
                                                                                                // should
                                                                                                // not
                                                                                                // be
                                                                                                // used
    rendererResponseTimeUntampered.setSeriesPaint(0, new Color(0, 161, 4));
    rendererResponseTimeUntampered.setSeriesShape(0, new Ellipse2D.Double(-4, -4, 8.0, 8.0));
    rendererResponseTimeUntampered.setUseFillPaint(true);
    rendererResponseTimeUntampered.setSeriesFillPaint(0, Color.white);
    rendererResponseTimeUntampered.setUseOutlinePaint(false);
    rendererResponseTimeUntampered.setSeriesOutlinePaint(0, Color.black);
    rendererResponseTimeUntampered.setSeriesToolTipGenerator(0,
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    plot.setDataset(2, dataResponseTimeUntampered);
    plot.setRenderer(2, rendererResponseTimeUntampered);
    // plot.mapDatasetToRangeAxis(0, 1);

    // ----------------------------
    // Data and Axis - Response time tampered
    // - Dataset
    // - Renderer
    // - Dataset zu X-Axis 2 mappen
    final XYDataset dataResponseTimeTampered = createDatasetResponseTime("tampered");
    XYLineAndShapeRenderer rendererResponseTimeTampered = new XYLineAndShapeRenderer(); // XYSplineRenderer();
    rendererResponseTimeTampered.setSeriesPaint(0, new Color(189, 0, 0));
    rendererResponseTimeTampered.setSeriesShape(0, new Ellipse2D.Double(-4, -4, 8.0, 8.0));// (-2.5, -2.5, 6.0,
                                                                                           // 6.0) );
    rendererResponseTimeTampered.setUseFillPaint(true);
    rendererResponseTimeTampered.setSeriesFillPaint(0, Color.white);
    rendererResponseTimeTampered.setUseOutlinePaint(false);
    rendererResponseTimeTampered.setSeriesOutlinePaint(0, Color.black);
    plot.setDataset(3, dataResponseTimeTampered);
    plot.setRenderer(3, rendererResponseTimeTampered);
    // plot.mapDatasetToRangeAxis(0, 2);

    // ----------------------------
    // Data and X-Axis - Number Requests UNtampered
    // - X-Axis Number Requests
    final NumberAxis xAxis1 = new NumberAxis(
            "Number Requests Per Interval (" + (model.getIntervalLengthReport() / 1000) + " sec)");
    xAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // xAxis1.setTickUnit( new NumberTickUnit(2) );
    plot.setRangeAxis(1, xAxis1);
    // - Dataset
    // - Renderer
    final IntervalXYDataset dataNumberRequestsUntampered = createDatasetNumberRequestsUntampered();
    final XYBarRenderer rendererNumberRequestsUntampered = new XYBarRenderer(0.2);
    rendererNumberRequestsUntampered.setShadowVisible(false);
    rendererNumberRequestsUntampered.setBarPainter(new StandardXYBarPainter());
    rendererNumberRequestsUntampered.setSeriesPaint(0, new Color(128, 255, 128));
    plot.setDataset(4, dataNumberRequestsUntampered);
    plot.setRenderer(4, rendererNumberRequestsUntampered);
    plot.mapDatasetToRangeAxis(4, 1);

    // -------------------------------
    // Data - Number Requests tampered
    // - Dataset
    // - Renderer
    final IntervalXYDataset dataNumberRequestsTampered = createDatasetNumberRequestsTampered();
    final XYBarRenderer rendererBarNumberRequestsTampered = new XYBarRenderer(0.2);
    rendererBarNumberRequestsTampered.setShadowVisible(false);
    rendererBarNumberRequestsTampered.setBarPainter(new StandardXYBarPainter());
    rendererBarNumberRequestsTampered.setSeriesPaint(0, new Color(255, 148, 148));
    plot.setDataset(5, dataNumberRequestsTampered);
    plot.setRenderer(5, rendererBarNumberRequestsTampered);
    plot.mapDatasetToRangeAxis(5, 1);

    // -------------------------
    // Other formating stuff
    // - add annotations
    // final double x = new Day(9, SerialDate.MARCH,
    // 2002).getMiddleMillisecond();
    // final XYTextAnnotation annotation = new
    // XYTextAnnotation("Anmerkung zu Datenpunkt", x, 1000.0);
    // annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    // plot.addAnnotation(annotation);

    // -------------------------
    // Create custom LegendTitles
    // Legend Row 1
    LegendTitle legendL1 = new LegendTitle(plot.getRenderer(0));
    legendL1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendL1.setBorder(0, 0, 0, 0);
    LegendTitle legendR1 = new LegendTitle(plot.getRenderer(4));
    legendR1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendR1.setBorder(0, 0, 0, 0);
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.setBorder(0, 0, 0, 0);
    blockcontainer.add(legendL1, RectangleEdge.LEFT);
    blockcontainer.add(legendR1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle1 = new CompositeTitle(blockcontainer);
    compositetitle1.setPosition(RectangleEdge.BOTTOM);
    // Legend Row 2
    LegendTitle legendL2 = new LegendTitle(plot.getRenderer(2));
    legendL2.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendL2.setBorder(0, 0, 0, 0);
    LegendTitle legendR2 = new LegendTitle(plot.getRenderer(5));
    legendR2.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendR2.setBorder(0, 0, 0, 0);
    BlockContainer blockcontainer2 = new BlockContainer(new BorderArrangement());
    blockcontainer2.setBorder(0, 0, 0, 0);
    blockcontainer2.add(legendL2, RectangleEdge.LEFT);
    blockcontainer2.add(legendR2, RectangleEdge.RIGHT);
    blockcontainer2.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle2 = new CompositeTitle(blockcontainer2);
    compositetitle2.setPosition(RectangleEdge.BOTTOM);
    // Legend Row 3
    LegendTitle legendL3 = new LegendTitle(plot.getRenderer(3));
    legendL3.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendL3.setBorder(0, 0, 0, 0);
    BlockContainer blockcontainer3 = new BlockContainer(new BorderArrangement());
    blockcontainer3.setBorder(0, 0, 0, 0);
    blockcontainer3.add(legendL3, RectangleEdge.LEFT);
    blockcontainer3.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle3 = new CompositeTitle(blockcontainer3);
    compositetitle3.setPosition(RectangleEdge.BOTTOM);

    // -------------------------
    // create Chart
    // - return a new chart containing the overlaid plot...
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart jFreeChart = new JFreeChart(model.getAttackName() + " - Response Time Plot", // Roundtrip Time Plot
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    // Add new legend boxes + format
    jFreeChart.addSubtitle(compositetitle1);
    jFreeChart.addSubtitle(compositetitle2);
    jFreeChart.addSubtitle(compositetitle3);

    // Surpress old Legends
    LegendTitle legendee2 = jFreeChart.getLegend(0);
    legendee2.setVisible(false);

    return jFreeChart;
}

From source file:net.sf.mzmine.modules.visualization.tic.TICPlot.java

@Override
public void actionPerformed(final ActionEvent event) {

    super.actionPerformed(event);

    final String command = event.getActionCommand();

    if ("SHOW_DATA_POINTS".equals(command)) {

        switchDataPointsVisible();/*from  ww  w  .  j av a 2s  .  co m*/
    }

    if ("SHOW_ANNOTATIONS".equals(command)) {

        switchItemLabelsVisible();
    }

    if ("SETUP_AXES".equals(command)) {

        new AxesSetupDialog(getXYPlot()).setVisible(true);
    }

    if ("ZOOM_IN".equals(command)) {

        getXYPlot().getDomainAxis().resizeRange(1.0 / ZOOM_FACTOR);
    }

    if ("ZOOM_OUT".equals(command)) {

        getXYPlot().getDomainAxis().resizeRange(ZOOM_FACTOR);
    }

    if ("SET_SAME_RANGE".equals(command)) {

        // Get current axes range.
        final NumberAxis xAxis = (NumberAxis) getXYPlot().getDomainAxis();
        final NumberAxis yAxis = (NumberAxis) getXYPlot().getRangeAxis();
        final double xMin = xAxis.getRange().getLowerBound();
        final double xMax = xAxis.getRange().getUpperBound();
        final double xTick = xAxis.getTickUnit().getSize();
        final double yMin = yAxis.getRange().getLowerBound();
        final double yMax = yAxis.getRange().getUpperBound();
        final double yTick = yAxis.getTickUnit().getSize();

        // Set the range of these frames
        for (final Window frame : JFrame.getWindows()) {
            if (frame instanceof TICVisualizerWindow) {

                final TICVisualizerWindow ticFrame = (TICVisualizerWindow) frame;
                ticFrame.setAxesRange(xMin, xMax, xTick, yMin, yMax, yTick);
            }
        }
    }

    if ("SHOW_SPECTRUM".equals(command)) {

        visualizer.actionPerformed(event);
    }

    if ("SHOW_LEGEND".equals(command)) {

        // Toggle legend visibility.
        final LegendTitle legend = getChart().getLegend();
        legend.setVisible(!legend.isVisible());
    }
}

From source file:org.gumtree.vis.core.internal.SWTChartComposite.java

private void setLegend(String legendPosition) {
    LegendTitle legend = getChart().getLegend();
    if (legend != null) {
        if (legendPosition.equals(LEGEND_BOTTOM_COMMAND)) {
            legend.setVisible(true);
            legend.setPosition(RectangleEdge.BOTTOM);
        } else if (legendPosition.equals(LEGEND_RIGHT_COMMAND)) {
            legend.setVisible(true);//from www  . j a  va2s . c o  m
            legend.setPosition(RectangleEdge.RIGHT);
        } else
            legend.setVisible(false);
    }
}

From source file:net.sf.jasperreports.components.spiderchart.FillSpiderChart.java

protected JFreeChart evaluateChart(byte evaluation) throws JRException {
    maxValue = (Double) fillContext.evaluate(getPlot().getMaxValueExpression(), evaluation);
    titleText = (String) fillContext.evaluate(getChartSettings().getTitleExpression(), evaluation);
    subtitleText = (String) fillContext.evaluate(getChartSettings().getSubtitleExpression(), evaluation);
    anchorName = (String) fillContext.evaluate(getChartSettings().getAnchorNameExpression(), evaluation);
    hyperlinkReference = (String) fillContext.evaluate(getChartSettings().getHyperlinkReferenceExpression(),
            evaluation);//from   w w w.j av a  2s. c  o m
    hyperlinkAnchor = (String) fillContext.evaluate(getChartSettings().getHyperlinkAnchorExpression(),
            evaluation);
    hyperlinkPage = (Integer) fillContext.evaluate(getChartSettings().getHyperlinkPageExpression(), evaluation);
    hyperlinkTooltip = (String) fillContext.evaluate(getChartSettings().getHyperlinkTooltipExpression(),
            evaluation);
    hyperlinkParameters = JRFillHyperlinkHelper.evaluateHyperlinkParameters(getChartSettings(),
            expressionEvaluator, evaluation);

    dataset.evaluateDatasetRun(evaluation);
    dataset.finishDataset();

    chartHyperlinkProvider = new CategoryChartHyperlinkProvider(dataset.getItemHyperlinks());

    bookmarkLevel = getChartSettings().getBookmarkLevel();

    SpiderWebPlot spiderWebPlot = new SpiderWebPlot((DefaultCategoryDataset) dataset.getCustomDataset());

    if (getPlot().getAxisLineColor() != null) {
        spiderWebPlot.setAxisLinePaint(getPlot().getAxisLineColor());
    }
    if (getPlot().getAxisLineWidth() != null) {
        spiderWebPlot.setAxisLineStroke(new BasicStroke(getPlot().getAxisLineWidth()));
    }
    if (getPlot().getBackcolor() != null) {
        spiderWebPlot.setBackgroundPaint(getPlot().getBackcolor());
    }
    if (getPlot().getBackgroundAlpha() != null) {
        spiderWebPlot.setBackgroundAlpha(getPlot().getBackgroundAlpha());
    }
    if (getPlot().getForegroundAlpha() != null) {
        spiderWebPlot.setForegroundAlpha(getPlot().getForegroundAlpha());
    }
    if (getPlot().getHeadPercent() != null) {
        spiderWebPlot.setHeadPercent(getPlot().getHeadPercent());
    }
    if (getPlot().getInteriorGap() != null) {
        spiderWebPlot.setInteriorGap(getPlot().getInteriorGap());
    }
    if (getPlot().getLabelColor() != null) {
        spiderWebPlot.setLabelPaint(getPlot().getLabelColor());
    }
    if (getPlot().getLabelFont() != null) {
        spiderWebPlot.setLabelFont(JRFontUtil.getAwtFont(getPlot().getLabelFont(), Locale.getDefault()));
    }
    if (getPlot().getLabelGap() != null) {
        spiderWebPlot.setAxisLabelGap(getPlot().getLabelGap());
    }
    if (maxValue != null) {
        spiderWebPlot.setMaxValue(maxValue);
    }
    if (getPlot().getRotation() != null) {
        spiderWebPlot.setDirection(getPlot().getRotation().getRotation());
    }
    if (getPlot().getStartAngle() != null) {
        spiderWebPlot.setStartAngle(getPlot().getStartAngle());
    }
    if (getPlot().getTableOrder() != null) {
        spiderWebPlot.setDataExtractOrder(getPlot().getTableOrder().getOrder());
    }
    if (getPlot().getWebFilled() != null) {
        spiderWebPlot.setWebFilled(getPlot().getWebFilled());
    }

    spiderWebPlot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    spiderWebPlot.setLabelGenerator(new StandardCategoryItemLabelGenerator());

    Font titleFont = getChartSettings().getTitleFont() != null
            ? JRFontUtil.getAwtFont(getChartSettings().getTitleFont(), Locale.getDefault())
            : TextTitle.DEFAULT_FONT;

    JFreeChart jfreechart = new JFreeChart(titleText, titleFont, spiderWebPlot, true);

    if (chartSettings.getBackcolor() != null) {
        jfreechart.setBackgroundPaint(chartSettings.getBackcolor());
    }

    RectangleEdge titleEdge = getEdge(getChartSettings().getTitlePosition(), RectangleEdge.TOP);

    if (titleText != null) {
        TextTitle title = jfreechart.getTitle();
        title.setText(titleText);
        if (getChartSettings().getTitleColor() != null) {
            title.setPaint(getChartSettings().getTitleColor());
        }

        title.setFont(titleFont);
        title.setPosition(titleEdge);
        jfreechart.setTitle(title);
    }

    if (subtitleText != null) {
        TextTitle subtitle = new TextTitle(subtitleText);
        subtitle.setText(subtitleText);
        if (getChartSettings().getSubtitleColor() != null) {
            subtitle.setPaint(getChartSettings().getSubtitleColor());
        }

        if (getChartSettings().getSubtitleColor() != null) {
            Font subtitleFont = getChartSettings().getSubtitleFont() != null
                    ? JRFontUtil.getAwtFont(getChartSettings().getSubtitleFont(), Locale.getDefault())
                    : TextTitle.DEFAULT_FONT;
            subtitle.setFont(subtitleFont);
        }

        subtitle.setPosition(titleEdge);

        jfreechart.addSubtitle(subtitle);
    }

    // Apply all of the legend formatting options
    LegendTitle legend = jfreechart.getLegend();

    if (legend != null) {
        legend.setVisible((chartSettings.getShowLegend() == null || chartSettings.getShowLegend()));
        if (legend.isVisible()) {
            if (getChartSettings().getLegendColor() != null) {
                legend.setItemPaint(getChartSettings().getLegendColor());
            }
            if (getChartSettings().getLegendBackgroundColor() != null) {
                legend.setBackgroundPaint(getChartSettings().getLegendBackgroundColor());
            }

            if (getChartSettings().getLegendFont() != null) {
                legend.setItemFont(
                        JRFontUtil.getAwtFont(getChartSettings().getLegendFont(), Locale.getDefault()));
            }
            legend.setPosition(getEdge(getChartSettings().getLegendPosition(), RectangleEdge.BOTTOM));
        }
    }
    return jfreechart;

}

From source file:org.logisticPlanning.utils.graphics.chart.impl.jfree._JFCLineChart2D.java

/** init the legend */
private final void __initLegend() {
    final LegendTitle t;

    if (this.getLegendType() != ELegendType.NO_LEGEND) {
        t = new LegendTitle(this.m_plot);
        t.setItemFont(this.getDriver().getPalette().getLegendFont());
        t.setBackgroundPaint(this.getDriver().getPalette().getBackgroundColor());
        t.setVisible(true);
        this.m_chart.addLegend(t);
    }/*ww w .  j a v  a 2  s  . c  o  m*/
}