Example usage for org.jfree.chart ChartPanel getChartRenderingInfo

List of usage examples for org.jfree.chart ChartPanel getChartRenderingInfo

Introduction

In this page you can find the example usage for org.jfree.chart ChartPanel getChartRenderingInfo.

Prototype

public ChartRenderingInfo getChartRenderingInfo() 

Source Link

Document

Returns the chart rendering info from the most recent chart redraw.

Usage

From source file:net.sf.maltcms.chromaui.charts.events.XYAnnotationAdder.java

/**
 *
 * @param g/*from  ww  w.j a va2s.c  o  m*/
 * @param xyp
 * @param dataArea
 * @param domainAxis
 * @param rangeAxis
 * @param domainEdge
 * @param rangeEdge
 * @param cp
 */
protected void paint(Graphics g, XYPlot xyp, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis,
        RectangleEdge domainEdge, RectangleEdge rangeEdge, ChartPanel cp) {
    //System.out.println("Painting " + this.xyaa.getPeakAnnotations().size() + " annotations");
    for (XYSelectableShapeAnnotation<Peak2D> xypa : getPeakAnnotations()) {
        //Peak2D peak = xypa.getPeak();
        //Point seed = peak.getPeakArea().getSeedPoint();
        //if(roi.contains(seed)) {
        //                    if (xypa.isActive()) {
        //                        g.setColor(new Color(0xFF0000CC));
        //                    } else {
        //                        g.setColor(new Color(0xCCCCCCCC));
        //                    }
        //                    Graphics2D g2 = (Graphics2D) g;
        //                    double xlow = domainAxis.valueToJava2D(seed.x, dataArea, domainEdge);
        //                    double ylow = rangeAxis.valueToJava2D(seed.y, dataArea,
        //                                rangeEdge);
        //                    Rectangle2D.Double r2d = new Rectangle2D.Double(xlow - 5, ylow - 5, 10, 10);
        //                    g2.draw(r2d);
        //                    Line2D.Double ud = new Line2D.Double(xlow,ylow-5,xlow,ylow+5);
        //                    Line2D.Double lr = new Line2D.Double(xlow-5,ylow,xlow+5,ylow);
        //                    g2.draw(ud);
        //                    g2.draw(lr);
        xypa.draw((Graphics2D) g, xyp, dataArea, domainAxis, rangeAxis, 0,
                cp.getChartRenderingInfo().getPlotInfo());
        //}
    }
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

private Point2D.Double getPoint(int dataIndex, Type type) {
    if (dataIndex < 0) {
        return null;
    }//from   w  w  w  .j av  a2  s. c o m

    final ChartPanel chartPanel = this.investmentFlowChartJDialog.getChartPanel();
    final JFreeChart chart = chartPanel.getChart();
    final XYPlot plot = (XYPlot) chart.getPlot();
    // Dataset 0 are the invest information. 1 is the ROI information.
    final TimeSeriesCollection timeSeriesCollection;
    if (type == Type.Invest) {
        timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(0);
    } else {
        assert (type == Type.ROI);
        timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(1);
    }
    final TimeSeries timeSeries = timeSeriesCollection.getSeries(0);

    if (dataIndex >= timeSeries.getItemCount()) {
        /* Not ready yet. */
        return null;
    }

    final ValueAxis domainAxis = plot.getDomainAxis();
    final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
    final ValueAxis rangeAxis = plot.getRangeAxis();
    final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();

    final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(dataIndex);
    final double xValue = timeSeriesDataItem.getPeriod().getFirstMillisecond();
    final double yValue = timeSeriesDataItem.getValue().doubleValue();
    final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
    final double xJava2D = domainAxis.valueToJava2D(xValue, plotArea, domainAxisEdge);
    final double yJava2D = rangeAxis.valueToJava2D(yValue, plotArea, rangeAxisEdge);
    // Use Double version, to avoid from losing precision.
    return new Point2D.Double(xJava2D, yJava2D);
}

From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java

private void updateIndicatorTraceInfos(int mainPointIndex) {
    this.indicatorTraceInfos.clear();
    if (this.mainTraceInfo == null) {
        return;/*from   w w  w.j a v  a2  s. co m*/
    }

    final ChartPanel chartPanel = this.chartJDialog.getChartPanel();

    Day day = null;

    final XYDataset xyDataset = this.chartJDialog.getPlot().getDataset();
    if (xyDataset instanceof TimeSeriesCollection) {
        // Get the date.
        day = (Day) ((TimeSeriesCollection) xyDataset).getSeries(0).getDataItem(mainPointIndex).getPeriod();

        // 0 means main plot.
        final XYPlot plot = this.chartJDialog.getPlot();
        final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset();
        // Start with 1. We are not interested in main series.
        for (int j = 1, size = timeSeriesCollection.getSeriesCount(); j < size; j++) {
            final TimeSeries timeSeries = timeSeriesCollection.getSeries(j);
            /* Time consuming. */
            final int dataIndex = getDataIndex(timeSeries, day);

            if (dataIndex < 0) {
                continue;
            }

            final Point2D point = this.getPoint(0, j, dataIndex);
            final String name = this.getLegendName(0, j);
            final Number value = this.getValue(0, j, dataIndex);

            if (point == null || name == null || value == null) {
                continue;
            }

            // We will never draw ball for SMA, EMA...
            this.indicatorTraceInfos.add(TraceInfo.newInstance(null, 0, j, dataIndex));
        }
    } else {
        final Date date = ((org.jfree.data.xy.DefaultHighLowDataset) xyDataset).getXDate(0, mainPointIndex);
        // OK to do so? Is "day" only used to compare day, excluding time information?
        // Will day 13th September 2009, 1:00pm same as another day 13th September 2009, 3:00pm?
        day = new Day(date);

        // 0 means main plot.
        final XYPlot plot = this.chartJDialog.getPlot();
        final int count = plot.getDatasetCount();
        for (int i = 1; i < count; i++) {
            final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(i);

            /* Not ready. */
            if (timeSeriesCollection == null) {
                continue;
            }

            final TimeSeries timeSeries = timeSeriesCollection.getSeries(0);
            /* Time consuming. */
            final int dataIndex = getDataIndex(timeSeries, day);

            if (dataIndex < 0) {
                continue;
            }

            final Point2D point = this.getPoint(0, i, dataIndex);
            final String name = this.getLegendName(0, i);
            final Number value = this.getValue(0, i, dataIndex);

            if (point == null || name == null || value == null) {
                continue;
            }

            // We will never draw ball for SMA, EMA...
            this.indicatorTraceInfos.add(TraceInfo.newInstance(null, 0, i, dataIndex));
        }
    }

    // Begin with 1. 0 is main plot.
    for (int i = 1, size = this.chartJDialog.getPlotSize(); i < size; i++) {
        final XYPlot plot = this.chartJDialog.getPlot(i);
        final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset();
        // So far, for subplot, each of them only have 1 series.
        assert (1 == timeSeriesCollection.getSeriesCount());
        for (int j = 0, size2 = timeSeriesCollection.getSeriesCount(); j < size2; j++) {
            final TimeSeries timeSeries = timeSeriesCollection.getSeries(j);
            /* Time consuming. */
            final int dataIndex = getDataIndex(timeSeries, day);

            if (dataIndex < 0) {
                continue;
            }

            final Point2D point = this.getPoint(i, j, dataIndex);
            final String name = this.getLegendName(i, j);
            final Number value = this.getValue(i, j, dataIndex);

            if (point == null || name == null || value == null) {
                continue;
            }

            final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(i)
                    .getDataArea();
            if (plotArea.contains(point)) {
                this.indicatorTraceInfos.add(TraceInfo.newInstance(point, i, j, dataIndex));
            } else {
                this.indicatorTraceInfos.add(TraceInfo.newInstance(null, i, j, dataIndex));
            }
        }
    }
}