Example usage for org.jfree.chart ChartPanel setMouseZoomable

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

Introduction

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

Prototype

public void setMouseZoomable(boolean flag, boolean fillRectangle) 

Source Link

Document

A convenience method that switches on mouse-based zooming.

Usage

From source file:de.codesourcery.eve.skills.ui.ChartTest.java

public static void main(String[] args) {

    TimeSeries s1 = new TimeSeries("L&G European Index Trust");
    s1.add(new Day(1, 2, 2001), 181.8);
    s1.add(new Month(3, 2001), 167.3);
    s1.add(new Month(4, 2001), 153.8);
    s1.add(new Month(5, 2001), 167.6);
    s1.add(new Month(6, 2001), 158.8);
    s1.add(new Month(7, 2001), 148.3);
    s1.add(new Month(8, 2001), 153.9);
    s1.add(new Month(9, 2001), 142.7);
    s1.add(new Month(10, 2001), 123.2);
    s1.add(new Month(11, 2001), 131.8);
    s1.add(new Month(12, 2001), 139.6);
    s1.add(new Month(1, 2002), 142.9);
    s1.add(new Month(2, 2002), 138.7);
    s1.add(new Month(3, 2002), 137.3);
    s1.add(new Month(4, 2002), 143.9);
    s1.add(new Month(5, 2002), 139.8);
    s1.add(new Month(6, 2002), 137.0);
    s1.add(new Month(7, 2002), 132.8);
    TimeSeries s2 = new TimeSeries("L&G UK Index Trust");
    s2.add(new Month(2, 2001), 129.6);
    s2.add(new Month(3, 2001), 123.2);
    s2.add(new Month(4, 2001), 117.2);
    s2.add(new Month(5, 2001), 124.1);
    s2.add(new Month(6, 2001), 122.6);
    s2.add(new Month(7, 2001), 119.2);
    s2.add(new Month(8, 2001), 116.5);
    s2.add(new Month(9, 2001), 112.7);
    s2.add(new Month(10, 2001), 101.5);
    s2.add(new Month(11, 2001), 106.1);
    s2.add(new Month(12, 2001), 110.3);
    s2.add(new Month(1, 2002), 111.7);
    s2.add(new Month(2, 2002), 111.0);
    s2.add(new Month(3, 2002), 109.6);
    s2.add(new Month(4, 2002), 113.2);
    s2.add(new Month(5, 2002), 111.6);
    s2.add(new Month(6, 2002), 108.8);
    s2.add(new Month(7, 2002), 101.6);

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);/*from  w  ww  .java 2  s.co m*/
    dataset.addSeries(s2);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    // display chart
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setMouseZoomable(true, false);

    JFrame frame = new JFrame("test");
    frame.setContentPane(chartPanel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

}

From source file:flow.visibility.FlowMain.java

