Example usage for org.jfree.chart JFreeChart getXYPlot

List of usage examples for org.jfree.chart JFreeChart getXYPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getXYPlot.

Prototype

public XYPlot getXYPlot() 

Source Link

Document

Returns the plot cast as an XYPlot .

Usage

From source file:playground.dgrether.events.handlers.DgGeoFilteredLegHistogram.java

private JFreeChart getGraphic(final ModeData modeData, final String modeName) {
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries departuresSerie = new XYSeries("departures", false, true);
    final XYSeries arrivalsSerie = new XYSeries("arrivals", false, true);
    final XYSeries onRouteSerie = new XYSeries("en route", false, true);
    int onRoute = 0;
    for (int i = 0; i < modeData.countsDep.length; i++) {
        onRoute = onRoute + modeData.countsDep[i] - modeData.countsArr[i] - modeData.countsStuck[i];
        double hour = i * this.binSizeSeconds / 60.0 / 60.0;
        departuresSerie.add(hour, modeData.countsDep[i]);
        arrivalsSerie.add(hour, modeData.countsArr[i]);
        onRouteSerie.add(hour, onRoute);
    }/*from w w w. jav  a  2 s  .c o  m*/

    xyData.addSeries(departuresSerie);
    xyData.addSeries(arrivalsSerie);
    xyData.addSeries(onRouteSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart(
            "Leg Histogram, " + modeName + ", it." + this.iteration, "time", "# vehicles", xyData,
            PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}

From source file:com.intel.stl.ui.common.view.ChartsView.java

public JFreeChart getSparkline(String name) {
    if (charts == null) {
        return null;
    }// ww  w  .  j ava 2s  . com

    JFreeChart chart = getChartWrap(name).chart;
    if (chart == null) {
        return null;
    }

    XYPlot plot = chart.getXYPlot();
    if (plot == null) {
        return null;
    }

    XYDataset dataset = plot.getDataset();
    return ComponentFactory.createXYAreaSparkline(dataset);
}

From source file:eu.stratosphere.addons.visualization.swt.SWTInstanceToolTip.java

private ChartComposite createCPUChart(InstanceVisualizationData instanceVisualizationData,
        Color backgroundColor) {/*from   ww  w  .j  a  va2s.  co  m*/

    final JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, "Time [sec.]", "CPU",
            instanceVisualizationData.getCpuDataSet(), PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(),
            backgroundColor.getBlue()));

    // Set axis properly
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.getDomainAxis().setAutoRange(true);
    xyPlot.getDomainAxis().setAutoRangeMinimumSize(60);

    xyPlot.getRangeAxis().setAutoRange(false);
    xyPlot.getRangeAxis().setRange(0, 100);

    return new ChartComposite(getShell(), SWT.NONE, chart, true);
}

From source file:org.cytoscape.dyn.internal.graphMetrics.GenerateChart.java

public JFreeChart generateTimeSeries() {

    dataset = new XYSeriesCollection();
    XYSeries[] attributeSeries = new XYSeries[(selectedNodes.size() + selectedEdges.size())
            * (checkedAttributes.size() + edgeCheckedAttributes.size())];
    int j = 0;/*from w  w w  .  j  a  v a 2  s  .c om*/
    /*creating dataseries for each node and its checked attribute and
    adding it to the dataset*/
    for (CyNode node : selectedNodes) {
        // System.out.println(checkedAttributes.size());
        for (int i = 0; i < checkedAttributes.size(); i++) {
            attributeSeries[j] = new XYSeries(dynamicNetwork.getNodeLabel(node) + checkedAttributes.get(i),
                    false, true);
            // System.out.println(dynamicNetwork.getDynAttribute(node,
            // checkedAttributes.get(i)).getKey().getColumn());

            for (DynInterval<T> interval : dynamicNetwork.getDynAttribute(node, checkedAttributes.get(i))
                    .getIntervalList()) {
                // System.out.println(interval.getOnValue());
                double value;
                if (interval.getOnValue() instanceof Double)
                    value = (Double) interval.getOnValue();
                else
                    value = ((Integer) interval.getOnValue()).doubleValue();
                // System.out.println(value);
                attributeSeries[j].add(interval.getStart(), value);
                attributeSeries[j].add(interval.getEnd(), value);
                //System.out.println("interval start ="+interval.getStart());
                //System.out.println("interval end ="+interval.getEnd());
                //System.out.println("--------");
            }
            dataset.addSeries(attributeSeries[j++]);
        }
    }
    /*creating dataseries for each edge and its checked attribute and
    adding it to the dataset*/
    for (CyEdge edge : selectedEdges) {
        // System.out.println(checkedAttributes.size());
        for (int i = 0; i < edgeCheckedAttributes.size(); i++) {
            attributeSeries[j] = new XYSeries(dynamicNetwork.getEdgeLabel(edge) + edgeCheckedAttributes.get(i),
                    false, true);
            // System.out.println(dynamicNetwork.getDynAttribute(node,
            // checkedAttributes.get(i)).getKey().getColumn());

            for (DynInterval<T> interval : dynamicNetwork.getDynAttribute(edge, edgeCheckedAttributes.get(i))
                    .getIntervalList()) {
                // System.out.println(interval.getOnValue());
                double value;
                if (interval.getOnValue() instanceof Double)
                    value = (Double) interval.getOnValue();
                else if (interval.getOnValue() instanceof Integer)
                    value = ((Integer) interval.getOnValue()).doubleValue();
                else if (interval.getOnValue() instanceof Short)
                    value = ((Short) interval.getOnValue()).doubleValue();
                else
                    value = ((Long) interval.getOnValue()).doubleValue();
                // System.out.println(value);
                attributeSeries[j].add(interval.getStart(), value);
                attributeSeries[j].add(interval.getEnd(), value);

            }
            dataset.addSeries(attributeSeries[j++]);
        }
    }

    String title = "Dynamic Graph Metrics";
    String xAxisLabel = "Time";
    String yAxisLabel = "Centrality Value";
    JFreeChart chart = ChartFactory.createXYStepChart(title, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, true, // legend
            true, // tooltips
            false // urls
    );

    NumberAxis xaxis = new NumberAxis();
    xaxis.setAutoRangeMinimumSize(1.0);
    xaxis.setLabel("Time");
    chart.getXYPlot().setDomainAxis(xaxis);
    NumberAxis yaxis = new NumberAxis();
    yaxis.setAutoRangeIncludesZero(true);
    yaxis.setLabel("Centrality/Attribute Value");
    chart.getXYPlot().setRangeAxis(yaxis);
    chart.setBackgroundPaint(Color.white);
    //chart.setPadding(new RectangleInsets(20,20,20,20));
    chart.getXYPlot().setBackgroundPaint(Color.white);
    chart.getXYPlot().setDomainGridlinePaint(Color.gray);
    chart.getXYPlot().setRangeGridlinePaint(Color.gray);
    return chart;
}

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

