use of org.jfree.chart.ChartPanel in project polyGembler by c-zhou.
the class HMMPanel method getChart.
public ChartPanel getChart() {
Range range = this.updateRates();
final JFreeChart chart = ChartFactory.createXYLineChart(null, // domain axis label
null, // range axis label
null, // data
rates, PlotOrientation.VERTICAL, // include legend
false, // tooltips?
true, // URL generator? Not required...
false);
final NumberAxis domainAxis = new NumberAxis("SNP relative physical position");
// final LogarithmicAxis rangeAxis = new LogarithmicAxis("Trans-out probability");
final NumberAxis rangeAxis = new NumberAxis("Trans-out probability");
AxisSpace space = new AxisSpace();
// reserved space on the left side of the plot
space.setRight(22);
space.setLeft(67);
chart.getXYPlot().setFixedRangeAxisSpace(space);
// double fixedDemension = HMMPanel.this.getX(0, false)+shift;
// rangeAxis.setFixedDimension(fixedDemension);
domainAxis.setTickUnit(new NumberTickUnit(1));
// rangeAxis.setLog10TickLabelsFlag(true);
rangeAxis.setRange(range);
domainAxis.setRange(new Range(1 - offset_yR, noSnps + offset_yR));
chart.getXYPlot().setDomainAxis(domainAxis);
chart.getXYPlot().setRangeAxis(rangeAxis);
final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
for (int i = 0; i < rates.getSeriesCount(); i++) {
Color c;
if (i == 0)
c = ca.getColor(i);
else
c = Color.lightGray;
renderer.setSeriesPaint(i, c);
if (i == 0)
renderer.setSeriesShapesVisible(i, true);
else
renderer.setSeriesShapesVisible(i, false);
}
/**
* XYPolygonAnnotation a = new XYPolygonAnnotation(new double[] {5.0,
* 0.0, 5.0, 0.5, 6.0, 0.5, 6.0, 0.0}, null, null,Color.black) {
* @Override
* public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
* Graphics2D g22 = (Graphics2D) g2.create();
* g22.setXORMode(new Color(0xff0000));
* super.draw(g22, plot, dataArea, domainAxis, rangeAxis, rendererIndex, info);
* }
* };
* renderer.addAnnotation(a, Layer.BACKGROUND);
*/
chart.getXYPlot().setRenderer(renderer);
double anno_offset_x = 0.5;
XYSeries d = rates.getSeries(0);
for (int i = 0; i < d.getItemCount(); i++) {
double x = d.getX(i).doubleValue();
double y = d.getY(i).doubleValue();
if (y > 0.1)
chart.getXYPlot().addAnnotation((XYAnnotation) new XYTextAnnotation(String.format(formatStr2, y), x > noSnps / 2 ? (x - anno_offset_x) : (x + anno_offset_x), y));
else
chart.getXYPlot().addAnnotation((XYAnnotation) new XYTextAnnotation(String.format(formatStr, y), x, y + .05));
}
// chart.getXYPlot().getRangeAxis().get
// chart.getXYPlot().setRangeAxis(new LogarithmicAxis("rates"));
final ChartPanel cp = new ChartPanel(chart, // width
this.getWidth(), // height
150, // mindrawWidth
this.getWidth(), // mindrawHeight
150, // maxDrawWith
this.getWidth(), // maxDrawHeight
150, ChartPanel.DEFAULT_BUFFER_USED, // properties
true, // save
true, // print
true, // zoom
true, // tooltips
true);
{
Range r = chart.getXYPlot().getDomainAxis().getRange();
chart.getXYPlot().getDomainAxis().setAutoRange(false);
chart.getXYPlot().getDomainAxis().setRange(1, r.getUpperBound());
}
{
Range r = chart.getXYPlot().getRangeAxis().getRange();
if (r.getLowerBound() < range.getUpperBound()) {
chart.getXYPlot().getRangeAxis().setAutoRange(false);
chart.getXYPlot().getRangeAxis().setRange(r.getLowerBound(), range.getUpperBound());
}
}
chart.setBackgroundPaint(Color.WHITE);
chart.setBorderPaint(Color.WHITE);
cp.setBorder(null);
/**
* RectangleEdge edge = chart.getXYPlot().getDomainAxisEdge();
* Rectangle2D edge2 = cp.getScreenDataArea();
* double x = RectangleEdge.coordinate(edge2, edge);
* ValueAxis edge3 = chart.getXYPlot().getDomainAxisForDataset(0);
* double xx = domainAxis.valueToJava2D(3, edge2, edge);
*/
return cp;
}
use of org.jfree.chart.ChartPanel in project polyGembler by c-zhou.
the class HMMSplitPanel method getChart.
public ChartPanel getChart() {
Range range = this.updateRates();
final JFreeChart chart = ChartFactory.createXYLineChart(null, // domain axis label
null, // range axis label
null, // data
rates, PlotOrientation.VERTICAL, // include legend
false, // tooltips?
true, // URL generator? Not required...
false);
final NumberAxis domainAxis = new NumberAxis("Relative position");
final LogarithmicAxis rangeAxis = new LogarithmicAxis("Trans-out probability");
AxisSpace space = new AxisSpace();
// reserved space on the left side of the plot
space.setRight(115);
space.setLeft(65);
chart.getXYPlot().setFixedRangeAxisSpace(space);
// double fixedDemension = HMMPanel.this.getX(0, false)-10;
// rangeAxis.setFixedDimension(fixedDemension);
domainAxis.setTickUnit(new NumberTickUnit(1));
rangeAxis.setLog10TickLabelsFlag(true);
rangeAxis.setRange(range);
chart.getXYPlot().setDomainAxis(domainAxis);
chart.getXYPlot().setRangeAxis(rangeAxis);
final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
for (int i = 0; i < rates.getSeriesCount(); i++) {
Color c = ca.getColor(i);
renderer.setSeriesPaint(i, c);
renderer.setSeriesShapesVisible(i, true);
}
chart.getXYPlot().setRenderer(renderer);
// chart.getXYPlot().getRangeAxis().get
// chart.getXYPlot().setRangeAxis(new LogarithmicAxis("rates"));
final ChartPanel cp = new ChartPanel(chart, // width
this.getWidth(), // height
200, // mindrawWidth
this.getWidth(), // mindrawHeight
100, // maxDrawWith
this.getWidth(), // maxDrawHeight
400, ChartPanel.DEFAULT_BUFFER_USED, // properties
true, // save
true, // print
true, // zoom
true, // tooltips
true);
{
Range r = chart.getXYPlot().getDomainAxis().getRange();
chart.getXYPlot().getDomainAxis().setAutoRange(false);
chart.getXYPlot().getDomainAxis().setRange(1, r.getUpperBound());
}
{
Range r = chart.getXYPlot().getRangeAxis().getRange();
if (r.getLowerBound() < range.getUpperBound()) {
chart.getXYPlot().getRangeAxis().setAutoRange(false);
chart.getXYPlot().getRangeAxis().setRange(r.getLowerBound(), range.getUpperBound());
}
}
chart.setBackgroundPaint(Color.WHITE);
chart.setBorderPaint(Color.WHITE);
cp.setBorder(null);
return cp;
}
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);
}
use of org.jfree.chart.ChartPanel in project watchdog by TestRoots.
the class WatchDogView method createChartPanel.
private void createChartPanel(JComponent parent, JFreeChart chart) {
ChartPanel chartPanel = new ChartPanel(chart);
parent.add(chartPanel);
}
use of org.jfree.chart.ChartPanel in project Course_Generator by patrovite.
the class JPanelAnalysisSpeed method initComponents.
private void initComponents() {
setLayout(new java.awt.BorderLayout());
// //-- Left - Toolbar
// Create_Toolbar();
// add(toolBar, java.awt.BorderLayout.WEST);
//
// -- Bottom - Info
jPanelSpeedInfo = new javax.swing.JPanel();
jPanelSpeedInfo.setOpaque(true);
jPanelSpeedInfo.setBackground(Color.WHITE);
jPanelSpeedInfo.setLayout(new GridBagLayout());
add(jPanelSpeedInfo, java.awt.BorderLayout.SOUTH);
// -- Start speed/End speed/Speed/Distance
// -- Start speed
lbSpeedInfoStartSpeed = new javax.swing.JLabel();
lbSpeedInfoStartSpeed.setOpaque(true);
lbSpeedInfoStartSpeed.setBackground(Color.WHITE);
lbSpeedInfoStartSpeed.setText(" " + bundle.getString("JPanelAnalysisSpeed.lbSpeedInfoStartSpeed.text") + "=0km/h ");
lbSpeedInfoStartSpeed.setBorder(javax.swing.BorderFactory.createEtchedBorder());
Utils.addComponent(jPanelSpeedInfo, lbSpeedInfoStartSpeed, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
// -- End speed
lbSpeedInfoEndSpeed = new javax.swing.JLabel();
lbSpeedInfoEndSpeed.setOpaque(true);
lbSpeedInfoEndSpeed.setBackground(Color.WHITE);
lbSpeedInfoEndSpeed.setText(" " + bundle.getString("JPanelAnalysisSpeed.lbSpeedInfoEndSpeed.text") + "=0km/h ");
lbSpeedInfoEndSpeed.setBorder(javax.swing.BorderFactory.createEtchedBorder());
Utils.addComponent(jPanelSpeedInfo, lbSpeedInfoEndSpeed, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
// -- Speed
lbSpeedInfoSpeed = new javax.swing.JLabel();
lbSpeedInfoSpeed.setOpaque(true);
lbSpeedInfoSpeed.setBackground(Color.WHITE);
lbSpeedInfoSpeed.setText(" " + bundle.getString("JPanelAnalysisSpeed.lbSpeedInfoSpeed.text") + "=0km/h ");
lbSpeedInfoSpeed.setBorder(javax.swing.BorderFactory.createEtchedBorder());
Utils.addComponent(jPanelSpeedInfo, lbSpeedInfoSpeed, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH);
// -- Distance
lbSpeedInfoDistance = new javax.swing.JLabel();
lbSpeedInfoDistance.setOpaque(true);
lbSpeedInfoDistance.setBackground(Color.WHITE);
lbSpeedInfoDistance.setText(" " + bundle.getString("JPanelAnalysisSpeed.lbSpeedInfoDistance.text") + "=0.000km ");
lbSpeedInfoDistance.setBorder(javax.swing.BorderFactory.createEtchedBorder());
Utils.addComponent(jPanelSpeedInfo, lbSpeedInfoDistance, 3, 0, 1, 1, 1, 0, 0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL);
// -- Chart Speed/Dist & Time/Dist
ChartPanelSpeed = new ChartPanel(chart, true, /* Properties */
true, /* save */
true, /* print */
false, /* zoom */
true);
ChartPanelSpeed.setDomainZoomable(false);
ChartPanelSpeed.setRangeZoomable(false);
CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
xCrosshair = new Crosshair(Double.NaN, Color.RED, new BasicStroke(0f));
xCrosshair.setLabelBackgroundPaint(Color.WHITE);
crosshairOverlay.addDomainCrosshair(xCrosshair);
ChartPanelSpeed.addOverlay(crosshairOverlay);
ChartPanelSpeed.setBackground(new java.awt.Color(255, 0, 51));
ChartPanelSpeed.addChartMouseListener(new ChartMouseListener() {
@Override
public void chartMouseClicked(ChartMouseEvent event) {
ChartEntity chartentity = event.getEntity();
if (chartentity instanceof XYItemEntity) {
XYItemEntity e = (XYItemEntity) chartentity;
XYDataset d = e.getDataset();
int s = e.getSeriesIndex();
int i = e.getItem();
double x = d.getXValue(s, i);
xCrosshair.setValue(x);
RefreshInfo(i);
}
}
@Override
public void chartMouseMoved(ChartMouseEvent event) {
}
});
add(ChartPanelSpeed, java.awt.BorderLayout.CENTER);
}
Aggregations