Example usage for org.jfree.chart.plot Marker setPaint

List of usage examples for org.jfree.chart.plot Marker setPaint

Introduction

In this page you can find the example usage for org.jfree.chart.plot Marker setPaint.

Prototype

public void setPaint(Paint paint) 

Source Link

Document

Sets the paint and sends a MarkerChangeEvent to all registered listeners.

Usage

From source file:ta4jexamples.analysis.BuyAndSellSignalsToChart.java

/**
 * Runs a strategy over a time series and adds the value markers
 * corresponding to buy/sell signals to the plot.
 * @param series a time series//from  w w w  .j  av a  2  s  .c om
 * @param strategy a trading strategy
 * @param plot the plot
 */
private static void addBuySellSignals(TimeSeries series, Strategy strategy, XYPlot plot) {
    // Running the strategy
    TimeSeriesManager seriesManager = new TimeSeriesManager(series);
    List<Trade> trades = seriesManager.run(strategy).getTrades();
    // Adding markers to plot
    for (Trade trade : trades) {
        // Buy signal
        double buySignalTickTime = new Minute(
                Date.from(series.getTick(trade.getEntry().getIndex()).getEndTime().toInstant()))
                        .getFirstMillisecond();
        Marker buyMarker = new ValueMarker(buySignalTickTime);
        buyMarker.setPaint(Color.GREEN);
        buyMarker.setLabel("B");
        plot.addDomainMarker(buyMarker);
        // Sell signal
        double sellSignalTickTime = new Minute(
                Date.from(series.getTick(trade.getExit().getIndex()).getEndTime().toInstant()))
                        .getFirstMillisecond();
        Marker sellMarker = new ValueMarker(sellSignalTickTime);
        sellMarker.setPaint(Color.RED);
        sellMarker.setLabel("S");
        plot.addDomainMarker(sellMarker);
    }
}

From source file:com.leonarduk.finance.analysis.BuyAndSellSignalsToChart.java

/**
 * Runs a strategy over a time series and adds the value markers
 * corresponding to buy/sell signals to the plot.
 *
 * @param series/*from w  ww. j  av  a2  s.  c  om*/
 *            a time series
 * @param strategy2
 *            a trading strategy
 * @param plot
 *            the plot
 */
private static void addBuySellSignals(final TimeSeries series, final AbstractStrategy strategy2,
        final XYPlot plot) {
    // Running the strategy
    final List<Trade> trades = series.run(strategy2.getStrategy()).getTrades();
    // Adding markers to plot
    for (final Trade trade : trades) {
        // Buy signal
        final double buySignalTickTime = new Minute(
                series.getTick(trade.getEntry().getIndex()).getEndTime().toDate()).getFirstMillisecond();
        final Marker buyMarker = new ValueMarker(buySignalTickTime);
        buyMarker.setPaint(Color.GREEN);
        buyMarker.setLabel("B");
        plot.addDomainMarker(buyMarker);
        // Sell signal
        final double sellSignalTickTime = new Minute(
                series.getTick(trade.getExit().getIndex()).getEndTime().toDate()).getFirstMillisecond();
        final Marker sellMarker = new ValueMarker(sellSignalTickTime);
        sellMarker.setPaint(Color.RED);
        sellMarker.setLabel("S");
        plot.addDomainMarker(sellMarker);
    }
}

From source file:org.gwaspi.reports.PlinkReportLoaderCombined.java