/**
 * Creates a chart./*from  w  w w  .  j a  v  a2  s  .c  o m*/
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart based on the supplied dataset.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart Demo 3", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPlotShapes(true);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}

From source file:org.squale.squaleweb.util.graph.ScatterMaker.java

/**
 * Construit (ou reconstruit) le diagramme puis le retourne
 * //from w w  w .  j av a2  s  . c  o m
 * @return le diagramme JFreeChart.
 */
protected JFreeChart getChart() {
    LOG.debug(WebMessages.getString("method.entry"));
    JFreeChart retChart = super.getChart();
    if (null == retChart) {
        // Gnration du Scatterplot
        retChart = ChartFactory.createScatterPlot(mTitle, mXLabel, mYLabel, mDataSet, PlotOrientation.VERTICAL,
                mShowLegend, false, false);
        ValueAxis domainAxis = retChart.getXYPlot().getDomainAxis();
        ValueAxis rangeAxis = retChart.getXYPlot().getRangeAxis();

        // Dtermination des bornes en abscisse et en ordonne
        double maxDomain = Math.max(domainAxis.getUpperBound(),
                DEFAULT_VERTICAL_AXIS_POS + DEFAULT_AXIS_MARGIN);
        double minDomain = Math.min(domainAxis.getLowerBound(),
                DEFAULT_VERTICAL_AXIS_POS - DEFAULT_AXIS_MARGIN);
        double maxRange = Math.max(rangeAxis.getUpperBound(),
                DEFAULT_HORIZONTAL_AXIS_POS + DEFAULT_AXIS_MARGIN);
        double minRange = Math.min(rangeAxis.getLowerBound(),
                DEFAULT_HORIZONTAL_AXIS_POS - DEFAULT_AXIS_MARGIN);

        // Mise  l'chelle logarithmique des axes
        LogarithmicAxis newDomainAxis = new LogarithmicAxis(domainAxis.getLabel());
        LogarithmicAxis newRangeAxis = new LogarithmicAxis(rangeAxis.getLabel());

        // Affectation des bornes en abscisse et en ordonne
        newDomainAxis.setLowerBound(minDomain);
        newDomainAxis.setUpperBound(maxDomain);
        newRangeAxis.setLowerBound(minRange);
        newRangeAxis.setUpperBound(maxRange);
        retChart.getXYPlot().setDomainAxis(newDomainAxis);
        retChart.getXYPlot().setRangeAxis(newRangeAxis);

        // Le point a une taille fixe
        Shape shape = new Rectangle(DEFAULT_POINT_SIZE, DEFAULT_POINT_SIZE);
        retChart.getXYPlot().getRenderer().setShape(shape);

        // Annotations
        XYLineAnnotation horizontalAxis = new XYLineAnnotation(minDomain, DEFAULT_HORIZONTAL_AXIS_POS,
                maxDomain, DEFAULT_HORIZONTAL_AXIS_POS);
        XYLineAnnotation verticalAxis = new XYLineAnnotation(DEFAULT_VERTICAL_AXIS_POS, minRange,
                DEFAULT_VERTICAL_AXIS_POS, maxRange);
        retChart.getXYPlot().addAnnotation(horizontalAxis);
        retChart.getXYPlot().addAnnotation(verticalAxis);

        super.setChart(retChart);
    }
    LOG.debug(WebMessages.getString("method.exit"));
    return retChart;
}

