org.jfree.chart.plot.Marker Java Examples

The following examples show how to use org.jfree.chart.plot.Marker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChartUtil.java    From ezScrum with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private void setMarker(XYPlot plot) {
	Iterator<Date> ir = m_dateMarkerMap.keySet().iterator();
	int index = 1;
	while (ir.hasNext()) {

		Date key = ir.next();

		final Marker marker = new IntervalMarker(key.getTime(),
				m_dateMarkerMap.get(key).getTime());

		if (this.m_visualMarkerLabel)
			marker.setLabel("#" + index);
		// marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
		// marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);

		marker.setAlpha(0.3f);
		//marker.setPaint(this.m_markerColor);

		plot.addDomainMarker(marker);
		index++;
	}
}
 
Example #2
Source File: ChartFormatter.java    From nmonvisualizer with Apache License 2.0 6 votes vote down vote up
public void reformatAnnotations() {
    for (Annotation a : AnnotationCache.getAnnotations()) {
        if (a instanceof TextAnnotation) {
            formatAnnotation((TextAnnotation) a);
        }
        else if (a instanceof XYTextAnnotation) {
            formatAnnotation((XYTextAnnotation) a);
        }
    }

    for (Marker m : AnnotationCache.getMarkers()) {
        boolean horizontal = m.getLabelTextAnchor() == TextAnchor.TOP_CENTER;

        // match offsets adjustments in formatMarker()
        if (horizontal) {
            formatMarker(m, true, (int) m.getLabelOffset().getLeft() - 50);
        }
        else {
            formatMarker(m, false, (int) m.getLabelOffset().getTop() - 5);
        }
    }
}
 
Example #3
Source File: ChartFormatter.java    From nmonvisualizer with Apache License 2.0 6 votes vote down vote up
public void formatMarker(Marker marker, boolean horizontal, int offset) {
    marker.setStroke(ANNOTATION_STROKE);
    marker.setPaint(annotationColor);
    marker.setLabelFont(ANNOTATION_FONT);
    marker.setLabelPaint(annotationColor);

    if (horizontal) {
        // 50 to move data to the right of the x axis
        marker.setLabelOffset(new RectangleInsets(-5, offset + 50, 5, 5));
        marker.setLabelTextAnchor(TextAnchor.TOP_CENTER);
    }
    else {
        // -5 to move to right of line
        marker.setLabelOffset(new RectangleInsets(offset + 5, -5, 5, 5));
        marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    }
}
 
Example #4
Source File: LineChartPanel.java    From nmonvisualizer with Apache License 2.0 6 votes vote down vote up
@Override
public void addMarkers(List<Marker> markers) {
    if (getChart() != null) {
        XYPlot plot = getChart().getXYPlot();

        plot.clearDomainMarkers();
        plot.clearRangeMarkers();

        for (Marker marker : markers) {
            if (marker instanceof RangeValueMarker) {
                plot.addRangeMarker(marker);
            }
            else if (marker instanceof DomainValueMarker) {
                plot.addDomainMarker(marker);
            }

            firePropertyChange("annotation", null, marker);
        }
    }
}
 
Example #5
Source File: Chart.java    From crypto-bot with Apache License 2.0 6 votes vote down vote up
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.getBar(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.getBar(trade.getExit().getIndex()).getEndTime().toInstant()))
						.getFirstMillisecond();
		Marker sellMarker = new ValueMarker(sellSignalTickTime);
		sellMarker.setPaint(Color.RED);
		sellMarker.setLabel("S");
		plot.addDomainMarker(sellMarker);
	}
}
 
Example #6
Source File: RangeIntervalMarkerCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void addMarker(Plot plot, Marker marker)
{
	if (plot instanceof XYPlot)
	{
		((XYPlot)plot).addRangeMarker(
			marker, 
			getLayer()
			);
	}
	else if (plot instanceof CategoryPlot)
	{
		((CategoryPlot)plot).addRangeMarker(
			marker, 
			getLayer()
			);
	}
}
 
