Example usage for org.jfree.chart.title CompositeTitle setPosition

List of usage examples for org.jfree.chart.title CompositeTitle setPosition

Introduction

In this page you can find the example usage for org.jfree.chart.title CompositeTitle setPosition.

Prototype

public void setPosition(RectangleEdge position) 

Source Link

Document

Sets the position for the title and sends a TitleChangeEvent to all registered listeners.

Usage

From source file:org.jfree.chart.demo.AnnotationDemo2.java

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset1();
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Annotation Demo 2", "Date", "Price Per Unit",
            xydataset, PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    NumberAxis numberaxis1 = new NumberAxis("Secondary");
    numberaxis1.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.setDataset(1, createDataset2());
    xyplot.mapDatasetToRangeAxis(1, 1);/* w  w w  .  j av  a 2 s .  c  o  m*/
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setBaseShapesFilled(true);
    XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("Annotation 1 (2.0, 167.3)", 2D,
            167.30000000000001D, -0.78539816339744828D);
    xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    xypointerannotation.setPaint(Color.red);
    xypointerannotation.setArrowPaint(Color.red);
    xylineandshaperenderer.addAnnotation(xypointerannotation);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(true, true);
    xylineandshaperenderer1.setSeriesPaint(0, Color.black);
    xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation("Annotation 2 (15.0, 613.2)", 15D,
            613.20000000000005D, 1.5707963267948966D);
    xypointerannotation1.setTextAnchor(TextAnchor.TOP_CENTER);
    xylineandshaperenderer1.addAnnotation(xypointerannotation1);
    xyplot.setRenderer(1, xylineandshaperenderer1);
    LegendTitle legendtitle = new LegendTitle(xylineandshaperenderer);
    LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1);
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}

From source file:org.jfree.chart.demo.DualAxisDemo1.java

private static JFreeChart createChart() {
    JFreeChart jfreechart = ChartFactory.createBarChart("Dual Axis Chart", "Category", "Value",
            createDataset1(), PlotOrientation.VERTICAL, false, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(new Color(238, 238, 255));
    categoryplot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    CategoryDataset categorydataset = createDataset2();
    categoryplot.setDataset(1, categorydataset);
    categoryplot.mapDatasetToRangeAxis(1, 1);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    NumberAxis numberaxis = new NumberAxis("Secondary");
    categoryplot.setRangeAxis(1, numberaxis);
    LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer();
    lineandshaperenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    categoryplot.setRenderer(1, lineandshaperenderer);
    categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    LegendTitle legendtitle = new LegendTitle(categoryplot.getRenderer(0));
    legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendtitle.setFrame(new BlockBorder());
    LegendTitle legendtitle1 = new LegendTitle(categoryplot.getRenderer(1));
    legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendtitle1.setFrame(new BlockBorder());
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.MarkerTimeChartDecorator.java

/**
 * Creates a legend item block.//from www .  ja v  a  2s.c om
 * 
 * @param item
 *            the legend item.
 * 
 * @return The block.
 */
protected void createLegendBlock(BlockContainer blockcontainerLabel) {

    XYPlot xyplot = (XYPlot) report.getPlot();

    int nbRenderer = xyplot.getDatasetCount();
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    if (nbRenderer > 1) {
        BlockContainer oldLegendBlockContainer = new BlockContainer(
                new FlowArrangement(HorizontalAlignment.LEFT, VerticalAlignment.TOP, 2.0D, 2.0D));
        for (int i = 0; i < nbRenderer; i++) {
            LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(i));
            legendtitle.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
            legendtitle.setFrame(new LineBorder());
            legendtitle.setBackgroundPaint(ChartColor.WHITE);
            oldLegendBlockContainer.add(legendtitle);
        }

        blockcontainer.add(oldLegendBlockContainer, RectangleEdge.LEFT);
    } else {
        LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(0));
        legendtitle.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legendtitle.setFrame(new LineBorder());
        legendtitle.setBackgroundPaint(ChartColor.WHITE);
        blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    }

    LegendTitle legendtitle1 = new LegendTitle(xyplot.getRenderer());
    legendtitle1.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    legendtitle1.setFrame(new LineBorder());
    legendtitle1.setBackgroundPaint(ChartColor.WHITE);
    legendtitle1.setWrapper(blockcontainerLabel);

    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(1000D, 0.0D));

    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    report.clearSubtitles();
    report.addSubtitle(compositetitle);
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.SurefirePercentAxisDecorator.java

/**
 *
 *///w  w  w .  j  a va 2 s  .  c o  m