public static void main(String[] args) throws Exception {

    /************************************************************** 
     * Creating the Main GUI // w w w .  j  a v a2 s. c o  m
     **************************************************************/

    final JDesktopPane desktop = new JDesktopPane();

    final JMenuBar mb = new JMenuBar();
    JMenu menu;

    /** Add File Menu to Open File and Save Result */

    menu = new JMenu("File");
    JMenuItem Open = new JMenuItem("Open");
    JMenuItem Save = new JMenuItem("Save");
    menu.add(Open);
    menu.add(Save);

    menu.addSeparator();
    JMenuItem Exit = new JMenuItem("Exit");
    menu.add(Exit);
    Exit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });

    mb.add(menu);

    /** Add Control Menu to Start and Stop Capture */

    menu = new JMenu("Control");
    JMenuItem Start = new JMenuItem("Start Capture");
    JMenuItem Stop = new JMenuItem("Stop Capture");
    menu.add(Start);
    Start.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FlowDumper.main(false);
        }
    });

    menu.add(Stop);
    Stop.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FlowDumper.main(true);
        }
    });

    mb.add(menu);

    /** Add Configuration Menu for Tapping and Display */

    menu = new JMenu("Configuration");
    JMenuItem Tapping = new JMenuItem("Tapping Configuration");
    JMenuItem Display = new JMenuItem("Display Configuration");
    menu.add(Tapping);
    Tapping.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FlowTapping.main(null);
        }
    });
    menu.add(Display);

    mb.add(menu);

    /** Add Detail Menu for NetGrok Visualization and JEthereal Inspection */

    menu = new JMenu("Flow Detail");
    JMenuItem FlowVisual = new JMenuItem("Flow Visualization");
    JMenuItem FlowInspect = new JMenuItem("Flow Inspections");
    menu.add(FlowVisual);
    FlowVisual.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            NetworkView.main(null);
        }
    });
    menu.add(FlowInspect);
    FlowInspect.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Ethereal.main(null);
        }
    });
    mb.add(menu);

    /** Add Help Menu for Software Information */
    menu = new JMenu("Help");
    JMenuItem About = new JMenuItem("About");
    menu.add(About);
    About.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "OF@TEIN Flow Visibility Tools @ 2015 by GIST",
                    "About the Software", JOptionPane.PLAIN_MESSAGE);
        }
    });
    mb.add(menu);

    /** Creating the main frame */
    JFrame frame = new JFrame("OF@TEIN Flow Visibility Tools");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(desktop);
    frame.setJMenuBar(mb);
    frame.setSize(1215, 720);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    /**Add Blank three (3) Internal Jframe*/

    /**Internal Frame from Flow Summary Chart*/
    JInternalFrame FlowStatistic = new JInternalFrame("Flow Statistic", true, true, true, true);
    FlowStatistic.setBounds(0, 0, 600, 330);
    ChartPanel chartPanel = new ChartPanel(createChart(null));
    chartPanel.setMouseZoomable(true, false);
    FlowStatistic.add(chartPanel);
    FlowStatistic.setVisible(true);
    desktop.add(FlowStatistic);

    /**Internal Frame from Flow Summary Text*/
    JInternalFrame FlowSummary = new JInternalFrame("Flow Summary", true, true, true, true);
    FlowSummary.setBounds(0, 331, 600, 329);
    JTextArea textArea = new JTextArea(50, 10);
    JScrollPane scrollPane = new JScrollPane(textArea);
    FlowSummary.add(scrollPane);
    FlowSummary.setVisible(true);
    desktop.add(FlowSummary);

    //JInternalFrame FlowInspection = new JInternalFrame("Flow Inspection", true, true, true, true);
    //FlowInspection.setBounds(601, 0, 600, 660);
    //JTextArea textArea2 = new JTextArea(50, 10);
    //JScrollPane scrollPane2 = new JScrollPane(textArea2);
    //FlowInspection.add(scrollPane2);
    //FlowInspection.setVisible(true);
    //desktop.add(FlowInspection);

    /**Internal Frame from Printing the Packet Sequence*/
    JInternalFrame FlowSequence = new JInternalFrame("Flow Sequence", true, true, true, true);
    FlowSequence.setBounds(601, 0, 600, 660);
    JTextArea textArea3 = new JTextArea(50, 10);
    JScrollPane scrollPane3 = new JScrollPane(textArea3);
    FlowSequence.add(scrollPane3);
    FlowSequence.setVisible(true);
    desktop.add(FlowSequence);

    /************************************************************** 
     * Update the Frame Regularly
     **************************************************************/

    /** Regularly update the Frame Content every 3 seconds */

    for (;;) {

        desktop.removeAll();
        desktop.add(FlowProcess.FlowStatistic());
        desktop.add(FlowProcess.FlowSummary());
        //desktop.add(FlowProcess.FlowInspection());
        desktop.add(FlowProcess.FlowSequence());
        desktop.revalidate();
        Thread.sleep(10000);

    }

}

From source file:org.kalypso.ogc.sensor.diagview.jfreechart.ChartFactory.java

/**
 * Create a ChartPanel over the given ObservationChart. The created panel has no popup menu.
 * <p>// ww  w  .  j av  a 2  s  .c om
 * Takes care of registering the ChartPanel within the ObservationChart so that the chart can refer to it once print is called for instance.
 */
public static ChartPanel createChartPanel(final ObservationChart obsChart) {
    final ChartPanel chartPanel = new ChartPanel(obsChart, false, false, false, false, false);
    chartPanel.setMouseZoomable(true, false);

    obsChart.setPanel(chartPanel);

    return chartPanel;
}

From source file:ch.zhaw.parallelComputing.view.Plotter.java

/**
 * Displays a plot of the given data sets as a dialog with a save as PNG option
 * @param parent component to set the dialog relative to
 * @param title the name of the Plot and the header of the dialog
 * @param dataset1 the first data set for plotting
 * @param dataset2 the second data set for plotting
 *///  w ww .  j a v a 2s . c om
public static void plotWithDialog(Component parent, String title, XYDataset dataset1, XYDataset dataset2) {
    JFreeChart chart = plot(title, dataset1, dataset2);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1024, 768));
    chartPanel.setMouseZoomable(true, false);

    String[] options = { "Print", "OK" };
    int response = JOptionPane.showOptionDialog(parent // Center in window.
            , chartPanel, title // Title in titlebar
            , JOptionPane.YES_NO_OPTION // Option type
            , JOptionPane.PLAIN_MESSAGE // messageType
            , null // Icon (none)
            , options // Button text as above.
            , "OK" // Default button
    );

    if (response == 0) {
        getPlotAsPNG(title, dataset1, dataset2);
    }
}

From source file:flow.visibility.pcap.FlowProcess.java

/** function to create internal frame contain flow summary chart */

