Example usage for org.jfree.chart.plot XYPlot setRangeCrosshairVisible

List of usage examples for org.jfree.chart.plot XYPlot setRangeCrosshairVisible

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setRangeCrosshairVisible.

Prototype

public void setRangeCrosshairVisible(boolean flag) 

Source Link

Document

Sets the flag indicating whether or not the range crosshair is visible.

Usage

From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java

@Override
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    XYDataset dataset = (XYDataset) datasets.getDatasets().get("1");

    final JFreeChart sparkLineGraph = ChartFactory.createTimeSeriesChart(null, null, null, dataset, legend,
            false, false);/*from   w  ww. j a v a  2s.  c o  m*/
    sparkLineGraph.setBackgroundPaint(color);

    TextTitle title = setStyleTitle(name, styleTitle);
    sparkLineGraph.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        sparkLineGraph.addSubtitle(subTitle);
    }

    sparkLineGraph.setBorderVisible(false);
    sparkLineGraph.setBorderPaint(Color.BLACK);
    XYPlot plot = sparkLineGraph.getXYPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setBackgroundPaint(null);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(color);

    // calculate the last marker color
    Paint colorLast = getLastPointColor();

    // Calculate average, minimum and maximum to draw plot borders.
    boolean isFirst = true;
    double avg = 0, min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY;
    int count = 0;
    for (int i = 0; i < timeSeries.getItemCount(); i++) {
        if (timeSeries.getValue(i) != null) {
            count++;
            if (isFirst) {
                min = timeSeries.getValue(i).doubleValue();
                max = timeSeries.getValue(i).doubleValue();
                isFirst = false;
            }
            double n = timeSeries.getValue(i).doubleValue();
            //calculate avg, min, max
            avg += n;
            if (n < min)
                min = n;
            if (n > max)
                max = n;
        }
    }
    // average
    avg = avg / (double) count;

    // calculate min and max between thresholds!
    boolean isFirst2 = true;
    double lb = 0, ub = 0;
    for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) {
        Double thres = (Double) iterator.next();
        if (isFirst2 == true) {
            ub = thres.doubleValue();
            lb = thres.doubleValue();
            isFirst2 = false;
        }
        if (thres.doubleValue() > ub)
            ub = thres.doubleValue();
        if (thres.doubleValue() < lb)
            lb = thres.doubleValue();
    }

    plot.getRangeAxis().setRange(new Range(Math.min(lb, min - 2), Math.max(ub, max + 2) + 2));

    addMarker(1, avg, Color.GRAY, 0.8f, plot);
    //addAvaregeSeries(series, plot);
    addPointSeries(timeSeries, plot);

    int num = 3;
    for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) {
        Double thres = (Double) iterator.next();
        TargetThreshold targThres = thresholds.get(thres);
        Color color = Color.WHITE;
        if (targThres != null && targThres.getColor() != null) {
            color = targThres.getColor();
        }
        if (targThres.isVisible()) {
            addMarker(num++, thres.doubleValue(), color, 0.5f, plot);
        }
    }

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(false);
    domainAxis.setUpperMargin(0.2);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(false);

    plot.getRenderer().setSeriesPaint(0, Color.BLACK);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) {
        public boolean getItemShapeVisible(int _series, int item) {
            TimeSeriesDataItem tsdi = timeSeries.getDataItem(item);
            if (tsdi == null)
                return false;
            Month period = (Month) tsdi.getPeriod();
            int currMonth = period.getMonth();
            int currYear = period.getYearValue();
            int lastMonthFilled = lastMonth.getMonth();
            int lastYearFilled = lastMonth.getYearValue();
            boolean isLast = false;
            if (currYear == lastYearFilled && currMonth == lastMonthFilled) {
                isLast = true;
            }
            return isLast;
        }
    };
    renderer.setSeriesPaint(0, Color.decode("0x000000"));

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(colorLast);
    renderer.setBaseOutlinePaint(Color.BLACK);
    renderer.setUseOutlinePaint(true);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0));

    if (wlt_mode.doubleValue() == 0) {
        renderer.setBaseItemLabelsVisible(Boolean.FALSE, true);
    } else {
        renderer.setBaseItemLabelsVisible(Boolean.TRUE, true);
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());
        renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("{2}", new DecimalFormat("0.###"),
                new DecimalFormat("0.###")) {
            public String generateLabel(CategoryDataset dataset, int row, int column) {
                if (dataset.getValue(row, column) == null || dataset.getValue(row, column).doubleValue() == 0)
                    return "";
                String columnKey = (String) dataset.getColumnKey(column);
                int separator = columnKey.indexOf('-');
                String month = columnKey.substring(0, separator);
                String year = columnKey.substring(separator + 1);
                int monthNum = Integer.parseInt(month);
                if (wlt_mode.doubleValue() >= 1 && wlt_mode.doubleValue() <= 4) {
                    if (wlt_mode.doubleValue() == 2 && column % 2 == 0)
                        return "";

                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.MONTH, monthNum - 1);
                    SimpleDateFormat dataFormat = new SimpleDateFormat("MMM");
                    return dataFormat.format(calendar.getTime());
                } else
                    return "" + monthNum;
            }
        });
    }

    if (wlt_mode.doubleValue() == 3) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 2));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 2));

    } else if (wlt_mode.doubleValue() == 4) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 4));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 4));
    }

    if (legend == true) {
        LegendItemCollection collection = createThresholdLegend(plot);
        LegendItem item = new LegendItem("Avg", "Avg", "Avg", "Avg", new Rectangle(10, 10), colorAverage);
        collection.add(item);
        plot.setFixedLegendItems(collection);

    }

    plot.setRenderer(0, renderer);
    logger.debug("OUT");
    return sparkLineGraph;
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java