public void createChart() {

    XYPlot xyplot = (XYPlot) report.getPlot();
    if (this.decoratedChart instanceof TimeChartRenderer && this.results != null && !this.results.isEmpty()) {

        Iterator iter = this.results.iterator();
        TimeSeriesCollection defaultdataset = new TimeSeriesCollection();
        TimeSeries s1 = new TimeSeries("% success", Day.class);

        while (iter.hasNext()) {
            SurefireReportBean surefire = (SurefireReportBean) iter.next();
            Date date = surefire.getDateGeneration();
            s1.addOrUpdate(new Day(TimePeriod.DAY.normalize(date)), surefire.getSucessRate() / PCENT);

        }

        defaultdataset.addSeries(s1);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setSeriesPaint(0, ChartColor.DARK_BLUE);
        renderer.setBaseShapesVisible(true);
        renderer.setDrawOutlines(true);
        StandardXYItemLabelGenerator labelgenerator = new StandardXYItemLabelGenerator(
                StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, TimePeriod.DAY.getDateFormat(),
                NumberFormat.getPercentInstance(Locale.getDefault()));
        renderer.setBaseItemLabelGenerator(labelgenerator);
        renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, ITEM_LABEL_FONT_SIZE));
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BASELINE_RIGHT));

        renderer.setBaseStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

        LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(0));
        legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle.setFrame(new BlockBorder());
        legendtitle.setBackgroundPaint(ChartColor.WHITE);

        LegendTitle legendtitle1 = new LegendTitle(renderer);
        legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle1.setFrame(new BlockBorder());
        legendtitle1.setBackgroundPaint(ChartColor.WHITE);

        BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
        blockcontainer.add(legendtitle, RectangleEdge.LEFT);
        blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
        blockcontainer.add(new EmptyBlock(BLOCK_CONTAINER_WIDTH, 0.0D));

        CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
        compositetitle.setPosition(RectangleEdge.BOTTOM);

        report.clearSubtitles();
        report.addSubtitle(compositetitle);

        xyplot.setDataset(1, defaultdataset);

        NumberAxis valueaxis = new NumberAxis("% success");
        valueaxis.setLowerMargin(0.0D);
        valueaxis.setUpperMargin(AXIS_UPPER_MARGIN);
        valueaxis.setRangeWithMargins(0.0D, 1.0D);
        valueaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
        xyplot.setRangeAxis(1, valueaxis);
        xyplot.mapDatasetToRangeAxis(1, 1);
        xyplot.setRenderer(1, renderer);
    }

}

From source file:com.bt.aloha.sipstone.GenGraph.java

private JFreeChart createCombinedChart() {
    XYDataset xydatasetArray[] = createDataset_TotalCallCreated_CallsPerSecond();
    XYDataset xydataset = xydatasetArray[0];
    final XYDataset percXydataset = xydatasetArray[1];
    JFreeChart jfreechart = ChartFactory.createXYLineChart("SIPStone graph", "Calls", "Call rate", xydataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = new NumberAxis("Avg. Response Time");
    numberaxis.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(1, numberaxis);/*from  w ww. j a  v  a2  s.  com*/
    xyplot.setDataset(1, createDataset_TotalCallCreated_AvgResponseTime());
    xyplot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setShapesFilled(true);
    }
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xylineandshaperenderer1.setSeriesPaint(0, Color.black);
    xylineandshaperenderer1.setBaseShapesVisible(true);
    xylineandshaperenderer1.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    xyplot.setRenderer(1, xylineandshaperenderer1);
    NumberAxis timeaxis = (NumberAxis) xyplot.getDomainAxis();
    timeaxis.setAutoRange(true);
    timeaxis.setAxisLineVisible(true);
    LegendTitle legendtitle = new LegendTitle(xyitemrenderer);
    LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1);
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));

    XYItemRenderer xyrenderer = (XYItemRenderer) xyplot.getRenderer();
    xyrenderer.setBaseItemLabelGenerator(new MyXYItemLabelGenerator(percXydataset));
    xyrenderer.setBaseItemLabelsVisible(true);

    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}

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/*from  w w w  .  j  a v  a  2  s. c  o m*/
    // - 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:org.trade.ui.chart.CandlestickChart.java

/**
 * A demonstration application showing a candlestick chart.
 * /* w  w  w . j a v  a2s .c o m*/
 * @param title
 *            the frame title.
 * @param strategyData
 *            StrategyData
 */