Example #7
Source File: BuyAndSellSignalsToChart.java    From ta4j-origins with MIT License 6 votes vote down vote up
/**
 * 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
 * @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);
    }
}
 
Example #8
Source File: RangeValueMarkerCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void addMarker(Plot plot, Marker marker) 
{
	((XYPlot)plot).addRangeMarker(
		marker, 
		getLayer()
		);
}
 
Example #9
Source File: DomainValueMarkerCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void addMarker(Plot plot, Marker marker) 
{
	((XYPlot)plot).addDomainMarker(
		marker, 
		getLayer()
		);
}
 
Example #10
Source File: DomainValueMarkerCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void customize(JFreeChart jfc, JRChart jrc) 
{
	if (jfc.getPlot() instanceof XYPlot)
	{
		Marker marker = createMarker();
		if (marker != null)
		{
			addMarker(jfc.getPlot(), marker);
		}
	}
}
 
Example #11
Source File: DomainIntervalMarkerCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void addMarker(Plot plot, Marker marker)
{
	((XYPlot)plot).addDomainMarker(
		marker, 
		getLayer()
		);
}
 
Example #12
Source File: ModifiedPlot.java    From chipster with MIT License 5 votes vote down vote up
/**
 * Adds a marker for the range axis.
 * <P>
 * Typically a marker will be drawn by the renderer as a line perpendicular
 * to the range axis, however this is entirely up to the renderer.
 *
 * @param marker The marker.
 */
public void addRangeMarker(Marker marker) {

    if (this.rangeMarkers == null) {
        this.rangeMarkers = new ArrayList<Marker>();
    }
    this.rangeMarkers.add(marker);
    notifyListeners(new PlotChangeEvent(this));

}
 
Example #13
Source File: AbstractMarkerCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void configureStroke(Marker marker)
{
	Float strokeWidth = getFloatProperty(PROPERTY_STROKE_WIDTH);
	if (strokeWidth == null)
	{
		strokeWidth = 1f;
	}

	BasicStroke basicStroke = getStroke(strokeWidth);

	marker.setStroke(basicStroke);
}
 
Example #14
Source File: ModifiedPlot.java    From chipster with MIT License 5 votes vote down vote up
/**
 * Draws a horizontal line across the chart to represent a 'range marker'.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param rangeAxis  the range axis.
 * @param marker  the marker line.
 * @param dataArea  the axis data area.
 */
public void drawRangeMarker(Graphics2D g2,
                            ModifiedPlot plot,
                            ValueAxis rangeAxis,
                            Marker marker,
                            Rectangle2D dataArea) {

    if (marker instanceof ValueMarker) {
        ValueMarker vm = (ValueMarker) marker;
        double value = vm.getValue();
        Range range = rangeAxis.getRange();
        if (!range.contains(value)) {
            return;
        }

        double y = rangeAxis.valueToJava2D(
            value, dataArea, RectangleEdge.LEFT
        );
        Line2D line = new Line2D.Double(
            dataArea.getMinX(), y, dataArea.getMaxX(), y
        );
        Paint paint = marker.getOutlinePaint();
        Stroke stroke = marker.getOutlineStroke();
        g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT);
        g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_STROKE);
        g2.draw(line);
    }

}
 
Example #15
Source File: XYPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the addDomainMarker() method(s).
 */
public void testAddDomainMarker() {
    XYPlot plot = new XYPlot();
    Marker m = new ValueMarker(1.0);
    plot.addDomainMarker(m);
    List listeners = Arrays.asList(m.getListeners(
            MarkerChangeListener.class));
    assertTrue(listeners.contains(plot));
    plot.clearDomainMarkers();
    listeners = Arrays.asList(m.getListeners(MarkerChangeListener.class));
    assertFalse(listeners.contains(plot));
}
 