@Override
public void initChart(final IScope scope, final String chartname) {
    super.initChart(scope, chartname);

    final XYPlot pp = (XYPlot) chart.getPlot();
    pp.setDomainGridlinePaint(axesColor);
    pp.setRangeGridlinePaint(axesColor);
    pp.setDomainCrosshairPaint(axesColor);
    pp.setRangeCrosshairPaint(axesColor);
    pp.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    pp.setDomainCrosshairVisible(false);
    pp.setRangeCrosshairVisible(false);
    pp.setRangeGridlinesVisible(false);/* w  w w .j  av a2 s.  c  om*/
    pp.setDomainGridlinesVisible(false);

    pp.getDomainAxis().setAxisLinePaint(axesColor);

    pp.getDomainAxis().setTickLabelFont(getTickFont());
    pp.getDomainAxis().setLabelFont(getLabelFont());
    if (textColor != null) {
        pp.getDomainAxis().setLabelPaint(textColor);
        pp.getDomainAxis().setTickLabelPaint(textColor);
    }
    if (xtickunit > 0) {
        ((NumberAxis) pp.getDomainAxis()).setTickUnit(new NumberTickUnit(xtickunit));
    }

    pp.getRangeAxis().setAxisLinePaint(axesColor);
    pp.getRangeAxis().setLabelFont(getLabelFont());
    pp.getRangeAxis().setTickLabelFont(getTickFont());
    if (textColor != null) {
        pp.getRangeAxis().setLabelPaint(textColor);
        pp.getRangeAxis().setTickLabelPaint(textColor);
    }
    if (ytickunit > 0) {
        ((NumberAxis) pp.getRangeAxis()).setTickUnit(new NumberTickUnit(ytickunit));
    }

    // resetAutorange(scope);

    if (xlabel != null && !xlabel.isEmpty()) {
        pp.getDomainAxis().setLabel(xlabel);
    }
    if (ylabel != null && !ylabel.isEmpty()) {
        pp.getRangeAxis().setLabel(ylabel);
    }

}

From source file:org.eumetsat.metop.visat.IasiInfoView.java

private void configureSpectrumPlot(XYPlot plot) {
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(false);
    plot.setNoDataMessage(NO_IFOV_SELECTED);
}

From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java

/**
 * Generates a Sparkline Bar Graph./*from   w ww.  j a  v a 2s . c o m*/
 *
 * @param def the key of the statistic object.
 * @return the generated chart.
 */
