Search in sources :

Example 46 with ChartPanel

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;
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) ChartPanel(org.jfree.chart.ChartPanel) XYAnnotation(org.jfree.chart.annotations.XYAnnotation) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) Range(org.jfree.data.Range) JFreeChart(org.jfree.chart.JFreeChart) NumberTickUnit(org.jfree.chart.axis.NumberTickUnit) XYTextAnnotation(org.jfree.chart.annotations.XYTextAnnotation) AxisSpace(org.jfree.chart.axis.AxisSpace)

Example 47 with ChartPanel

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;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) ChartPanel(org.jfree.chart.ChartPanel) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) AxisSpace(org.jfree.chart.axis.AxisSpace) Range(org.jfree.data.Range) JFreeChart(org.jfree.chart.JFreeChart) LogarithmicAxis(org.jfree.chart.axis.LogarithmicAxis) NumberTickUnit(org.jfree.chart.axis.NumberTickUnit)

Example 48 with ChartPanel

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);
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) ApplicationFrame(org.jfree.ui.ApplicationFrame) Dimension(java.awt.Dimension)

Example 49 with ChartPanel

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);
}
Also used : ChartPanel(org.jfree.chart.ChartPanel)

Example 50 with 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);
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) ChartPanel(org.jfree.chart.ChartPanel) GridBagLayout(java.awt.GridBagLayout) Crosshair(org.jfree.chart.plot.Crosshair) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) ChartMouseListener(org.jfree.chart.ChartMouseListener) XYItemEntity(org.jfree.chart.entity.XYItemEntity) JLabel(javax.swing.JLabel) CrosshairOverlay(org.jfree.chart.panel.CrosshairOverlay) XYDataset(org.jfree.data.xy.XYDataset) ChartEntity(org.jfree.chart.entity.ChartEntity) JPanel(javax.swing.JPanel)

Aggregations

ChartPanel (org.jfree.chart.ChartPanel)66 JFreeChart (org.jfree.chart.JFreeChart)42 XYPlot (org.jfree.chart.plot.XYPlot)19 Color (java.awt.Color)16 Dimension (java.awt.Dimension)16 NumberAxis (org.jfree.chart.axis.NumberAxis)16 JPanel (javax.swing.JPanel)15 XYSeries (org.jfree.data.xy.XYSeries)14 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)14 XYDataset (org.jfree.data.xy.XYDataset)12 BasicStroke (java.awt.BasicStroke)11 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)11 DecimalFormat (java.text.DecimalFormat)7 JButton (javax.swing.JButton)7 JLabel (javax.swing.JLabel)7 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)7 DefaultFormBuilder (com.jgoodies.forms.builder.DefaultFormBuilder)6 FormLayout (com.jgoodies.forms.layout.FormLayout)6 Font (java.awt.Font)6 GridBagLayout (java.awt.GridBagLayout)6