Example #16
Source File: CategoryMarkerCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void addMarker(Plot plot, Marker marker) 
{
	((CategoryPlot)plot).addDomainMarker(
		(CategoryMarker)marker, 
		getLayer()
		);
}
 
Example #17
Source File: RangeIntervalMarkerCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void customize(JFreeChart jfc, JRChart jrc) 
{
	if (
		jfc.getPlot() instanceof XYPlot
		|| jfc.getPlot() instanceof CategoryPlot
		)
	{
		Marker marker = createMarker();
		if (marker != null)
		{
			addMarker(jfc.getPlot(), marker);
		}
	}
}
 
Example #18
Source File: DomainIntervalMarkerCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void customize(JFreeChart jfc, JRChart jrc) 
{
	if (jfc.getPlot() instanceof XYPlot)
	{
		Marker marker = createMarker();
		if (marker != null)
		{
			addMarker(jfc.getPlot(), marker);
		}
	}
}
 
Example #19
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns a horizontal line marker for the given x value and label.
 */
private Marker getMarker( Double value, String label )
{
    Marker marker = new ValueMarker( value );
    marker.setPaint( Color.BLACK );
    marker.setStroke( new BasicStroke( 1.1f ) );
    marker.setLabel( label );
    marker.setLabelOffset( new RectangleInsets( -10, 50, 0, 0 ) );
    marker.setLabelFont( SUB_TITLE_FONT );

    return marker;
}
 
Example #20
Source File: ChartImageGenerator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns a horizontal line marker for the given x value and label.
 */
private Marker getMarker(Double value, String label )
{
    Marker marker = new ValueMarker( value );
    marker.setPaint( Color.BLACK );
    marker.setStroke( new BasicStroke( 1.1f ) );
    marker.setLabel( label );
    marker.setLabelOffset( new RectangleInsets( -10, 50, 0, 0 ) );
    marker.setLabelFont( SUB_TITLE_FONT );

    return marker;
}
 
Example #21
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a waterfall chart.  The chart object returned by this method
 * uses a {@link CategoryPlot} instance as the plot, with a
 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the
 * range axis, and a {@link WaterfallBarRenderer} as the renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel  the label for the category axis
 *                           (<code>null</code> permitted).
 * @param valueAxisLabel  the label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A waterfall chart.
 */
public static JFreeChart createWaterfallChart(String title,
        String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, boolean legend) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    categoryAxis.setCategoryMargin(0.0);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
    WaterfallBarRenderer renderer = new WaterfallBarRenderer();
    ItemLabelPosition position = new ItemLabelPosition(
            ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 0.0);
    renderer.setBasePositiveItemLabelPosition(position);
    renderer.setBaseNegativeItemLabelPosition(position);
    StandardCategoryToolTipGenerator generator
            = new StandardCategoryToolTipGenerator();
    renderer.setBaseToolTipGenerator(generator);
    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);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #22
Source File: XYPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the addRangeMarker() method(s).
 */
public void testAddRangeMarker() {
    XYPlot plot = new XYPlot();
    Marker m = new ValueMarker(1.0);
    plot.addRangeMarker(m);
    List listeners = Arrays.asList(m.getListeners(
            MarkerChangeListener.class));
    assertTrue(listeners.contains(plot));
    plot.clearRangeMarkers();
    listeners = Arrays.asList(m.getListeners(MarkerChangeListener.class));
    assertFalse(listeners.contains(plot));
}
 
Example #23
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the addRangeMarker() method(s).
 */
public void testAddRangeMarker() {
    CategoryPlot plot = new CategoryPlot();
    Marker m = new ValueMarker(1.0);
    plot.addRangeMarker(m);
    List listeners = Arrays.asList(m.getListeners(
            MarkerChangeListener.class));
    assertTrue(listeners.contains(plot));
    plot.clearRangeMarkers();
    listeners = Arrays.asList(m.getListeners(MarkerChangeListener.class));
    assertFalse(listeners.contains(plot));
}
 
