use of org.jfree.chart.ChartPanel in project mafscaling by vimsh.
the class VECalc method createChart.
protected void createChart(JPanel plotPanel, String xAxisName, String yAxisName) {
JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
chart.setBorderVisible(true);
chartPanel = new ChartPanel(chart, true, true, true, true, true);
chartPanel.setAutoscrolls(true);
chartPanel.setMouseZoomable(false);
GridBagConstraints gbl_chartPanel = new GridBagConstraints();
gbl_chartPanel.anchor = GridBagConstraints.CENTER;
gbl_chartPanel.insets = new Insets(3, 3, 3, 3);
gbl_chartPanel.weightx = 1.0;
gbl_chartPanel.weighty = 1.0;
gbl_chartPanel.fill = GridBagConstraints.BOTH;
gbl_chartPanel.gridx = 0;
gbl_chartPanel.gridy = 1;
plotPanel.add(chartPanel, gbl_chartPanel);
XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
lineRenderer.setUseFillPaint(true);
lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
lineRenderer.setSeriesStroke(0, stroke);
lineRenderer.setSeriesPaint(0, Color.RED);
lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
private static final long serialVersionUID = 7593430826693873496L;
public String generateLabel(XYDataset dataset, int series) {
XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
return xys.getDescription();
}
});
NumberAxis xAxis = new NumberAxis(xAxisName);
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis(yAxisName);
yAxis.setAutoRangeIncludesZero(false);
XYSeriesCollection lineDataset = new XYSeriesCollection();
XYPlot plot = chart.getXYPlot();
plot.setRangePannable(true);
plot.setDomainPannable(true);
plot.setDomainGridlinePaint(Color.DARK_GRAY);
plot.setRangeGridlinePaint(Color.DARK_GRAY);
plot.setBackgroundPaint(new Color(224, 224, 224));
plot.setDataset(0, lineDataset);
plot.setRenderer(0, lineRenderer);
plot.setDomainAxis(0, xAxis);
plot.setRangeAxis(0, yAxis);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
LegendTitle legend = new LegendTitle(plot.getRenderer());
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
chart.addLegend(legend);
}
use of org.jfree.chart.ChartPanel in project mafscaling by vimsh.
the class LogView method createWotChart.
protected void createWotChart() {
wotMarker = new XYDomainMutilineAnnotation();
wotMarker.setDefaultPaint(Color.WHITE);
JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
wotChartPanel = new ChartPanel(chart, true, true, true, true, true);
wotChartPanel.setFocusable(true);
wotChartPanel.setAutoscrolls(true);
chart.setBackgroundPaint(chartColor);
wotPlot = chart.getXYPlot();
wotPlot.setRangePannable(true);
wotPlot.setDomainPannable(true);
wotPlot.setDomainGridlinePaint(Color.LIGHT_GRAY);
wotPlot.setRangeGridlinePaint(Color.LIGHT_GRAY);
wotPlot.setBackgroundPaint(chartBgColor);
wotPlot.addAnnotation(wotMarker);
wotPlot.setRangeAxis(null);
NumberAxis xAxis = new NumberAxis();
xAxis.setAutoRangeIncludesZero(false);
xAxis.setTickLabelPaint(Color.WHITE);
xAxis.setLabelPaint(Color.LIGHT_GRAY);
wotPlot.setDomainAxis(0, xAxis);
wotPlot.setDataset(0, new XYSeriesCollection());
wotPlot.mapDatasetToDomainAxis(0, 0);
wotPlot.mapDatasetToRangeAxis(0, 0);
LegendTitle legend = new LegendTitle(wotPlot);
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
legend.setItemPaint(Color.WHITE);
chart.addLegend(legend);
wotChartPanel.addChartMouseListener(new ChartMouseListener() {
@Override
public void chartMouseMoved(ChartMouseEvent event) {
try {
wotPlot.clearRangeMarkers();
wotMarker.clearLabels(false);
Rectangle2D dataArea = wotChartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
Point2D p = wotChartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
double x = wotPlot.getDomainAxis().java2DToValue(p.getX(), dataArea, wotPlot.getDomainAxisEdge());
XYSeriesCollection dataset;
XYSeries series;
for (int i = 0; i < wotPlot.getDatasetCount(); ++i) {
dataset = (XYSeriesCollection) wotPlot.getDataset(i);
if (dataset != null && dataset.getSeriesCount() > 0) {
for (int j = 0; j < dataset.getSeriesCount(); ++j) {
series = dataset.getSeries(j);
int idx = 0;
double closest;
double pclosest = Math.abs(series.getX(0).doubleValue() - x);
for (int k = 1; k < series.getItemCount(); ++k) {
closest = Math.abs(series.getX(k).doubleValue() - x);
if (closest < pclosest) {
idx = k;
pclosest = closest;
}
}
double x0 = series.getX(0).doubleValue();
double x1 = series.getX(series.getItemCount() - 1).doubleValue();
double xerr = x0 * 0.01;
if (x >= (x0 - xerr) && x <= (x1 + xerr))
wotMarker.addLabel(series.getDescription() + ": ", wotPlot.getRenderer(i).getSeriesPaint(j), series.getY(idx).toString(), false);
}
}
}
if (wotMarker.count() > 0) {
boolean isLeft = (p.getX() < (dataArea.getMaxX() - dataArea.getMinX()) / 2) ? true : false;
if (isLeft) {
wotMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
wotMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
} else {
wotMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
wotMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
}
wotMarker.setValue(x);
}
wotChartPanel.repaint();
} catch (Exception ex) {
ex.printStackTrace();
logger.error(ex);
}
}
@Override
public void chartMouseClicked(ChartMouseEvent event) {
wotChartPanel.requestFocusInWindow();
ChartEntity entity = event.getEntity();
if (entity == null || !(entity instanceof LegendItemEntity))
return;
LegendItemEntity itemEntity = (LegendItemEntity) entity;
int seriesIndex = ((XYDataset) itemEntity.getDataset()).indexOf(itemEntity.getSeriesKey());
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) wotChartPanel.getChart().getXYPlot().getRenderer();
Paint p = renderer.getSeriesPaint(seriesIndex);
colorChooser.setColor((Color) p);
final ColorPreviewPanel preview = new ColorPreviewPanel(colorChooser);
colorChooser.setPreviewPanel(preview);
AbstractColorChooserPanel[] panels = colorChooser.getChooserPanels();
for (AbstractColorChooserPanel accp : panels) {
if (!accp.getDisplayName().equals("Swatches")) {
colorChooser.removeChooserPanel(accp);
}
}
ColorSelectionModel model = colorChooser.getSelectionModel();
model.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent event) {
ColorSelectionModel model = (ColorSelectionModel) event.getSource();
preview.setColor(model.getSelectedColor());
}
});
if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(null, colorChooser, "Select new color for " + itemEntity.getSeriesKey(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE))
renderer.setSeriesPaint(seriesIndex, colorChooser.getColor());
}
});
wotChartPanel.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (!wotChartPanel.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) wotChartPanel.getChart().getXYPlot()).getDomainAxis();
else
axis = ((XYPlot) wotChartPanel.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) {
}
});
}
use of org.jfree.chart.ChartPanel in project mafscaling by vimsh.
the class VVTCalc method clearChartData.
private void clearChartData() {
runData.clear();
XYSeriesCollection dataset;
for (ChartPanel chartPanel : chartPanels) {
XYPlot plot = chartPanel.getChart().getXYPlot();
dataset = (XYSeriesCollection) plot.getDataset(0);
dataset.removeAllSeries();
dataset = (XYSeriesCollection) plot.getDataset(1);
dataset.removeAllSeries();
}
DefaultMutableTreeNode root = (DefaultMutableTreeNode) pullTree.getModel().getRoot();
root.removeAllChildren();
((DefaultTreeModel) pullTree.getModel()).reload(root);
for (HashMap<String, XYSeries> series : hiddenSeries) series.clear();
vvt1RunSeries.clear();
vvt2RunSeries.clear();
veRunSeries.clear();
vvt1BestSeries.clear();
vvt2BestSeries.clear();
ve1BestSeries.clear();
ve2BestSeries.clear();
plot3d.removeAllPlots();
pullsComboBox.removeAllItems();
pullsComboBox.addItem("");
}
use of org.jfree.chart.ChartPanel in project crypto-bot by jnidzwetzki.
the class Chart method displayChart.
/**
* Displays a chart in a frame.
*
* @param chart
* the chart to be displayed
*/
private static void displayChart(JFreeChart chart) {
// Chart panel
ChartPanel panel = new ChartPanel(chart);
panel.setFillZoomRectangle(true);
panel.setMouseWheelEnabled(true);
panel.setPreferredSize(new Dimension(1024, 400));
// Application frame
ApplicationFrame frame = new ApplicationFrame("Ta4j example - Buy and sell signals to chart");
frame.setContentPane(panel);
frame.pack();
RefineryUtilities.centerFrameOnScreen(frame);
frame.setVisible(true);
}
Aggregations