private static void appendToCombinedRangePlot(CombinedRangeXYPlot combinedPlot, String chromosome,
        XYSeriesCollection tempChrData, boolean showlables) {
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesVisibleInLegend(0, showlables);
    renderer.setSeriesVisibleInLegend(1, showlables);
    //renderer.setBaseShape(new Ellipse2D.Float(0, 0, 2,2), false);

    if (combinedPlot.getSubplots().isEmpty()) {
        LogAxis rangeAxis = new LogAxis("P value");
        rangeAxis.setBase(10);//  ww w . j a v  a2s  .c o  m
        rangeAxis.setInverted(true);
        rangeAxis.setNumberFormatOverride(GenericReportGenerator.FORMAT_P_VALUE);

        rangeAxis.setTickMarkOutsideLength(2.0f);
        rangeAxis.setMinorTickCount(2);
        rangeAxis.setMinorTickMarksVisible(true);
        rangeAxis.setAxisLineVisible(true);
        rangeAxis.setAutoRangeMinimumSize(0.0000005);
        rangeAxis.setLowerBound(1d);
        //rangeAxis.setAutoRangeIncludesZero(false);

        combinedPlot.setRangeAxis(0, rangeAxis);
    }

    JFreeChart subchart = ChartFactory.createScatterPlot("", "Chr " + chromosome, "", tempChrData,
            PlotOrientation.VERTICAL, true, false, false);

    XYPlot subplot = (XYPlot) subchart.getPlot();
    subplot.setRenderer(renderer);
    subplot.setBackgroundPaint(null);

    final Marker thresholdLine = new ValueMarker(0.0000005);
    thresholdLine.setPaint(Color.red);
    if (showlables) {
        thresholdLine.setLabel("P = 510??");
    }
    thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    subplot.addRangeMarker(thresholdLine);

    NumberAxis chrAxis = (NumberAxis) subplot.getDomainAxis();
    chrAxis.setAxisLineVisible(false);
    chrAxis.setTickLabelsVisible(false);
    chrAxis.setTickMarksVisible(false);
    chrAxis.setAutoRangeIncludesZero(false);
    //combinedPlot.setGap(0);
    combinedPlot.add(subplot, 1);
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsUIUtil.java

public static ChartPanel buildGapChartPanel(final Instances dataSet, final int dateIdx, final Attribute attr,
        final int gapsize, final int position) throws Exception {
    Instances filteredDs = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSet,
            new int[] { attr.index(), dateIdx });
    filteredDs = WekaDataProcessingUtil.buildFilteredDataSet(filteredDs, 0, filteredDs.numAttributes() - 1,
            Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize),
            Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize,
                    filteredDs.numInstances() - 1));

    final ChartPanel cp = TimeSeriesChartUtil.buildChartPanelForAllAttributes(filteredDs, false,
            WekaDataStatsUtil.getFirstDateAttributeIdx(filteredDs), null);

    final XYPlot xyp = (XYPlot) cp.getChart().getPlot();
    xyp.getDomainAxis().setLabel("");
    xyp.getRangeAxis().setLabel("");

    final Marker gapBeginMarker = new ValueMarker(dataSet.instance(Math.max(0, position - 1)).value(dateIdx));
    gapBeginMarker.setPaint(Color.RED);
    gapBeginMarker.setLabel("Gap begin");
    gapBeginMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    gapBeginMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    cp.getChart().getXYPlot().addDomainMarker(gapBeginMarker);

    final Marker gapEndMarker = new ValueMarker(
            dataSet.instance(Math.min(dataSet.numInstances() - 1, position + gapsize)).value(dateIdx));
    gapEndMarker.setPaint(Color.RED);
    gapEndMarker.setLabel("Gap end");
    gapEndMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    gapEndMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    cp.getChart().getXYPlot().addDomainMarker(gapEndMarker);

    addExportPopupMenu(filteredDs, cp);/*w  w  w  . j a v a2s .  c o  m*/

    return cp;
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsUIUtil.java