public JFreeChart generateSparklineBarGraph(String key, String color, Statistic[] def, long startTime,
        long endTime, int dataPoints) {
    Color backgroundColor = getBackgroundColor();

    IntervalXYDataset dataset = (IntervalXYDataset) populateData(key, def, startTime, endTime, dataPoints);
    JFreeChart chart = ChartFactory.createXYBarChart(null, // chart title
            null, // domain axis label
            true, null, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            false, // tooltips?
            false // URLs?
    );

    chart.setBackgroundPaint(backgroundColor);
    chart.setBorderVisible(false);
    chart.setBorderPaint(null);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(backgroundColor);
    plot.setRangeGridlinesVisible(false);

    GraphDefinition graphDef = GraphDefinition.getDefinition(color);
    Color plotColor = graphDef.getInlineColor(0);
    plot.getRenderer().setSeriesPaint(0, plotColor);
    plot.getRenderer().setBaseItemLabelsVisible(false);
    plot.getRenderer().setBaseOutlinePaint(backgroundColor);
    plot.setOutlineStroke(null);
    plot.setDomainGridlinePaint(null);

    ValueAxis xAxis = chart.getXYPlot().getDomainAxis();

    xAxis.setLabel(null);
    xAxis.setTickLabelsVisible(true);
    xAxis.setTickMarksVisible(true);
    xAxis.setAxisLineVisible(false);
    xAxis.setNegativeArrowVisible(false);
    xAxis.setPositiveArrowVisible(false);
    xAxis.setVisible(false);

    ValueAxis yAxis = chart.getXYPlot().getRangeAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setAxisLineVisible(false);
    yAxis.setNegativeArrowVisible(false);
    yAxis.setPositiveArrowVisible(false);
    yAxis.setVisible(false);

    return chart;
}

From source file:ucar.unidata.idv.control.chart.PlotWrapper.java

/**
 * Utility to init xy plots// ww  w  . j  ava2  s  .  com
 *
 * @param plot the plotx
 */
protected void initXYPlot(XYPlot plot) {
    plot.setBackgroundPaint(dataAreaColor);
    //        plot.setAxisOffset(new RectangleInsets(6.0, 3.0, 3.0, 3.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    plot.setDomainGridlinesVisible(domainLineState.getVisible());
    plot.setRangeGridlinesVisible(rangeLineState.getVisible());
    plot.setDomainGridlinePaint(domainLineState.getColor());
    plot.setRangeGridlinePaint(rangeLineState.getColor());
    plot.setDomainGridlineStroke(domainLineState.getStroke());
    plot.setRangeGridlineStroke(rangeLineState.getStroke());
}

From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java

/**
 * Generates a SparkLine Time Area Chart.
 * @param key//from w  ww  .  java  2  s .c  o m
 * @param stats
 * @param startTime
 * @param endTime
 * @return chart
 */
private JFreeChart generateSparklineAreaChart(String key, String color, Statistic[] stats, long startTime,
        long endTime, int dataPoints) {
    Color backgroundColor = getBackgroundColor();

    XYDataset dataset = populateData(key, stats, startTime, endTime, dataPoints);

    JFreeChart chart = ChartFactory.createXYAreaChart(null, // chart title
            null, // xaxis label
            null, // yaxis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            false, // tooltips?
            false // URLs?
    );

    chart.setBackgroundPaint(backgroundColor);
    chart.setBorderVisible(false);
    chart.setBorderPaint(null);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(1.0f);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(backgroundColor);
    plot.setRangeGridlinesVisible(false);

    GraphDefinition graphDef = GraphDefinition.getDefinition(color);
    Color plotColor = graphDef.getInlineColor(0);
    plot.getRenderer().setSeriesPaint(0, plotColor);
    plot.getRenderer().setBaseItemLabelsVisible(false);
    plot.getRenderer().setBaseOutlinePaint(backgroundColor);
    plot.setOutlineStroke(null);
    plot.setDomainGridlinePaint(null);

    NumberAxis xAxis = (NumberAxis) chart.getXYPlot().getDomainAxis();

    xAxis.setLabel(null);
    xAxis.setTickLabelsVisible(true);
    xAxis.setTickMarksVisible(true);
    xAxis.setAxisLineVisible(false);
    xAxis.setNegativeArrowVisible(false);
    xAxis.setPositiveArrowVisible(false);
    xAxis.setVisible(false);

    NumberAxis yAxis = (NumberAxis) chart.getXYPlot().getRangeAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setAxisLineVisible(false);
    yAxis.setNegativeArrowVisible(false);
    yAxis.setPositiveArrowVisible(false);
    yAxis.setVisible(false);

    return chart;
}

