Java Code Examples for org.jfree.chart.plot.Marker#setPaint()
The following examples show how to use
org.jfree.chart.plot.Marker#setPaint() .
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: Chart.java From crypto-bot with Apache License 2.0 | 6 votes |
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 2
Source File: BuyAndSellSignalsToChart.java From ta4j-origins with MIT License | 6 votes |
/** * 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 3
Source File: ChartFormatter.java From nmonvisualizer with Apache License 2.0 | 6 votes |
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: DefaultChartService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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 5
Source File: ChartImageGenerator.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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 6
Source File: ChartFactory.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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 7
Source File: AbstractMarkerCustomizer.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
protected void configureMarker(Marker marker) { String label = getProperty(PROPERTY_LABEL); if (label != null && label.length() > 0) { marker.setLabel(label); } RectangleAnchorEnum labelAnchor = RectangleAnchorEnum.getByName(getProperty(PROPERTY_LABEL_ANCHOR)); if (labelAnchor != null) { marker.setLabelAnchor(labelAnchor.getRectangleAnchor()); } Double offsetTop = getDoubleProperty(PROPERTY_LABEL_OFFSET_TOP); Double offsetLeft = getDoubleProperty(PROPERTY_LABEL_OFFSET_LEFT); Double offsetBottom = getDoubleProperty(PROPERTY_LABEL_OFFSET_BOTTOM); Double offsetRight = getDoubleProperty(PROPERTY_LABEL_OFFSET_RIGHT); if ( offsetTop != null || offsetLeft != null || offsetBottom != null || offsetRight != null ) { RectangleInsets currentOffset = marker.getLabelOffset(); marker.setLabelOffset( new RectangleInsets( offsetTop == null ? currentOffset.getTop() : offsetTop, offsetLeft == null ? currentOffset.getLeft() : offsetLeft, offsetBottom == null ? currentOffset.getBottom() : offsetBottom, offsetRight == null ? currentOffset.getRight() : offsetRight ) ); } TextAnchorEnum labelTextAnchor = TextAnchorEnum.getByName(getProperty(PROPERTY_LABEL_TEXT_ANCHOR)); if (labelTextAnchor != null) { marker.setLabelTextAnchor(labelTextAnchor.getTextAnchor()); } Color color = JRColorUtil.getColor(getProperty(PROPERTY_COLOR), null); if (color != null) { marker.setPaint(color); } Float alpha = getFloatProperty(PROPERTY_ALPHA); if (alpha != null) { marker.setAlpha(alpha); } }
Example 8
Source File: JPanelProfil.java From Course_Generator with GNU General Public License v3.0 | 4 votes |
/** * Update the profil chart */ public void RefreshProfilChart() { if (track == null) return; if (track.data.isEmpty()) return; // -- Clear all series if (datasetProfil.getSeriesCount() > 0) datasetProfil.removeAllSeries(); XYPlot plot = chartProfil.getXYPlot(); plot.clearDomainMarkers(); // -- Populate the serie XYSeries serie1 = new XYSeries("Elevation/Distance"); int cmpt = 1; for (CgData r : track.data) { double x = r.getTotal(settings.Unit) / 1000; double y = r.getElevation(settings.Unit); serie1.add(x, y); if (((r.getTag() & CgConst.TAG_MARK) != 0) & showProfilMarker) { Marker m = new ValueMarker(x); m.setPaint(Color.GRAY); m.setLabelFont(new Font("SansSerif", Font.PLAIN, 10)); m.setLabel(String.valueOf(cmpt)); m.setLabelOffset(new RectangleInsets(5, 0, 0, 2)); m.setLabelAnchor(RectangleAnchor.TOP_RIGHT); m.setLabelTextAnchor(TextAnchor.TOP_LEFT); plot.addDomainMarker(m); cmpt++; } } datasetProfil.addSeries(serie1); if (track.getMaxElev(settings.Unit) > track.getMinElev(settings.Unit)) { // XYPlot plot = chart.getXYPlot(); ValueAxis axisY = plot.getRangeAxis(); axisY.setRange(Math.floor(track.getMinElev(settings.Unit) / 100.0) * 100.0, Math.ceil(track.getMaxElev(settings.Unit) / 100.0) * 100.0); } }