public static ChartPanel buildGapChartPanelWithCorrection(final Instances pdataSet, final int dateIdx,
        final Attribute attr, final int gapsize, final int position, final GapFiller gapFiller,
        final java.util.Collection<String> attrs) throws Exception {
    final Instances dataSetWithTheGap = new Instances(pdataSet);
    for (int i = position; i < position + gapsize; i++)
        dataSetWithTheGap.instance(i).setMissing(attr);

    int[] arr = new int[] { attr.index(), dateIdx };
    for (final String sss : attrs) {
        arr = ArraysUtil.concat(arr, new int[] { dataSetWithTheGap.attribute(sss).index() });
    }/*from   w w w.  j  ava2 s. com*/

    Instances filteredDsWithTheGap = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSetWithTheGap,
            arr);
    filteredDsWithTheGap = WekaDataProcessingUtil.buildFilteredDataSet(filteredDsWithTheGap, 0,
            filteredDsWithTheGap.numAttributes() - 1,
            Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize),
            Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize,
                    filteredDsWithTheGap.numInstances() - 1));

    final Instances completedds = gapFiller.fillGaps(filteredDsWithTheGap);
    final Instances diff = WekaTimeSeriesUtil.buildDiff(filteredDsWithTheGap, completedds);

    Instances filteredDsWithoutTheGap = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(pdataSet, arr);
    filteredDsWithoutTheGap = WekaDataProcessingUtil.buildFilteredDataSet(filteredDsWithoutTheGap, 0,
            filteredDsWithoutTheGap.numAttributes() - 1,
            Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize),
            Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize,
                    filteredDsWithoutTheGap.numInstances() - 1));

    diff.insertAttributeAt(new Attribute(attr.name() + "_orig"), diff.numAttributes());
    for (int i = 0; i < filteredDsWithoutTheGap.numInstances(); i++) {
        diff.instance(i).setValue(diff.numAttributes() - 1,
                filteredDsWithoutTheGap.instance(i).value(filteredDsWithoutTheGap.attribute(attr.name())));
    }
    //System.out.println(attr.name()+"\n"+diff.toSummaryString());

    final java.util.List<String> toRemove = new java.util.ArrayList<String>();
    for (int j = 0; j < diff.numAttributes(); j++) {
        final String consideredAttrName = diff.attribute(j).name();
        if (!consideredAttrName.contains("timestamp") && !consideredAttrName.contains(attr.name()))
            toRemove.add(consideredAttrName);
    }
    diff.setClassIndex(-1);
    for (final String ssss : toRemove)
        diff.deleteAttributeAt(diff.attribute(ssss).index());
    //System.out.println(attr.name()+"\n"+diff.toSummaryString());

    final ChartPanel cp = TimeSeriesChartUtil.buildChartPanelForAllAttributes(diff, false,
            WekaDataStatsUtil.getFirstDateAttributeIdx(diff), null);

    final XYPlot xyp = (XYPlot) cp.getChart().getPlot();
    xyp.getDomainAxis().setLabel("");
    xyp.getRangeAxis().setLabel("");

    final Marker gapBeginMarker = new ValueMarker(
            dataSetWithTheGap.instance(Math.max(0, position - 1)).value(dateIdx));
    gapBeginMarker.setPaint(Color.RED);
    gapBeginMarker.setLabel("Gap begin");
    gapBeginMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    gapBeginMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    cp.getChart().getXYPlot().addDomainMarker(gapBeginMarker);

    final Marker gapEndMarker = new ValueMarker(dataSetWithTheGap
            .instance(Math.min(dataSetWithTheGap.numInstances() - 1, position + gapsize)).value(dateIdx));
    gapEndMarker.setPaint(Color.RED);
    gapEndMarker.setLabel("Gap end");
    gapEndMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    gapEndMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    cp.getChart().getXYPlot().addDomainMarker(gapEndMarker);

    addExportPopupMenu(diff, cp);

    return cp;
}

From source file:utils.ChartUtils.java

/**
 * Update values of a bar chart/*from   w w  w .  j  a v  a 2 s .  com*/
 * 
 * @param labelsByFreq Labels ordered by frequency
 * @param nInstances Number of instances
 * @param cp CategoryPlot
 */
public static void updateValuesBarChart(ImbalancedFeature[] labelsByFreq, int nInstances, CategoryPlot cp) {
    DefaultCategoryDataset data = new DefaultCategoryDataset();

    double prob;

    labelsByFreq = MetricUtils.sortByFrequency(labelsByFreq);

    double sum = 0.0;
    for (int i = 0; i < labelsByFreq.length; i++) {
        prob = labelsByFreq[i].getAppearances() * 1.0 / nInstances;
        sum += prob;

        data.setValue(prob, labelsByFreq[i].getName(), " ");
    }

    cp.setDataset(data);

    // add mean mark
    sum = sum / labelsByFreq.length;
    Marker start = new ValueMarker(sum);
    start.setPaint(Color.red);
    start.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
    start.setLabel("                        Mean: " + MetricUtils.truncateValue(sum, 3));
    cp.addRangeMarker(start);
}

From source file:utils.ChartUtils.java

