Example usage for org.jfree.data.xy XYSeriesCollection XYSeriesCollection

List of usage examples for org.jfree.data.xy XYSeriesCollection XYSeriesCollection

Introduction

In this page you can find the example usage for org.jfree.data.xy XYSeriesCollection XYSeriesCollection.

Prototype

public XYSeriesCollection(XYSeries series) 

Source Link

Document

Constructs a dataset and populates it with a single series.

Usage

From source file:slash.navigation.converter.gui.elevationview.ElevationView.java

private XYSeriesCollection createDataset(PositionsModel model) {
    PatchedXYSeries series = new PatchedXYSeries("Elevation");
    new ElevationModel(model, series);
    return new XYSeriesCollection(series);
}

From source file:user.Query.java

private XYSeriesCollection getXYSeries(ResultSet resultSet, String value, String second_Value) {
    XYSeries series = new XYSeries("Tweets");
    try {/*from ww  w .  j av a 2  s  .  c o m*/
        while (resultSet.next()) {
            series.add(Double.parseDouble(resultSet.getString(second_Value)),
                    Double.parseDouble(resultSet.getString(value)));
        }
    } catch (SQLException ex) {
    }
    XYSeriesCollection data = new XYSeriesCollection(series);
    return data;
}

From source file:c.depthchart.ViewerPanel.java

private void initChart()
// create the dataset, chart, panel, and window
{
    // create an empty data set
    series = new XYSeries("Depth Counts Histogram");
    for (int i = 0; i <= CHART_MAX_DEPTH; i++)
        series.add(i, 0); // depth with a zero count
    XYSeriesCollection dataset = new XYSeriesCollection(series);

    // put the data into a chart
    JFreeChart chart = ChartFactory.createXYBarChart("Depth Histogram", "Depth (mm)", false, "Depth Count",
            dataset, PlotOrientation.VERTICAL, false, true, false); // legend, tooltips, urls

    // modify the chart axes
    XYPlot plot = (XYPlot) chart.getPlot();

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); // x-axis
    domainAxis.setVerticalTickLabels(true);
    domainAxis.setRange(0, CHART_MAX_DEPTH);
    domainAxis.setTickUnit(new NumberTickUnit(100));

    ValueAxis rangeAxis = plot.getRangeAxis(); // y-axis
    rangeAxis.setRange(0, 15000); // a bit of a guess

    // add the chart to a panel
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(1000, 500));

    // add the panel to a window
    JFrame chartFrame = new JFrame("Depth Histogram");
    chartFrame.setContentPane(chartPanel);
    chartFrame.pack();/* w  ww .  jav a 2s .  c  o m*/
    chartFrame.setVisible(true);
}

From source file:DynamiskDemo2.java

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title.//from  ww  w.j a  va  2 s  .  co m
 */
public DynamiskDemo2(final String title) {

    super(title);
    this.series = new XYSeries(title, false, false);
    final XYSeriesCollection dataset = new XYSeriesCollection(this.series);
    final JFreeChart chart = createChart(dataset);

    final ChartPanel chartPanel = new ChartPanel(chart);
    final JButton button = new JButton("Add New Data Item");
    button.setActionCommand("ADD_DATA");
    button.addActionListener(this);

    final JPanel content = new JPanel(new BorderLayout());
    content.add(chartPanel);
    content.add(button, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(content);
    String fil = "C:" + File.separator + "Users" + File.separator + "madso" + File.separator + "Documents"
            + File.separator + "!Privat" + File.separator + "DTU 2016-2020" + File.separator + "MATLAB";
    String filnavn = "EKGdata";
    try {
        Scanner sc = new Scanner(new FileReader(fil + File.separator + filnavn));

        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                if (sc.hasNext()) {
                    final double newItem = Double.parseDouble(sc.next());
                    series.add(x, newItem);
                    x += 10;
                }
            }

        }, 100, 2);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

/**
 * A demonstration application showing an XY plot, with a cyclic axis and renderer
 *
 * @param title  the frame title.// w ww.j  a  v  a  2 s .c om
 */