public CandlestickChart(final String title, StrategyData strategyData, Tradingday tradingday) {

    this.strategyData = strategyData;
    this.setLayout(new BorderLayout());
    // Used to mark the current price
    stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 10, 3 }, 0);
    valueMarker = new ValueMarker(0.00, Color.black, stroke);

    this.chart = createChart(this.strategyData, title, tradingday);

    BlockContainer container = new BlockContainer(new BorderArrangement());
    container.add(titleLegend1, RectangleEdge.LEFT);
    container.add(titleLegend2, RectangleEdge.RIGHT);
    container.add(new EmptyBlock(2000, 0));
    CompositeTitle legends = new CompositeTitle(container);
    legends.setPosition(RectangleEdge.BOTTOM);
    this.chart.addSubtitle(legends);

    final ChartPanel chartPanel = new ChartPanel(this.chart);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseZoomable(true, true);
    chartPanel.setRefreshBuffer(true);
    chartPanel.setDoubleBuffered(true);
    chartPanel.setVerticalAxisTrace(true);
    chartPanel.setHorizontalAxisTrace(true);
    chartPanel.addChartMouseListener(new ChartMouseListener() {

        public void chartMouseMoved(ChartMouseEvent e) {
        }

        public void chartMouseClicked(final ChartMouseEvent e) {
            CombinedDomainXYPlot combinedXYplot = (CombinedDomainXYPlot) e.getChart().getPlot();
            @SuppressWarnings("unchecked")
            List<XYPlot> subplots = combinedXYplot.getSubplots();
            if (e.getTrigger().getClickCount() == 2) {
                double xItem = 0;
                double yItem = 0;
                if (e.getEntity() instanceof XYItemEntity) {
                    XYItemEntity xYItemEntity = ((XYItemEntity) e.getEntity());
                    xItem = xYItemEntity.getDataset().getXValue(xYItemEntity.getSeriesIndex(),
                            xYItemEntity.getItem());
                    yItem = xYItemEntity.getDataset().getYValue(xYItemEntity.getSeriesIndex(),
                            xYItemEntity.getItem());
                } else {
                    PlotEntity plotEntity = ((PlotEntity) e.getEntity());
                    XYPlot plot = (XYPlot) plotEntity.getPlot();
                    xItem = plot.getDomainCrosshairValue();
                    yItem = plot.getRangeCrosshairValue();
                }

                for (XYPlot xyplot : subplots) {

                    double x = xyplot.getDomainCrosshairValue();
                    double y = xyplot.getRangeCrosshairValue();

                    /*
                     * If the cross hair is from a right-hand y axis we need
                     * to convert this to a left-hand y axis.
                     */
                    String rightAxisName = ", Price: ";
                    double rangeLowerLeft = 0;
                    double rangeUpperLeft = 0;
                    double rangeLowerRight = 0;
                    double rangeUpperRight = 0;
                    double yRightLocation = 0;
                    for (int index = 0; index < xyplot.getRangeAxisCount(); index++) {
                        AxisLocation axisLocation = xyplot.getRangeAxisLocation(index);
                        Range range = xyplot.getRangeAxis(index).getRange();

                        if (axisLocation.equals(AxisLocation.BOTTOM_OR_LEFT)
                                || axisLocation.equals(AxisLocation.TOP_OR_LEFT)) {
                            rangeLowerLeft = range.getLowerBound();
                            rangeUpperLeft = range.getUpperBound();
                            rightAxisName = ", " + xyplot.getRangeAxis(index).getLabel() + ": ";
                        }
                        if (y >= range.getLowerBound() && y <= range.getUpperBound()
                                && (axisLocation.equals(AxisLocation.BOTTOM_OR_RIGHT)
                                        || axisLocation.equals(AxisLocation.TOP_OR_RIGHT))) {
                            rangeUpperRight = range.getUpperBound();
                            rangeLowerRight = range.getLowerBound();
                        }
                    }
                    if ((rangeUpperRight - rangeLowerRight) > 0) {
                        yRightLocation = rangeLowerLeft + ((rangeUpperLeft - rangeLowerLeft)
                                * ((y - rangeLowerRight) / (rangeUpperRight - rangeLowerRight)));
                    } else {
                        yRightLocation = y;
                    }

                    String text = " Time: " + dateFormatShort.format(new Date((long) (x))) + rightAxisName
                            + new Money(y);
                    if (x == xItem && y == yItem) {
                        titleLegend1.setText(text);
                        if (null == clickCrossHairs) {
                            clickCrossHairs = new XYTextAnnotation(text, x, yRightLocation);
                            clickCrossHairs.setTextAnchor(TextAnchor.BOTTOM_LEFT);
                            xyplot.addAnnotation(clickCrossHairs);
                        } else {
                            clickCrossHairs.setText(text);
                            clickCrossHairs.setX(x);
                            clickCrossHairs.setY(yRightLocation);
                        }
                    }
                }
            } else if (e.getTrigger().getClickCount() == 1 && null != clickCrossHairs) {
                for (XYPlot xyplot : subplots) {
                    if (xyplot.removeAnnotation(clickCrossHairs)) {
                        clickCrossHairs = null;
                        titleLegend1.setText(" Time: 0, Price :0.0");
                        break;
                    }
                }
            }
        }
    });
    this.add(chartPanel, null);
    this.strategyData.getCandleDataset().getSeries(0).addChangeListener(this);
}