Example #24
Source File: XYPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the addDomainMarker() method(s).
 */
public void testAddDomainMarker() {
    XYPlot plot = new XYPlot();
    Marker m = new ValueMarker(1.0);
    plot.addDomainMarker(m);
    List listeners = Arrays.asList(m.getListeners(
            MarkerChangeListener.class));
    assertTrue(listeners.contains(plot));
    plot.clearDomainMarkers();
    listeners = Arrays.asList(m.getListeners(MarkerChangeListener.class));
    assertFalse(listeners.contains(plot));
}
 
Example #25
Source File: XYPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the addRangeMarker() method(s).
 */
public void testAddRangeMarker() {
    XYPlot plot = new XYPlot();
    Marker m = new ValueMarker(1.0);
    plot.addRangeMarker(m);
    List listeners = Arrays.asList(m.getListeners(
            MarkerChangeListener.class));
    assertTrue(listeners.contains(plot));
    plot.clearRangeMarkers();
    listeners = Arrays.asList(m.getListeners(MarkerChangeListener.class));
    assertFalse(listeners.contains(plot));
}
 
Example #26
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the addRangeMarker() method(s).
 */
public void testAddRangeMarker() {
    CategoryPlot plot = new CategoryPlot();
    Marker m = new ValueMarker(1.0);
    plot.addRangeMarker(m);
    List listeners = Arrays.asList(m.getListeners(
            MarkerChangeListener.class));
    assertTrue(listeners.contains(plot));
    plot.clearRangeMarkers();
    listeners = Arrays.asList(m.getListeners(MarkerChangeListener.class));
    assertFalse(listeners.contains(plot));
}
 
Example #27
Source File: Scatter.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void addAnnotation( String text, double x ) {
    XYPlot plot = (XYPlot) getChart().getPlot();
    Color color = new Color(0, 0, 0, 100);
    Marker updateMarker = new ValueMarker(x, color, new BasicStroke(2f));
    plot.addDomainMarker(updateMarker);
    if (text != null) {
        XYTextAnnotation updateLabel = new XYTextAnnotation(text, x, 0);
        updateLabel.setRotationAnchor(TextAnchor.BASELINE_CENTER);
        updateLabel.setTextAnchor(TextAnchor.BASELINE_CENTER);
        updateLabel.setRotationAngle(-3.14 / 2);
        updateLabel.setPaint(Color.black);
        plot.addAnnotation(updateLabel);
    }
    setShapeLinesVisibility(plot);
}
 
Example #28
Source File: AnnotationCache.java    From nmonvisualizer with Apache License 2.0 5 votes vote down vote up
public static void add(Object o) {
    if (o instanceof Marker) {
        markers.add((Marker) o);
    }
    else if (o instanceof Annotation) {
        annotations.add((Annotation) o);
    }
    else {
        return;
    }

    for (AnnotationListener listener : listeners) {
        listener.annotationAdded();
    }
}
 
Example #29
Source File: AnnotationCache.java    From nmonvisualizer with Apache License 2.0 5 votes vote down vote up
public static void addMarker(Marker marker) {
    if (marker != null) {
        markers.add(marker);

        for (AnnotationListener listener : listeners) {
            listener.annotationAdded();
        }
    }
}
 
Example #30
Source File: ModifiedPlot.java    From chipster with MIT License 5 votes vote down vote up
/**
 * Adds a marker for the domain axis.
 * <P>
 * Typically a marker will be drawn by the renderer as a line perpendicular
 * to the range axis, however this is entirely up to the renderer.
 *
 * @param marker the marker.
 */
public void addDomainMarker(Marker marker) {

    if (this.domainMarkers == null) {
        this.domainMarkers = new ArrayList<Marker>();
    }
    this.domainMarkers.add(marker);
    notifyListeners(new PlotChangeEvent(this));

}