From source file:loci.slim2.process.interactive.ui.DefaultDecayGraph.java

/**
 * Creates the chart//from w ww  . j  av  a 2  s  . c  om
 *
 * @param bins number of bins
 * @param timeInc time increment per bin
 * @return the chart
 */
JFreeChart createCombinedChart(final int bins, final double timeInc) {

    // create empty chart data sets
    decayDataset = new XYSeriesCollection();
    residualDataset = new XYSeriesCollection();

    // make a common horizontal axis for both sub-plots
    final NumberAxis timeAxis = new NumberAxis(TIME_AXIS_LABEL);
    timeAxis.setLabel(UNITS_LABEL);
    timeAxis.setRange(0.0, (bins - 1) * timeInc);

    // make a vertically combined plot
    final CombinedDomainXYPlot parent = new CombinedDomainXYPlot(timeAxis);

    // create decay sub-plot
    NumberAxis photonAxis;
    if (logarithmic) {
        photonAxis = new LogarithmicAxis(PHOTON_AXIS_LABEL);
    } else {
        photonAxis = new NumberAxis(PHOTON_AXIS_LABEL);
    }
    final XYSplineRenderer decayRenderer = new XYSplineRenderer();
    decayRenderer.setSeriesShapesVisible(0, false);
    decayRenderer.setSeriesShapesVisible(1, false);
    decayRenderer.setSeriesLinesVisible(2, false);
    decayRenderer.setSeriesShape(2, new Ellipse2D.Float(-1.0f, -1.0f, 2.0f, 2.0f));

    decayRenderer.setSeriesPaint(0, PROMPT_COLOR);
    decayRenderer.setSeriesPaint(1, FITTED_COLOR);
    decayRenderer.setSeriesPaint(2, DECAY_COLOR);

    decaySubPlot = new XYPlot(decayDataset, null, photonAxis, decayRenderer);
    decaySubPlot.setDomainCrosshairVisible(true);
    decaySubPlot.setRangeCrosshairVisible(true);

    // add decay sub-plot to parent
    parent.add(decaySubPlot, DECAY_WEIGHT);

    // create residual sub-plot
    final NumberAxis residualAxis = new NumberAxis(RESIDUAL_AXIS_LABEL);
    final XYSplineRenderer residualRenderer = new XYSplineRenderer();
    residualRenderer.setSeriesPaint(0, RESIDUAL_COLOR);
    residualRenderer.setSeriesLinesVisible(0, false);
    residualRenderer.setSeriesShape(0, new Ellipse2D.Float(-1.0f, -1.0f, 2.0f, 2.0f));

    final XYPlot residualSubPlot = new XYPlot(residualDataset, null, residualAxis, residualRenderer);
    residualSubPlot.setDomainCrosshairVisible(true);
    residualSubPlot.setRangeCrosshairVisible(true);
    residualSubPlot.setFixedLegendItems(null);

    // add residual sub-plot to parent
    parent.add(residualSubPlot, RESIDUAL_WEIGHT);

    // now make the top level JFreeChart
    final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, parent, true);
    chart.removeLegend();

    return chart;
}

From source file:org.locationtech.udig.processingtoolbox.tools.MoranScatterPlotDialog.java