/**
 * Update IR bar chart//from  w  w  w  . j a v a 2 s. c  o m
 * 
 * @param labelsByFrequency Labels ordered by frequency
 * @param IR Imbalance Ratio values
 * @param cp CategoryPlot
 */
public static void updateIRBarChart(ImbalancedFeature[] labelsByFrequency, double[] IR, CategoryPlot cp) {
    DefaultCategoryDataset myData = new DefaultCategoryDataset();

    double prob = 0;

    labelsByFrequency = MetricUtils.sortByFrequency(labelsByFrequency);

    double sum = 0.0;
    for (int i = labelsByFrequency.length - 1; i >= 0; i--) {
        prob = IR[i];
        sum += prob;
        myData.setValue(prob, labelsByFrequency[i].getName(), " ");
    }

    cp.setDataset(myData);

    // add mean mark
    sum = sum / labelsByFrequency.length;
    Marker meanMark = new ValueMarker(sum);
    meanMark.setPaint(Color.red);
    meanMark.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
    meanMark.setLabel("                        Mean: " + MetricUtils.truncateValue(sum, 3));
    cp.addRangeMarker(meanMark);

    //Add Imbalance limit mark
    Marker limitMark = new ValueMarker(1.5);
    limitMark.setPaint(Color.black);
    limitMark.setLabelFont(new Font("SansSerif", Font.BOLD, 12));

    if ((sum < 1.3) || (sum > 1.7)) {
        limitMark.setLabel("                                                Imbalance limit (IR=1.5)");
    }
    cp.addRangeMarker(limitMark);
}

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java

private static JFreeChart createWaterfallChart(CategoryDataset dataset) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    categoryAxis.setCategoryMargin(0.0);

    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    WaterfallBarRenderer renderer = new WaterfallBarRenderer();
    if (orientation == PlotOrientation.HORIZONTAL) {
        ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
                TextAnchor.CENTER, Math.PI / 2.0);
        renderer.setBasePositiveItemLabelPosition(position);
        renderer.setBaseNegativeItemLabelPosition(position);
    } else if (orientation == PlotOrientation.VERTICAL) {
        ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
                TextAnchor.CENTER, 0.0);
        renderer.setBasePositiveItemLabelPosition(position);
        renderer.setBaseNegativeItemLabelPosition(position);
    }/* w  w  w.j a v  a2  s  . c  o m*/
    if (tooltips) {
        StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator();
        renderer.setBaseToolTipGenerator(generator);
    }
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.clearRangeMarkers();
    Marker baseline = new ValueMarker(0.0);
    baseline.setPaint(Color.black);
    plot.addRangeMarker(baseline, Layer.FOREGROUND);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart("Waterfall Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    //        GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    //        AbstractRenderer#setSeriesPaint(int, Paint) are ignored;
    //        renderer.setSeriesPaint(0, gp0);
    //        renderer.setSeriesPaint(1, gp1);
    //        renderer.setSeriesPaint(2, gp2);

    //??
    renderer.setFirstBarPaint(gp0);
    renderer.setLastBarPaint(gp2);
    renderer.setPositiveBarPaint(Color.orange);
    renderer.setNegativeBarPaint(Color.cyan);

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    return chart;

}

From source file:org.gwaspi.reports.GenericReportGenerator.java