public CyclicXYPlotDemo(final String title) {

    super(title);

    this.series = new XYSeries("Random Data");
    this.series.setMaximumItemCount(50); // Only 50 items are visible at the same time. 
                                         // Keep more as a mean to test this.
    final XYSeriesCollection data = new XYSeriesCollection(this.series);

    final JFreeChart chart = ChartFactory.createXYLineChart("Cyclic XY Plot Demo", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);

    final XYPlot plot = chart.getXYPlot();
    plot.setDomainAxis(new CyclicNumberAxis(10, 0));
    plot.setRenderer(new CyclicXYItemRenderer());

    final NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(false);
    axis.setAutoRangeMinimumSize(1.0);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(400, 300));
    final JPanel content = new JPanel(new BorderLayout());
    content.add(chartPanel, BorderLayout.CENTER);

    final JButton button1 = new JButton("Start");
    button1.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            timer.start();
        }
    });

    final JButton button2 = new JButton("Stop");
    button2.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            timer.stop();
        }
    });

    final JButton button3 = new JButton("Step by step");
    button3.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            CyclicXYPlotDemo.this.actionPerformed(null);
        }
    });

    final JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(button1);
    buttonPanel.add(button2);
    buttonPanel.add(button3);

    content.add(buttonPanel, BorderLayout.SOUTH);
    setContentPane(content);

    this.timer = new Timer(200, this);
}

From source file:fr.crnan.videso3d.trajectography.Track2DView.java

public Track2DView(VidesoTrack track) {
    if (track instanceof LPLNTrack) {
        XYSeries dataset = new XYSeries(track.getName());
        List<ValueMarker> markers = new LinkedList<ValueMarker>();
        double distance = 0;
        LPLNTrackPoint last = null;//  w w w  . j  av a2  s  . c o  m
        for (LPLNTrackPoint p : ((LPLNTrack) track).getTrackPoints()) {
            if (last != null) {
                distance += Position.ellipsoidalDistance(last.getPosition(), p.getPosition(),
                        Earth.WGS84_EQUATORIAL_RADIUS, Earth.WGS84_POLAR_RADIUS) / LatLonCautra.NM;
            }
            dataset.add(distance, p.getElevation() / 30.48);
            ValueMarker marker = new ValueMarker(distance);
            marker.setLabel(p.getName());
            marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
            marker.setLabelTextAnchor(TextAnchor.TOP_CENTER);
            markers.add(marker);
            last = p;
        }
        JFreeChart chart = ChartFactory.createXYLineChart("Coupe 2D", "NM", "FL",
                new XYSeriesCollection(dataset), PlotOrientation.VERTICAL, false, false, false);
        for (ValueMarker m : markers) {
            chart.getXYPlot().addDomainMarker(m);
        }
        //ajout des secteurs AIP avec des XYPolygonAnnotation
        Collection<Object> secteurs;
        AIPController controller = (AIPController) DatasManager.getController(DatasManager.Type.AIP);
        secteurs = controller.getObjects(AIP.CTL);
        for (int i = 0; i <= 600; i += 10) {
            last = null;
            Secteur3D lastSecteur = null;
            double lastBoundary = 0.0;
            for (LPLNTrackPoint point : ((LPLNTrack) track).getTrackPoints()) {
                Position p = new Position(point.getPosition(), i * 30.48);
                //calcul du secteur contenant le point en cours
                Iterator<Object> iterator = secteurs.iterator();
                boolean contain = false;
                Secteur3D secteur = null;
                while (iterator.hasNext() && !contain) {
                    Secteur3D temp = (Secteur3D) iterator.next();
                    if (temp.contains(p)) {
                        contain = true;
                        secteur = temp;
                    }
                }

                //si premier point, on enregistre simplement le secteur trouv
                if (last == null) {
                    lastSecteur = secteur;
                } else {
                    if (lastSecteur != secteur) {
                        //si le secteur a chang, on dessine le secteur prcdent
                        //sauf si ce dernier n'existait pas
                        if (lastSecteur != null) {
                            //dans ce cas, on calcule le point d'intersection entre le secteur et le segment form par les deux points
                            //lastSecteur != null => last !=null
                            Set<Point2D> intersects = lastSecteur
                                    .getIntersections(new Line2D.Double(last.getLatitude(), last.getLongitude(),
                                            p.getLatitude().degrees, p.getLongitude().degrees), true);
                            if (!intersects.isEmpty()) {
                                Point2D intersect = intersects.iterator().next();
                                distance = Position.ellipsoidalDistance(
                                        new LatLonCautra(intersect.getX(), intersect.getY()),
                                        last.getPosition(), Earth.WGS84_EQUATORIAL_RADIUS,
                                        Earth.WGS84_POLAR_RADIUS) / LatLonCautra.NM;
                                //et ajout de l'annotation
                                XYPolygonAnnotation annotation = new XYPolygonAnnotation(
                                        new double[] { lastBoundary, i, lastBoundary + distance, i,
                                                lastBoundary + distance, i + 10, lastBoundary, i + 10 });
                                chart.getXYPlot().addAnnotation(annotation);
                                lastBoundary += distance;
                            }
                        }
                        lastSecteur = secteur;
                    }
                }
                last = point;
            }
        }
        //espace en haut pour les marqueurs
        chart.getXYPlot().getRangeAxis().setUpperMargin(0.05);
        ChartPanel chartPanel = new ChartPanel(chart);
        this.setContentPane(chartPanel);
        this.pack();
    }
}

