Example usage for org.jfree.chart ChartPanel setHorizontalAxisTrace

List of usage examples for org.jfree.chart ChartPanel setHorizontalAxisTrace

Introduction

In this page you can find the example usage for org.jfree.chart ChartPanel setHorizontalAxisTrace.

Prototype

public void setHorizontalAxisTrace(boolean flag) 

Source Link

Document

A flag that controls trace lines on the horizontal axis.

Usage

From source file:org.jfree.chart.demo.ScatterPlotDemo1.java

public static JPanel createDemoPanel() {
    JFreeChart jfreechart = createChart(new SampleXYDataset2());
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setVerticalAxisTrace(true);
    chartpanel.setHorizontalAxisTrace(true);
    chartpanel.setPopupMenu(null);//from  w  ww.j  a  v a 2  s. c  o  m
    chartpanel.setDomainZoomable(true);
    chartpanel.setRangeZoomable(true);
    return chartpanel;
}

From source file:org.jfree.chart.demo.ScatterPlotDemo.java

/**
 * A demonstration application showing a scatter plot.
 * /*  w ww  . j  av a2  s . c o  m*/
 * @param title
 *           the frame title.
 */
public ScatterPlotDemo(final String title) {

    super(title);
    final XYDataset data = new SampleXYDataset2();
    final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);
    final Legend legend = chart.getLegend();
    if (legend instanceof StandardLegend) {
        final StandardLegend sl = (StandardLegend) legend;
        sl.setDisplaySeriesShapes(true);
    }
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setVerticalAxisTrace(true);
    chartPanel.setHorizontalAxisTrace(true);
    chartPanel.setVerticalZoom(true);
    chartPanel.setHorizontalZoom(true);
    setContentPane(chartPanel);

}

From source file:org.jfree.chart.demo.ScatterPlotDemo2.java

/**
 * A demonstration application showing a scatter plot.
 *
 * @param title  the frame title.//from   w  w  w  .  ja va2 s  .  c  o m
 */
public ScatterPlotDemo2(final String title) {

    super(title);
    final XYDataset dataset = new SampleXYDataset2();
    final JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setVerticalAxisTrace(true);
    chartPanel.setHorizontalAxisTrace(true);
    //        chartPanel.setVerticalZoom(true);
    //      chartPanel.setHorizontalZoom(true);
    setContentPane(chartPanel);

}

From source file:analisisnumerico.Graficador.java