private static void appendToCombinedRangeManhattanPlot(CombinedRangeXYPlot combinedPlot, String chromosome,
        XYSeriesCollection currChrSC, boolean showlables, double threshold, Color background,
        Color backgroundAlternative, Color main) {

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);

    // Set dot shape of the currently appended Series
    renderer.setSeriesPaint(currChrSC.getSeriesCount() - 1, main);
    renderer.setSeriesVisibleInLegend(currChrSC.getSeriesCount() - 1, showlables);
    renderer.setSeriesShape(currChrSC.getSeriesCount() - 1, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0));

    // Set range axis
    if (combinedPlot.getSubplots().isEmpty()) {
        LogAxis rangeAxis = new LogAxis("P value");
        rangeAxis.setBase(10);/*from w  w  w.ja v a2 s  . c  o  m*/
        rangeAxis.setInverted(true);
        rangeAxis.setNumberFormatOverride(FORMAT_P_VALUE);

        rangeAxis.setTickMarkOutsideLength(2.0f);
        rangeAxis.setMinorTickCount(2);
        rangeAxis.setMinorTickMarksVisible(true);
        rangeAxis.setAxisLineVisible(true);
        rangeAxis.setUpperMargin(0);

        TickUnitSource units = NumberAxis.createIntegerTickUnits();
        rangeAxis.setStandardTickUnits(units);

        combinedPlot.setRangeAxis(0, rangeAxis);
    }

    // Build subchart
    JFreeChart subchart = ChartFactory.createScatterPlot("", "Chr " + chromosome, "", currChrSC,
            PlotOrientation.VERTICAL, false, false, false);

    // Get subplot from subchart
    XYPlot subplot = (XYPlot) subchart.getPlot();
    subplot.setRenderer(renderer);
    subplot.setBackgroundPaint(null);

    // CHART BACKGROUD COLOR
    if (combinedPlot.getSubplots().size() % 2 == 0) {
        subplot.setBackgroundPaint(background); // Hue, saturation, brightness
    } else {
        subplot.setBackgroundPaint(backgroundAlternative); // Hue, saturation, brightness
    }

    // Add significance Threshold to subplot
    final Marker thresholdLine = new ValueMarker(threshold);
    thresholdLine.setPaint(Color.red);
    // Add legend to hetzyThreshold
    if (showlables) {
        thresholdLine.setLabel("P = " + FORMAT_P_VALUE.format(threshold));
    }
    thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    subplot.addRangeMarker(thresholdLine);

    // Chromosome Axis Labels
    NumberAxis chrAxis = (NumberAxis) subplot.getDomainAxis();
    chrAxis.setLabelAngle(1.0);
    chrAxis.setAutoRangeIncludesZero(false);
    chrAxis.setAxisLineVisible(true);

    chrAxis.setTickLabelsVisible(false);
    chrAxis.setTickMarksVisible(false);
    //      chrAxis.setNumberFormatOverride(Report_Analysis.FORMAT_SCIENTIFIC);
    //      TickUnitSource units = NumberAxis.createIntegerTickUnits();
    //      chrAxis.setStandardTickUnits(units);

    //combinedPlot.setGap(0);
    combinedPlot.add(subplot, 1);
}

From source file:de.xirp.chart.ChartManager.java

/**
 * Sets some values on the given//  w  w  w . j  a v  a  2s. co  m
 * {@link org.jfree.chart.plot.XYPlot} corresponding to some
 * options of the {@link de.xirp.chart.ChartOptions}
 * field. <br>
 * <br>
 * If <code>options.is(OptionName.SHOW_THRESHOLD)</code> is
 * <code>true</code> a threshold line is painted to the chart
 * using the <code>threshold</code> field. <br>
 * <br>
 * If <code>options.is(OptionName.USE_RELATIVE)</code> is
 * <code>true</code> the date axis of the plot gets a title
 * indicating that relative values are used. If the flag is
 * <code>false</code> the plot gets a title indicating that
 * absolute values are used.
 * 
 * @param plot
 *            The plot to alter.
 * @param start
 *            The start time.
 * @see de.xirp.chart.ChartOptions
 * @see org.jfree.chart.plot.XYPlot
 */
private static void setXYPlot(XYPlot plot, Date start) {
    plot.setNoDataMessage(NO_DATA_AVAILABLE);

    if (options.is(OptionName.SHOW_THRESHOLD)) {
        Marker marker = new ValueMarker(threshold);
        marker.setPaint(Color.orange);
        marker.setAlpha(0.8f);
        plot.addRangeMarker(marker);
    }

    if (options.is(OptionName.USE_RELATIVE)) {
        DateAxis axis = new DateAxis(I18n.getString("ChartManager.text.relativeTime")); //$NON-NLS-1$
        RelativeDateFormat rdf = new RelativeDateFormat(start);
        axis.setDateFormatOverride(rdf);
        plot.setDomainAxis(axis);
    } else {
        plot.setDomainAxis(new DateAxis(I18n.getString("ChartManager.text.absoluteTime"))); //$NON-NLS-1$
    }
}