private void updateChart(SimpleFeatureCollection features, String propertyName, String morani) {
    // 1. Create a single plot containing both the scatter and line
    XYPlot plot = new XYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setDomainPannable(false);//from   w w w. j av  a  2  s  . c  om
    plot.setRangePannable(false);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setDomainCrosshairLockedOnData(true);
    plot.setRangeCrosshairLockedOnData(true);
    plot.setDomainCrosshairPaint(java.awt.Color.CYAN);
    plot.setRangeCrosshairPaint(java.awt.Color.CYAN);

    plot.setDomainGridlinePaint(java.awt.Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(java.awt.Color.LIGHT_GRAY);

    // 2. Setup Scatter plot
    // Create the scatter data, renderer, and axis
    int fontStyle = java.awt.Font.BOLD;
    FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0];

    NumberAxis xPlotAxis = new NumberAxis(propertyName); // ZScore
    xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));

    NumberAxis yPlotAxis = new NumberAxis("lagged " + propertyName); //$NON-NLS-1$
    yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));

    XYToolTipGenerator plotToolTip = new StandardXYToolTipGenerator();

    XYItemRenderer plotRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only
    plotRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3));
    plotRenderer.setSeriesPaint(0, java.awt.Color.BLUE); // dot
    plotRenderer.setBaseToolTipGenerator(plotToolTip);

    // Set the scatter data, renderer, and axis into plot
    plot.setDataset(0, getScatterPlotData(features));
    plot.setRenderer(0, plotRenderer);
    plot.setDomainAxis(0, xPlotAxis);
    plot.setRangeAxis(0, yPlotAxis);

    // Map the scatter to the first Domain and first Range
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    // 3. Setup line
    // Create the line data, renderer, and axis
    XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only
    lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY); // dot

    // Set the line data, renderer, and axis into plot
    NumberAxis xLineAxis = new NumberAxis(EMPTY);
    xLineAxis.setTickMarksVisible(false);
    xLineAxis.setTickLabelsVisible(false);
    NumberAxis yLineAxis = new NumberAxis(EMPTY);
    yLineAxis.setTickMarksVisible(false);
    yLineAxis.setTickLabelsVisible(false);

    plot.setDataset(1, getLinePlotData(crossCenter));
    plot.setRenderer(1, lineRenderer);
    plot.setDomainAxis(1, xLineAxis);
    plot.setRangeAxis(1, yLineAxis);

    // Map the line to the second Domain and second Range
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 0);

    // 4. Setup Selection
    NumberAxis xSelectionAxis = new NumberAxis(EMPTY);
    xSelectionAxis.setTickMarksVisible(false);
    xSelectionAxis.setTickLabelsVisible(false);
    NumberAxis ySelectionAxis = new NumberAxis(EMPTY);
    ySelectionAxis.setTickMarksVisible(false);
    ySelectionAxis.setTickLabelsVisible(false);

    XYItemRenderer selectionRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only
    selectionRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 6, 6));
    selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot

    plot.setDataset(2, new XYSeriesCollection(new XYSeries(EMPTY)));
    plot.setRenderer(2, selectionRenderer);
    plot.setDomainAxis(2, xSelectionAxis);
    plot.setRangeAxis(2, ySelectionAxis);

    // Map the scatter to the second Domain and second Range
    plot.mapDatasetToDomainAxis(2, 0);
    plot.mapDatasetToRangeAxis(2, 0);

    // 5. Finally, Create the chart with the plot and a legend
    String title = "Moran's I = " + morani; //$NON-NLS-1$
    java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20);
    JFreeChart chart = new JFreeChart(title, titleFont, plot, false);
    chart.setBackgroundPaint(java.awt.Color.WHITE);
    chart.setBorderVisible(false);

    chartComposite.setChart(chart);
    chartComposite.forceRedraw();
}

From source file:com.android.ddmuilib.log.event.EventDisplay.java