public static JInternalFrame FlowStatistic() {

    final StringBuilder errbuf = new StringBuilder(); // For any error msgs  
    final String file = "tmp-capture-file.pcap";

    //System.out.printf("Opening file for reading: %s%n", file);  

    /*************************************************************************** 
     * Second we open up the selected file using openOffline call 
     **************************************************************************/
    Pcap pcap = Pcap.openOffline(file, errbuf);

    if (pcap == null) {
        System.err.printf("Error while opening device for capture: " + errbuf.toString());
    }//  ww  w  .  j  a v  a2s.  c o  m

    Pcap pcap1 = Pcap.openOffline(file, errbuf);
    FlowMap map = new FlowMap();
    pcap1.loop(Pcap.LOOP_INFINITE, map, null);

    //System.out.printf(map.toString());
    //System.out.printf(map.toString2());

    /** Splitting the packets statistics strings from FlowMap function */

    String packet = map.toString2();
    String[] NumberPacket = packet.split(",");

    final XYSeries Flow = new XYSeries("Flow");

    for (int i = 0; i < NumberPacket.length - 1; i = i + 1) {

        //System.out.printf(NumberPacket[i+1] + "\n");
        double NoPacket = Double.valueOf(NumberPacket[i + 1]);
        Flow.add(i, NoPacket);

    }

    /** Create dataset for chart */

    final XYSeriesCollection dataset = new XYSeriesCollection();

    dataset.addSeries(Flow);

    /** Create the internal frame contain flow summary chart */

    JInternalFrame FlowStatistic = new JInternalFrame("Flow Statistic", true, true, true, true);
    FlowStatistic.setBounds(0, 0, 600, 330);

    ChartPanel chartPanel = new ChartPanel(createChart(dataset));
    chartPanel.setMouseZoomable(true, false);

    FlowStatistic.add(chartPanel);
    FlowStatistic.setVisible(true);
    FlowStatistic.revalidate();
    pcap1.close();

    return FlowStatistic;

}

From source file:jyplot.XYErrorBar.ErrorBarDemo.java

private ChartPanel createChartPanel(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createScatterPlot("Error Bar Demo",
            // title
            "x",/*from   ww w .j  av a 2  s . c om*/
            // x-axis label
            "y",
            // y-axis label
            dataset,
            // data
            PlotOrientation.VERTICAL,
            // create legend?
            true,
            // generate tooltips?
            true, false
    // generate URLs?
    );
    XYErrorBarRenderer r = new XYErrorBarRenderer();
    chart.getXYPlot().setRenderer(r);
    r.addChangeListener(chart.getXYPlot());// see bug 1177884

    ChartPanel chartPanel = new ChartPanel(chart, false, false, false, false, false);
    chartPanel.setMouseZoomable(true, false);
    return chartPanel;
}

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

public TimeSeriesDemo14(String s) {
    super(s);//  ww w . j  av  a2s.  com
    XYDataset xydataset = createDataset();
    JFreeChart jfreechart = createChart(xydataset);
    ChartPanel chartpanel = new ChartPanel(jfreechart, false);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    chartpanel.setMouseZoomable(true, false);
    setContentPane(chartpanel);
}

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

public TimePeriodValuesDemo1(String s) {
    super(s);/*from  w  w w  . j a va 2  s  . c o  m*/
    XYDataset xydataset = createDataset1();
    XYBarRenderer xybarrenderer = new XYBarRenderer();
    DateAxis dateaxis = new DateAxis("Date");
    dateaxis.setVerticalTickLabels(true);
    dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1));
    dateaxis.setDateFormatOverride(new SimpleDateFormat("hh:mm"));
    dateaxis.setLowerMargin(0.01D);
    dateaxis.setUpperMargin(0.01D);
    NumberAxis numberaxis = new NumberAxis("Value");
    XYPlot xyplot = new XYPlot(xydataset, dateaxis, numberaxis, xybarrenderer);
    XYDataset xydataset1 = createDataset2();
    StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer(3);
    standardxyitemrenderer.setBaseShapesFilled(true);
    xyplot.setDataset(1, xydataset1);
    xyplot.setRenderer(1, standardxyitemrenderer);
    JFreeChart jfreechart = new JFreeChart("Supply and Demand", xyplot);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    chartpanel.setMouseZoomable(true, false);
    setContentPane(chartpanel);
}

From source file:tools.descartes.bungee.chart.ChartFrame.java

public ChartFrame(final String title, JFreeChart chart, int width, int height, boolean visible) {
    super(title);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    chartPanel.setMouseZoomable(true, false);
    setContentPane(chartPanel);/*  w ww  .  ja  va2s .co m*/

    pack();
    RefineryUtilities.centerFrameOnScreen(this);
    setVisible(visible);
}

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

public PeriodAxisDemo2(String s) {
    super(s);/*from  w  w  w. j  ava2 s .co  m*/
    XYDataset xydataset = createDataset();
    JFreeChart jfreechart = createChart(xydataset);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    chartpanel.setMouseZoomable(true, false);
    setContentPane(chartpanel);
}