From source file:trendgraph.XYLineChart_AWT.java

public XYLineChart_AWT(int yearStart, int yearEnd, String[] creditUnionName, String columnName)
        throws SQLException {
    super("Graph");
    super.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.yearStart = yearStart;
    this.yearEnd = yearEnd;
    this.creditUnionName = creditUnionName;
    this.columnName = columnName;
    saveGraphButton = new JButton("Save Graph");
    saveGraphButton.setBorderPainted(false);
    saveGraphButton.setFocusPainted(false);

    JFreeChart xylineChart = ChartFactory.createXYLineChart("CU Report", "Year (YYYY)", //X-axis
            columnName, //Y-axis (replace with columnName
            createDataset(), PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(xylineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1000, 800)); //(x, y)
    final XYPlot plot = xylineChart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    renderer.setSeriesPaint(0, Color.RED); //can be GREEN, YELLOW, ETC.

    renderer.setSeriesStroke(0, new BasicStroke(3.0f)); //Font size

    renderer.setSeriesPaint(1, Color.BLUE); //can be GREEN, YELLOW, ETC.

    renderer.setSeriesStroke(1, new BasicStroke(3.0f)); //Font size

    renderer.setSeriesPaint(2, Color.GREEN); //can be GREEN, YELLOW, ETC.

    renderer.setSeriesStroke(2, new BasicStroke(3.0f)); //Font size

    renderer.setSeriesPaint(3, Color.yellow); //can be GREEN, YELLOW, ETC.

    renderer.setSeriesStroke(3, new BasicStroke(3.0f)); //Font size

    plot.setRenderer(renderer);// w  w  w . j a  v a  2 s. co m
    chartPanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
    chartPanel.add(saveGraphButton);
    setContentPane(chartPanel);
    pack();
    RefineryUtilities.centerFrameOnScreen(this);
    setVisible(true);

    saveGraphButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Rectangle rect = chartPanel.getBounds();
            FileChooser chooser = new FileChooser();

            //get chosen path and save the variable
            String path = chooser.getPath();
            path = path.replace("\\", "/");

            String format = "png";
            String fileName = path + "." + format;
            BufferedImage captureImage = new BufferedImage(rect.width, rect.height,
                    BufferedImage.TYPE_INT_ARGB);
            chartPanel.paint(captureImage.getGraphics());

            File file = new File(fileName);

            try {
                ImageIO.write(captureImage, format, file);

                //write data to file
            } catch (IOException ex) {
                Logger.getLogger(XYLineChart_AWT.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}

From source file:eu.stratosphere.addons.visualization.swt.SWTInstanceToolTip.java

private ChartComposite createMemoryChart(InstanceVisualizationData instanceVisualizationData,
        Color backgroundColor) {/*from  www.  ja  va  2 s. c  om*/

    final JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, "Time [sec.]", "Memory",
            instanceVisualizationData.getMemoryDataSet(), PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(),
            backgroundColor.getBlue()));

    // Set axis properly
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.getDomainAxis().setAutoRange(true);
    xyPlot.getDomainAxis().setAutoRangeMinimumSize(60);

    xyPlot.getRangeAxis().setAutoRange(false);
    xyPlot.getRangeAxis().setRange(0, instanceVisualizationData.getUpperBoundForMemoryChart());

    return new ChartComposite(getShell(), SWT.NONE, chart, true);
}

From source file:gui.DendrogramChart.java

private void setChartData(JFreeChart chart, boolean log) {
    XYSeries series = new XYSeries("Similarity vs No. of Groups");

    double rSim = d.getRootSimilarity();
    double diff = 1 - rSim;

    // TODO: What causes this?
    if (diff == 0)
        return;/*from w  w w. j av  a  2  s . c o  m*/

    for (double sim = rSim; sim <= 1.0; sim += (diff / 50)) {
        series.add(sim, d.getGroupCount(sim));
    }

    XYSeriesCollection data = new XYSeriesCollection(series);
    chart.getXYPlot().setDataset(data);
}

From source file:eu.stratosphere.addons.visualization.swt.SWTInstanceToolTip.java

private ChartComposite createNetworkChart(InstanceVisualizationData instanceVisualizationData,
        Color backgroundColor) {/*from ww  w  .  j a  v  a2s.  co  m*/

    final JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, "Time [sec.]", "Network",
            instanceVisualizationData.getNetworkDataSet(), PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(),
            backgroundColor.getBlue()));

    // Set axis properly
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.getDomainAxis().setAutoRange(true);
    xyPlot.getDomainAxis().setAutoRangeMinimumSize(60);

    // TODO: Repair auto range for range axis
    xyPlot.getRangeAxis().setAutoRange(false);
    xyPlot.getRangeAxis().setRange(0, 4096);

    return new ChartComposite(getShell(), SWT.NONE, chart, true);
}