Control createCompositeChart(final Composite parent, EventLogParser logParser, String title) {
    mChart = ChartFactory.createTimeSeriesChart(null, null /* timeAxisLabel */, null /* valueAxisLabel */,
            null, /* dataset. set below */
            true /* legend */, false /* tooltips */, false /* urls */);

    // get the font to make a proper title. We need to convert the swt font,
    // into an awt font.
    Font f = parent.getFont();/*from  ww w . j  av  a 2  s  .  c  om*/
    FontData[] fData = f.getFontData();

    // event though on Mac OS there could be more than one fontData, we'll only use
    // the first one.
    FontData firstFontData = fData[0];

    java.awt.Font awtFont = SWTUtils.toAwtFont(parent.getDisplay(), firstFontData, true /* ensureSameSize */);

    mChart.setTitle(new TextTitle(title, awtFont));

    final XYPlot xyPlot = mChart.getXYPlot();
    xyPlot.setRangeCrosshairVisible(true);
    xyPlot.setRangeCrosshairLockedOnData(true);
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setDomainCrosshairLockedOnData(true);

    mChart.addChangeListener(new ChartChangeListener() {
        @Override
        public void chartChanged(ChartChangeEvent event) {
            ChartChangeEventType type = event.getType();
            if (type == ChartChangeEventType.GENERAL) {
                // because the value we need (rangeCrosshair and domainCrosshair) are
                // updated on the draw, but the notification happens before the draw,
                // we process the click in a future runnable!
                parent.getDisplay().asyncExec(new Runnable() {
                    @Override
                    public void run() {
                        processClick(xyPlot);
                    }
                });
            }
        }
    });

    mChartComposite = new ChartComposite(parent, SWT.BORDER, mChart, ChartComposite.DEFAULT_WIDTH,
            ChartComposite.DEFAULT_HEIGHT, ChartComposite.DEFAULT_MINIMUM_DRAW_WIDTH,
            ChartComposite.DEFAULT_MINIMUM_DRAW_HEIGHT, 3000, // max draw width. We don't want it to zoom, so we put a big number
            3000, // max draw height. We don't want it to zoom, so we put a big number
            true, // off-screen buffer
            true, // properties
            true, // save
            true, // print
            true, // zoom
            true); // tooltips

    mChartComposite.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent e) {
            mValueTypeDataSetMap.clear();
            mDataSetCount = 0;
            mOccurrenceDataSet = null;
            mChart = null;
            mChartComposite = null;
            mValueDescriptorSeriesMap.clear();
            mOcurrenceDescriptorSeriesMap.clear();
        }
    });

    return mChartComposite;

}

From source file:org.trade.ui.chart.CandlestickChart.java

/**
 * Method createChart.//from ww w  .ja  va  2 s  .com
 * 
 * @param strategyData
 *            StrategyData
 * @param title
 *            String
 * @return JFreeChart
 */
