use of org.jfree.chart.plot.ValueMarker in project pinot by linkedin.
the class AnomalyGraphGenerator method createGraphMarker.
/**
* Returns either a value marker (point) or a interval marker (range) depending on provided
* inputs. By default values are gray or transparent gray.
* @param intervalStart
* @param intervalEnd
* @return
*/
private Marker createGraphMarker(Long intervalStart, Long intervalEnd, String label) {
Marker anomalyMarker;
if (intervalEnd == null || intervalStart.equals(intervalEnd)) {
// Point
anomalyMarker = new ValueMarker(intervalStart);
anomalyMarker.setPaint(Color.LIGHT_GRAY);
} else {
// Range
anomalyMarker = new IntervalMarker(intervalStart, intervalEnd);
anomalyMarker.setPaint(TRANSPARENT_GRAY);
}
anomalyMarker.setLabel(label);
LOG.info("Anomaly marker generated for: {}, {}", intervalStart, intervalEnd);
return anomalyMarker;
}
use of org.jfree.chart.plot.ValueMarker in project zaproxy by zaproxy.
the class ScanProgressDialog method updateProgress.
/**
* Updates the scan progress shown by the dialogue (scanners' progress/state and chart).
*/
private void updateProgress() {
// Start panel data settings
HostProcess hp = getSelectedHostProcess();
if (scan.getHostProcesses() != null && hp != null) {
// Update the main table entries
model.updateValues(scan, hp);
if (scan.isStopped()) {
this.stopThread = true;
}
if (chart != null) {
ResponseCountSnapshot snapshot = scan.getRequestHistory();
while (snapshot != null) {
try {
Second second = new Second(snapshot.getDate());
this.seriesTotal.add(second, snapshot.getTotal());
this.series100.add(second, snapshot.getResp100());
this.series200.add(second, snapshot.getResp200());
this.series300.add(second, snapshot.getResp300());
this.series400.add(second, snapshot.getResp400());
this.series500.add(second, snapshot.getResp500());
snapshot = scan.getRequestHistory();
for (Plugin plugin : scan.getHostProcesses().get(0).getRunning()) {
if (!labelsAdded.contains(plugin.getName())) {
// Add a vertical line with the plugin name
ValueMarker vm = new ValueMarker(plugin.getTimeStarted().getTime());
double center = chart.getXYPlot().getRangeAxis().getRange().getCentralValue();
if (lastCentre != center) {
if (lastCentre != -1) {
// Move the existing labels so they stay in the centre
@SuppressWarnings("rawtypes") List annotations = chart.getXYPlot().getAnnotations();
for (Object o : annotations) {
if (o instanceof XYTextAnnotation) {
XYTextAnnotation annotation = (XYTextAnnotation) o;
annotation.setY(center);
}
}
}
lastCentre = center;
}
XYTextAnnotation updateLabel = new XYTextAnnotation(plugin.getName(), plugin.getTimeStarted().getTime(), center);
updateLabel.setFont(FontUtils.getFont("Sans Serif"));
updateLabel.setRotationAnchor(TextAnchor.BASELINE_CENTER);
updateLabel.setTextAnchor(TextAnchor.BASELINE_CENTER);
updateLabel.setRotationAngle(-3.14 / 2);
updateLabel.setPaint(Color.black);
chart.getXYPlot().addDomainMarker(vm, Layer.BACKGROUND);
chart.getXYPlot().addAnnotation(updateLabel);
labelsAdded.add(plugin.getName());
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
snapshot = null;
}
}
}
}
}
use of org.jfree.chart.plot.ValueMarker in project crypto-bot by jnidzwetzki.
the class Chart method addBuySellSignals.
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);
}
}
use of org.jfree.chart.plot.ValueMarker in project ta4j by ta4j.
the class BuyAndSellSignalsToChart method addBuySellSignals.
/**
* 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 buySignalBarTime = new Minute(Date.from(series.getBar(trade.getEntry().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
Marker buyMarker = new ValueMarker(buySignalBarTime);
buyMarker.setPaint(Color.GREEN);
buyMarker.setLabel("B");
plot.addDomainMarker(buyMarker);
// Sell signal
double sellSignalBarTime = new Minute(Date.from(series.getBar(trade.getExit().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
Marker sellMarker = new ValueMarker(sellSignalBarTime);
sellMarker.setPaint(Color.RED);
sellMarker.setLabel("S");
plot.addDomainMarker(sellMarker);
}
}
use of org.jfree.chart.plot.ValueMarker in project mafscaling by vimsh.
the class LogView method createGraghPanel.
private void createGraghPanel() {
JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
chartPanel = new ChartPanel(chart, true, true, true, true, true);
chartPanel.setFocusable(true);
chartPanel.setAutoscrolls(true);
chartPanel.setPopupMenu(null);
chart.setBackgroundPaint(chartColor);
rpmDataset = new XYSeriesCollection();
rpmPlotRenderer = new XYLineAndShapeRenderer();
dataset = new XYSeriesCollection();
plotRenderer = new XYLineAndShapeRenderer();
NumberAxis xAxis = new NumberAxis();
xAxis.setTickLabelsVisible(false);
xAxis.setTickLabelPaint(Color.WHITE);
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis();
yAxis.setTickLabelsVisible(false);
yAxis.setTickLabelPaint(Color.WHITE);
yAxis.setAutoRangeIncludesZero(false);
NumberAxis y2Axis = new NumberAxis();
y2Axis.setTickLabelsVisible(false);
y2Axis.setTickLabelPaint(Color.WHITE);
y2Axis.setAutoRangeIncludesZero(false);
plot = chartPanel.getChart().getXYPlot();
plot.setRangePannable(true);
plot.setDomainPannable(true);
plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
plot.setBackgroundPaint(chartBgColor);
plot.setDataset(0, rpmDataset);
plot.setRenderer(0, rpmPlotRenderer);
plot.setDomainAxis(0, xAxis);
plot.setRangeAxis(0, yAxis);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
plot.setDataset(1, dataset);
plot.setRenderer(1, plotRenderer);
plot.setRangeAxis(1, y2Axis);
plot.mapDatasetToDomainAxis(1, 0);
plot.mapDatasetToRangeAxis(1, 1);
LegendTitle legend = new LegendTitle(plot);
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
legend.setItemPaint(Color.WHITE);
chart.addLegend(legend);
xMarker = new XYDomainMutilineAnnotation();
xMarker.setDefaultPaint(Color.WHITE);
plot.addAnnotation(xMarker);
chartMouseListener = new ChartMouseListener() {
@Override
public void chartMouseMoved(ChartMouseEvent event) {
try {
Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
boolean isLeft = (p.getX() < (dataArea.getMaxX() - dataArea.getMinX()) / 2) ? true : false;
if (setMarkers(x, isLeft)) {
try {
int selectedCol = logDataTable.getTable().getSelectedColumn();
if (selectedCol < 0)
selectedCol = 0;
if (logPlayWindow == null || startMarker != null || endMarker != null) {
logDataTable.getTable().setRowSelectionInterval((int) x, (int) x);
logDataTable.getTable().changeSelection((int) x, selectedCol, false, false);
} else {
logPlayWindow.setProgressBar((int) x);
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void chartMouseClicked(ChartMouseEvent event) {
chartPanel.requestFocusInWindow();
if (logPlayWindow == null)
return;
if (xMarker.count() == 0)
return;
Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
if (x < 0 || (int) x >= logDataTable.getRowCount())
return;
if (SwingUtilities.isLeftMouseButton(event.getTrigger())) {
if (startMarker == null) {
startMarker = new ValueMarker(x);
startMarker.setPaint(Color.GREEN);
startMarker.setStroke(new BasicStroke(1.5f));
plot.addDomainMarker(startMarker);
} else {
plot.removeDomainMarker(startMarker);
startMarker = null;
}
} else if (SwingUtilities.isRightMouseButton(event.getTrigger())) {
if (endMarker == null) {
endMarker = new ValueMarker(x);
endMarker.setPaint(Color.GREEN);
endMarker.setStroke(new BasicStroke(1.5f));
plot.addDomainMarker(endMarker);
} else {
plot.removeDomainMarker(endMarker);
endMarker = null;
}
}
chartPanel.repaint();
logPlayWindow.setStartEndArea(startMarker, endMarker);
}
};
chartPanel.addChartMouseListener(chartMouseListener);
chartPanel.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (!chartPanel.hasFocus())
return;
int keyCode = e.getKeyCode();
if (keyCode < KeyEvent.VK_LEFT || keyCode > KeyEvent.VK_DOWN)
return;
ValueAxis axis = null;
if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT)
axis = ((XYPlot) chartPanel.getChart().getXYPlot()).getDomainAxis();
else
axis = ((XYPlot) chartPanel.getChart().getXYPlot()).getRangeAxis();
if (axis != null) {
double delta = (axis.getUpperBound() - axis.getLowerBound()) / 100.0;
if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_DOWN)
axis.setRange(axis.getLowerBound() - delta, axis.getUpperBound() - delta);
else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_RIGHT)
axis.setRange(axis.getLowerBound() + delta, axis.getUpperBound() + delta);
}
}
public void keyReleased(KeyEvent arg0) {
}
public void keyTyped(KeyEvent arg0) {
}
});
}
Aggregations