From source file:intelligentWebAlgorithms.util.gui.XyGui.java

public XyGui(String title, double[] x, double[] y) {

    super(title);

    errMsg = new StringBuilder();
    setLoopInt(x.length);//  w w  w  .j a  va 2s . co m

    if (checkX(x) && checkY(x.length, y)) {

        XYSeries xydata = new XYSeries(title);

        for (int i = 0; i < loopInt; i++) {
            xydata.add(x[i], y[i]);
        }

        XYSeriesCollection xycollection = new XYSeriesCollection(xydata);

        final JFreeChart chart = ChartFactory.createXYLineChart(title + " (XY Plot)", "X", "Y", xycollection,
                PlotOrientation.VERTICAL, true, true, false);

        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);
    } else {
        System.err.println(errMsg.toString());
    }
}

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

/**
 * Creates a sample dataset.//w ww. j a  v  a2s.c  o  m
 * 
 * @return A sample dataset.
 */
private IntervalXYDataset createDataset() {
    final XYSeries series = new XYSeries("Random Data");
    series.add(1.0, 400.2);
    series.add(5.0, 294.1);
    series.add(4.0, 100.0);
    series.add(12.5, 734.4);
    series.add(17.3, 453.2);
    series.add(21.2, 500.2);
    series.add(21.9, null);
    series.add(25.6, 734.4);
    series.add(30.0, 453.2);
    final XYSeriesCollection dataset = new XYSeriesCollection(series);
    return dataset;
}

From source file:intelligentWebAlgorithms.util.gui.ScatterGui.java

public ScatterGui(String title, double[] x, double[] y) {

    super(title);

    errMsg = new StringBuilder();
    setLoopInt(x.length);//from w w w.jav a  2  s  . co  m

    if (checkX(x) && checkY(x.length, y)) {

        XYSeries xydata = new XYSeries(title);

        for (int i = 0; i < loopInt; i++) {
            xydata.add(x[i], y[i]);
        }

        XYSeriesCollection xycollection = new XYSeriesCollection(xydata);

        final JFreeChart chart = ChartFactory.createScatterPlot(title + " (Scatter Plot)", "X", "Y",
                xycollection, PlotOrientation.VERTICAL, true, true, false);

        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    } else {
        System.err.println(errMsg.toString());
    }
}

From source file:slash.navigation.converter.gui.profileview.ProfileView.java

public void initialize(PositionsModel positionsModel, final PositionsSelectionModel positionsSelectionModel,
        final UnitSystemModel unitSystemModel, final ProfileModeModel profileModeModel) {
    this.positionsModel = positionsModel;
    PatchedXYSeries series = new PatchedXYSeries("Profile");
    this.profileModel = new ProfileModel(positionsModel, series, unitSystemModel.getUnitSystem(),
            profileModeModel.getProfileMode());
    XYSeriesCollection dataset = new XYSeriesCollection(series);

    unitSystemModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            setUnitSystem(unitSystemModel.getUnitSystem());
        }//from  w ww .  ja  va2  s .c o m
    });
    profileModeModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            setProfileMode(profileModeModel.getProfileMode());
        }
    });

    JFreeChart chart = createChart(dataset);
    plot = createPlot(chart);

    ActionManager actionManager = Application.getInstance().getContext().getActionManager();
    for (ProfileMode mode : ProfileMode.values())
        actionManager.register("show-" + mode.name().toLowerCase(),
                new ToggleProfileModeAction(profileModeModel, mode));
    // since JFreeChart is not very nice to extensions - constructors calling protected methods... ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD
    LazyToolTipChartPanel.profileModeModel = profileModeModel;
    chartPanel = new LazyToolTipChartPanel(chart, false, true, true, true, true);
    chartPanel.addChartMouseListener(new ChartMouseListener() {
        public void chartMouseClicked(ChartMouseEvent e) {
            ChartEntity entity = e.getEntity();
            if (!(entity instanceof XYItemEntity))
                return;
            int row = ((XYItemEntity) entity).getItem();
            positionsSelectionModel.setSelectedPositions(new int[] { row }, true);
        }

        public void chartMouseMoved(ChartMouseEvent e) {
        }
    });
    chartPanel.setMouseWheelEnabled(true);

    updateAxis();
}