private JFreeChart createChart(StrategyData strategyData, String title, Tradingday tradingday) {

    DateAxis dateAxis = new DateAxis("Date");
    dateAxis.setVerticalTickLabels(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm"));
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    NumberAxis priceAxis = new NumberAxis("Price");
    priceAxis.setAutoRange(true);
    priceAxis.setAutoRangeIncludesZero(false);
    XYPlot pricePlot = new XYPlot(strategyData.getCandleDataset(), dateAxis, priceAxis,
            strategyData.getCandleDataset().getRenderer());
    pricePlot.setOrientation(PlotOrientation.VERTICAL);
    pricePlot.setDomainPannable(true);
    pricePlot.setRangePannable(true);
    pricePlot.setDomainCrosshairVisible(true);
    pricePlot.setDomainCrosshairLockedOnData(true);
    pricePlot.setRangeCrosshairVisible(true);
    pricePlot.setRangeCrosshairLockedOnData(true);
    pricePlot.setRangeGridlinePaint(new Color(204, 204, 204));
    pricePlot.setDomainGridlinePaint(new Color(204, 204, 204));
    pricePlot.setBackgroundPaint(Color.white);

    /*
     * Calculate the number of 15min segments in this trading day. i.e.
     * 6.5hrs/15min = 26 and there are a total of 96 = one day
     */

    int segments15min = (int) (tradingday.getClose().getTime() - tradingday.getOpen().getTime())
            / (1000 * 60 * 15);

    SegmentedTimeline segmentedTimeline = new SegmentedTimeline(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE,
            segments15min, (96 - segments15min));

    Date startDate = tradingday.getOpen();
    Date endDate = tradingday.getClose();

    if (!strategyData.getCandleDataset().getSeries(0).isEmpty()) {
        startDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0).getDataItem(0)).getPeriod()
                .getStart();
        startDate = TradingCalendar.getSpecificTime(tradingday.getOpen(), startDate);
        endDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0)
                .getDataItem(strategyData.getCandleDataset().getSeries(0).getItemCount() - 1)).getPeriod()
                        .getStart();
        endDate = TradingCalendar.getSpecificTime(tradingday.getClose(), endDate);
    }

    segmentedTimeline.setStartTime(startDate.getTime());
    segmentedTimeline.addExceptions(getNonTradingPeriods(startDate, endDate, tradingday.getOpen(),
            tradingday.getClose(), segmentedTimeline));
    dateAxis.setTimeline(segmentedTimeline);

    // Build Combined Plot
    CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(dateAxis);
    mainPlot.add(pricePlot, 4);

    int axixIndex = 0;
    int datasetIndex = 0;

    /*
     * Change the List of indicators so that the candle dataset is the first
     * one in the list. The main chart must be plotted first.
     */
    List<IndicatorDataset> indicators = new ArrayList<IndicatorDataset>(0);
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (!IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (int i = 0; i < indicators.size(); i++) {
        IndicatorDataset indicator = indicators.get(i);
        if (indicator.getDisplaySeries(0)) {

            if (indicator.getSubChart(0)) {
                String axisName = "Price";
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    axisName = ((CandleSeries) indicator.getSeries(0)).getSymbol();
                } else {
                    org.trade.dictionary.valuetype.IndicatorSeries code = org.trade.dictionary.valuetype.IndicatorSeries
                            .newInstance(indicator.getType(0));
                    axisName = code.getDisplayName();
                }
                NumberAxis subPlotAxis = new NumberAxis(axisName);
                subPlotAxis.setAutoRange(true);
                subPlotAxis.setAutoRangeIncludesZero(false);

                XYPlot subPlot = new XYPlot((XYDataset) indicator, dateAxis, subPlotAxis,
                        indicator.getRenderer());

                subPlot.setOrientation(PlotOrientation.VERTICAL);
                subPlot.setDomainPannable(true);
                subPlot.setRangePannable(true);
                subPlot.setDomainCrosshairVisible(true);
                subPlot.setDomainCrosshairLockedOnData(true);
                subPlot.setRangeCrosshairVisible(true);
                subPlot.setRangeCrosshairLockedOnData(true);
                subPlot.setRangeGridlinePaint(new Color(204, 204, 204));
                subPlot.setDomainGridlinePaint(new Color(204, 204, 204));
                subPlot.setBackgroundPaint(Color.white);
                XYItemRenderer renderer = subPlot.getRendererForDataset((XYDataset) indicator);
                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
                mainPlot.add(subPlot, 1);

            } else {
                datasetIndex++;
                pricePlot.setDataset(datasetIndex, (XYDataset) indicator);
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    // add secondary axis
                    axixIndex++;

                    final NumberAxis axis2 = new NumberAxis(
                            ((CandleSeries) indicator.getSeries(0)).getSymbol());
                    axis2.setAutoRange(true);
                    axis2.setAutoRangeIncludesZero(false);
                    pricePlot.setRangeAxis(datasetIndex, axis2);
                    pricePlot.setRangeAxisLocation(i + 1, AxisLocation.BOTTOM_OR_RIGHT);
                    pricePlot.mapDatasetToRangeAxis(datasetIndex, axixIndex);
                    pricePlot.setRenderer(datasetIndex, new StandardXYItemRenderer());
                } else {
                    pricePlot.setRenderer(datasetIndex, indicator.getRenderer());
                }
                XYItemRenderer renderer = pricePlot.getRendererForDataset((XYDataset) indicator);

                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
            }
        }
    }
    JFreeChart jfreechart = new JFreeChart(title, null, mainPlot, true);
    jfreechart.setAntiAlias(false);
    return jfreechart;
}