public Graficador(Funcion F, double lower, double upper) {
    //super("Graficador");
    JFrame f = new JFrame("Grafica");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setLayout(new BorderLayout(0, 5));

    XYDataset paresDeDatos = generarDatos(F, lower, upper);
    JFreeChart diagrama = crearDiagrama(paresDeDatos);
    ChartPanel chartPanel = new ChartPanel(diagrama);
    chartPanel.setPreferredSize(new Dimension(500, 400));
    //setContentPane(chartPanel);
    f.add(chartPanel, BorderLayout.CENTER);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setHorizontalAxisTrace(true);
    chartPanel.setVerticalAxisTrace(true);
    f.pack();//from   www .j  a va 2  s .co m
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:desmoj.extensions.grafic.util.Plotter.java

/**
  * Build a JPanel with plotType of a DesmoJ time-series dataset.
 * When allowMultipleValues is set, multiple range values of a time value are allowed.
 * In the opposite Case only the last range value of a time value is accepted.
 * In the case ts.getShowTimeSpansInReport() the data values are interpreted as
 * a timespan in a appropriate time unit. 
  * @param ts               DesmoJ time-series dataset
  * @param plotType          possible Values: 
  *                         Plotter.TimeSeries_ScatterPlot, 
  *                         Plotter.TimeSeries_StepChart
  *                         Plotter.TimeSeries_LinePlot
 * @param allowMultipleValues//  w w w .  ja  va2  s.c o m
 * @return
 */
private JPanel getTimeSeriesPanel(TimeSeries ts, int plotType, boolean allowMultipleValues) {
    JFreeChart chart;
    TimeSeriesDataSetAdapter dataset = new TimeSeriesDataSetAdapter(ts, allowMultipleValues);
    switch (plotType) {
    case Plotter.TimeSeries_LineChart:
        chart = ChartFactory.createXYLineChart(ts.getName(), "Time", "Observation", dataset,
                PlotOrientation.VERTICAL, false, false, false);
        break;
    case Plotter.TimeSeries_ScatterPlot:
        chart = ChartFactory.createScatterPlot(ts.getName(), "Time", "Observation", dataset,
                PlotOrientation.VERTICAL, false, false, false);
        break;
    case Plotter.TimeSeries_StepChart:
        chart = ChartFactory.createXYStepChart(ts.getName(), "Time", "Observation", dataset,
                PlotOrientation.VERTICAL, false, false, false);
        break;
    default:
        chart = ChartFactory.createScatterPlot(ts.getName(), "Time", "Observation", dataset,
                PlotOrientation.VERTICAL, false, false, false);
        break;
    }
    if (ts.getDescription() != null)
        chart.setTitle(ts.getDescription());

    XYPlot xyplot = (XYPlot) chart.getPlot();
    xyplot.setNoDataMessage("NO DATA");
    if (ts.getShowTimeSpansInReport() && !dataset.isValid())
        xyplot.setNoDataMessage("NO VALID TIMESPANS");
    xyplot.setDomainZeroBaselineVisible(false);
    xyplot.setRangeZeroBaselineVisible(false);

    DateAxis dateAxis = new DateAxis();
    xyplot.setDomainAxis(dateAxis);
    this.configureDomainAxis(dateAxis);

    String numberLabel;
    if (!dataset.isValid())
        numberLabel = "Unit: invalid";
    else if (ts.getShowTimeSpansInReport())
        numberLabel = "Unit: timespan [" + dataset.getRangeTimeUnit().name() + "]";
    else if (ts.getUnit() != null)
        numberLabel = "Unit: [" + ts.getUnit() + "]";
    else
        numberLabel = "Unit: unknown";
    NumberAxis numberAxis = new NumberAxis();
    xyplot.setRangeAxis(numberAxis);
    this.configureRangeAxis(numberAxis, numberLabel);

    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setSeriesOutlinePaint(0, Color.black);
    xylineandshaperenderer.setUseOutlinePaint(true);

    ChartPanel panel = new ChartPanel(chart);
    panel.setVerticalAxisTrace(false);
    panel.setHorizontalAxisTrace(false);
    panel.setPopupMenu(null);
    panel.setDomainZoomable(false);
    panel.setRangeZoomable(false);

    return panel;
}

From source file:org.jfree.chart.demo.JFreeChartDemo.java

/**
 * Handles menu selections by passing control to an appropriate method.
 *
 * @param event  the event./* w  w  w.  j  av a 2s.  c  o  m*/
 */
public void actionPerformed(final ActionEvent event) {

    final String command = event.getActionCommand();
    if (command.equals(EXIT_COMMAND)) {
        attemptExit();
    } else if (command.equals(ABOUT_COMMAND)) {
        about();
    } else {
        /// Loop through available commands to find index to current command.
        int chartnum = -1;
        int i = CHART_COMMANDS.length;
        while (i > 0) {
            --i;
            if (command.equals(CHART_COMMANDS[i][0])) {
                chartnum = i;
                i = 0;
            }
        }

        /// check our index is valid
        if ((chartnum >= 0) && (chartnum < this.frame.length)) {
            /// Check we have not already created chart.
            if (this.frame[chartnum] == null) {
                // setup the chart.
                DEMO.getChart(chartnum);

                // present it in a frame...
                String str = this.resources.getString(CHART_COMMANDS[chartnum][2] + ".title");
                this.frame[chartnum] = new ChartFrame(str, DEMO.getChart(chartnum));
                this.frame[chartnum].getChartPanel().setPreferredSize(new java.awt.Dimension(500, 270));
                this.frame[chartnum].pack();
                RefineryUtilities.positionFrameRandomly(this.frame[chartnum]);

                /// Set panel to zoomable if required
                try {
                    str = this.resources.getString(CHART_COMMANDS[chartnum][2] + ".zoom");
                    if ((str != null) && (str.toLowerCase().equals("true"))) {
                        final ChartPanel panel = this.frame[chartnum].getChartPanel();
                        panel.setMouseZoomable(true);
                        panel.setHorizontalAxisTrace(true);
                        panel.setVerticalAxisTrace(true);
                    }
                } catch (Exception ex) {
                    /// Filter out messages which for charts which do not have zoom
                    /// specified.
                    if (ex.getMessage().indexOf("MissingResourceException") == 0) {
                        ex.printStackTrace();
                    }
                }

                this.frame[chartnum].setVisible(true);

            } else {
                this.frame[chartnum].setVisible(true);
                this.frame[chartnum].requestFocus();
            }
        }
    }
}

From source file:org.trade.ui.chart.CandlestickChart.java

/**
 * A demonstration application showing a candlestick chart.
 * /*from w ww  .  j a v a2s.  c  o  m*/
 * @param title
 *            the frame title.
 * @param strategyData
 *            StrategyData
 */
public CandlestickChart(final String title, StrategyData strategyData, Tradingday tradingday) {

    this.strategyData = strategyData;
    this.setLayout(new BorderLayout());
    // Used to mark the current price
    stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 10, 3 }, 0);
    valueMarker = new ValueMarker(0.00, Color.black, stroke);

    this.chart = createChart(this.strategyData, title, tradingday);

    BlockContainer container = new BlockContainer(new BorderArrangement());
    container.add(titleLegend1, RectangleEdge.LEFT);
    container.add(titleLegend2, RectangleEdge.RIGHT);
    container.add(new EmptyBlock(2000, 0));
    CompositeTitle legends = new CompositeTitle(container);
    legends.setPosition(RectangleEdge.BOTTOM);
    this.chart.addSubtitle(legends);

    final ChartPanel chartPanel = new ChartPanel(this.chart);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseZoomable(true, true);
    chartPanel.setRefreshBuffer(true);
    chartPanel.setDoubleBuffered(true);
    chartPanel.setVerticalAxisTrace(true);
    chartPanel.setHorizontalAxisTrace(true);
    chartPanel.addChartMouseListener(new ChartMouseListener() {

        public void chartMouseMoved(ChartMouseEvent e) {
        }

        public void chartMouseClicked(final ChartMouseEvent e) {
            CombinedDomainXYPlot combinedXYplot = (CombinedDomainXYPlot) e.getChart().getPlot();
            @SuppressWarnings("unchecked")
            List<XYPlot> subplots = combinedXYplot.getSubplots();
            if (e.getTrigger().getClickCount() == 2) {
                double xItem = 0;
                double yItem = 0;
                if (e.getEntity() instanceof XYItemEntity) {
                    XYItemEntity xYItemEntity = ((XYItemEntity) e.getEntity());
                    xItem = xYItemEntity.getDataset().getXValue(xYItemEntity.getSeriesIndex(),
                            xYItemEntity.getItem());
                    yItem = xYItemEntity.getDataset().getYValue(xYItemEntity.getSeriesIndex(),
                            xYItemEntity.getItem());
                } else {
                    PlotEntity plotEntity = ((PlotEntity) e.getEntity());
                    XYPlot plot = (XYPlot) plotEntity.getPlot();
                    xItem = plot.getDomainCrosshairValue();
                    yItem = plot.getRangeCrosshairValue();
                }

                for (XYPlot xyplot : subplots) {

                    double x = xyplot.getDomainCrosshairValue();
                    double y = xyplot.getRangeCrosshairValue();

                    /*
                     * If the cross hair is from a right-hand y axis we need
                     * to convert this to a left-hand y axis.
                     */
                    String rightAxisName = ", Price: ";
                    double rangeLowerLeft = 0;
                    double rangeUpperLeft = 0;
                    double rangeLowerRight = 0;
                    double rangeUpperRight = 0;
                    double yRightLocation = 0;
                    for (int index = 0; index < xyplot.getRangeAxisCount(); index++) {
                        AxisLocation axisLocation = xyplot.getRangeAxisLocation(index);
                        Range range = xyplot.getRangeAxis(index).getRange();

                        if (axisLocation.equals(AxisLocation.BOTTOM_OR_LEFT)
                                || axisLocation.equals(AxisLocation.TOP_OR_LEFT)) {
                            rangeLowerLeft = range.getLowerBound();
                            rangeUpperLeft = range.getUpperBound();
                            rightAxisName = ", " + xyplot.getRangeAxis(index).getLabel() + ": ";
                        }
                        if (y >= range.getLowerBound() && y <= range.getUpperBound()
                                && (axisLocation.equals(AxisLocation.BOTTOM_OR_RIGHT)
                                        || axisLocation.equals(AxisLocation.TOP_OR_RIGHT))) {
                            rangeUpperRight = range.getUpperBound();
                            rangeLowerRight = range.getLowerBound();
                        }
                    }
                    if ((rangeUpperRight - rangeLowerRight) > 0) {
                        yRightLocation = rangeLowerLeft + ((rangeUpperLeft - rangeLowerLeft)
                                * ((y - rangeLowerRight) / (rangeUpperRight - rangeLowerRight)));
                    } else {
                        yRightLocation = y;
                    }

                    String text = " Time: " + dateFormatShort.format(new Date((long) (x))) + rightAxisName
                            + new Money(y);
                    if (x == xItem && y == yItem) {
                        titleLegend1.setText(text);
                        if (null == clickCrossHairs) {
                            clickCrossHairs = new XYTextAnnotation(text, x, yRightLocation);
                            clickCrossHairs.setTextAnchor(TextAnchor.BOTTOM_LEFT);
                            xyplot.addAnnotation(clickCrossHairs);
                        } else {
                            clickCrossHairs.setText(text);
                            clickCrossHairs.setX(x);
                            clickCrossHairs.setY(yRightLocation);
                        }
                    }
                }
            } else if (e.getTrigger().getClickCount() == 1 && null != clickCrossHairs) {
                for (XYPlot xyplot : subplots) {
                    if (xyplot.removeAnnotation(clickCrossHairs)) {
                        clickCrossHairs = null;
                        titleLegend1.setText(" Time: 0, Price :0.0");
                        break;
                    }
                }
            }
        }
    });
    this.add(chartPanel, null);
    this.strategyData.getCandleDataset().getSeries(0).addChangeListener(this);
}