Example usage for org.jfree.chart.plot XYPlot setRenderer

List of usage examples for org.jfree.chart.plot XYPlot setRenderer

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setRenderer.

Prototype

public void setRenderer(XYItemRenderer renderer) 

Source Link

Document

Sets the renderer for the primary dataset and sends a change event to all registered listeners.

Usage

From source file:net.sourceforge.processdash.ui.web.reports.snippets.EstErrorScatterChart.java

@Override
public JFreeChart createChart() {
    JFreeChart chart = super.createChart();

    // set minimum/maximum bounds on the two axes
    XYPlot xyPlot = chart.getXYPlot();
    double cutoff = getPercentParam("cut", 100, 200, 5000);
    xyPlot.setDomainAxis(truncAxis(xyPlot.getDomainAxis(), cutoff));
    xyPlot.setRangeAxis(truncAxis(xyPlot.getRangeAxis(), cutoff));
    xyPlot.setRenderer(new TruncatedItemRenderer(xyPlot.getRenderer()));

    // add a box illustrating the target range
    if (data.numRows() > 0) {
        double box = getPercentParam("pct", 0, 50, 100);
        xyPlot.addAnnotation(new XYBoxAnnotation(-box, -box, box, box));
        xyPlot.addAnnotation(new XYLineAnnotation(-box, 0, box, 0));
        xyPlot.addAnnotation(new XYLineAnnotation(0, -box, 0, box));
    }/*from w w  w .j  av a 2  s.  c  o  m*/

    return chart;
}

From source file:org.moeaframework.examples.gp.regression.SymbolicRegressionGUI.java

/**
 * Updates the GUI.  This method updates a Swing GUI, and therefore must
 * only be invoked on the event dispatch thread.
 *//*from w w  w  .j  av  a  2  s.c  o  m*/
protected void updateOnEventQueue() {
    // create local reference incase update is called again
    double[] x = problem.getX();
    double[] actualY = problem.getActualY();
    double[] approximatedY = problem.getApproximatedY(solution);

    // generate the line series
    XYSeries actualSeries = new XYSeries("Target Function", false, false);
    XYSeries approximatedSeries = new XYSeries("Estimated Function", false, false);

    for (int i = 0; i < x.length; i++) {
        actualSeries.add(x[i], actualY[i]);
        approximatedSeries.add(x[i], approximatedY[i]);
    }

    DefaultTableXYDataset dataset = new DefaultTableXYDataset();
    dataset.addSeries(actualSeries);
    dataset.addSeries(approximatedSeries);

    // generate the plot
    JFreeChart chart = ChartFactory.createXYLineChart("Symbolic Regression Demo", "x", "f(x)", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new XYLineAndShapeRenderer());

    // update the details
    details.setText("Generation " + generation + " / " + maxGenerations + "\nObjective value: "
            + solution.getObjective(0) + "\n\n" + solution.getVariable(0));

    container.removeAll();
    container.add(new ChartPanel(chart), BorderLayout.CENTER);
    container.revalidate();
    container.repaint();

    if (!isCanceled) {
        setVisible(true);
    }
}

From source file:edu.cmu.sv.modelinference.eventtool.charting.DataChart.java

private JFreeChart createChart(String yLabel) {
    //Create the chart
    final JFreeChart chart = ChartFactory.createXYLineChart("Chart", "Time", yLabel, null);

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);

    // 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:loadmaprenderer.ChartTest.java

private JFreeChart makeChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYLineChart("Cost/Year Chart", "Year", "Cost", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.BLUE);
    plot.setRangeGridlinePaint(Color.BLUE);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRange(rootPaneCheckingEnabled);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(rootPaneCheckingEnabled);
    return chart;
}

From source file:network.Draw.java

@Override
public void run() {
    JFrame frame = new JFrame();
    frame.addWindowListener(new java.awt.event.WindowAdapter() {
        @Override//from   w ww . j  av  a  2s  .com
        public void windowClosing(java.awt.event.WindowEvent windowEvent) {
            isRun = false;
        }
    });

    while (isRun) {
        JFreeChart xylineChart;
        if (method == 0) {
            System.out.println("hi");
            xylineChart = ChartFactory.createXYLineChart("Tempreture", "Time", "Tempreture", createDataset(0),
                    PlotOrientation.VERTICAL, true, true, false);
        } else {
            System.out.println("hi");
            xylineChart = ChartFactory.createXYLineChart("Tempreture", "Time", "Tempreture", createDataset(1),
                    PlotOrientation.VERTICAL, true, true, false);
        }
        final XYPlot plot = xylineChart.getXYPlot();
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesStroke(0, new BasicStroke(1.0f));
        plot.setRenderer(renderer);

        frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        frame.setSize(700, 500);
        frame.getContentPane().removeAll();

        ChartPanel chartPanel = new ChartPanel(xylineChart);
        frame.add(chartPanel);
        frame.setVisible(true);
        try {
            Thread.sleep(10000);
        } catch (InterruptedException ex) {
            System.out.println(ex);
        }
    }
}

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

/**
 * Constructs the demo application.//from  ww  w  .j  a v  a 2 s.  com
 *
 * @param title  the frame title.
 */
public XYLineAndShapeRendererDemo(final String title) {

    super(title);
    XYDataset dataset = createSampleDataset();
    JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", dataset, PlotOrientation.VERTICAL, true,
            false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, true);
    plot.setRenderer(renderer);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
    setContentPane(chartPanel);

}

From source file:org.mwc.cmap.LiveDataMonitor.views.LiveDataMonitor.java

/**
 * Creates the Chart based on a dataset/*www.j  av a 2 s.c o  m*/
 */
private JFreeChart createChart(final TimeSeriesCollection dataset) {

    final String annTitle = "[PENDING]";
    final String catLabel = "Time";
    final String valueLabel = "Value";
    final JFreeChart chart = ChartFactory.createXYLineChart(annTitle, catLabel, valueLabel, dataset,
            PlotOrientation.VERTICAL, false, true, false);

    final XYPlot plot = chart.getXYPlot();
    final DateAxis dateA = new DateAxis();
    plot.setDomainAxis(dateA);
    plot.setRenderer(new XYLineAndShapeRenderer());
    plot.setNoDataMessage("No data available");
    return chart;

}

From source file:cloud.requestengine.ResponseTimeService.java

public JFreeChart getChart() {
    JFreeChart chart = ChartFactory.createScatterPlot("Response Time", "Time (ms)", "ResponseTime (ms)",
            getDataset(), PlotOrientation.VERTICAL, true, true, false);
    final XYPlot plot = chart.getXYPlot();
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);

    Shape shape = new Rectangle2D.Double(-1, -1, 2, 2);
    renderer.setSeriesShape(0, shape);//from   ww w. ja v a  2 s .c  o m

    plot.setRenderer(renderer);

    return chart;
}

From source file:syg_package01.PanelRysunek_Wykres.java

private void initGUI() {
    try {//w w  w.  j av  a2 s  . co m
        GridLayout thisLayout = new GridLayout(1, 1);
        thisLayout.setHgap(5);
        thisLayout.setVgap(5);
        thisLayout.setColumns(1);
        this.setLayout(thisLayout);
        setPreferredSize(new Dimension(400, 300));

        if (this.wykres) {

            XYSeries series = new XYSeries("Wykres");
            double punkt;
            double ta = this.sygnalWyswietlany.gett1();

            if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY
                    || sygnalWyswietlany.getPunktyY().size() <= 0) {
                punkt = this.sygnalWyswietlany.gett1();
                while (ta <= this.sygnalWyswietlany.gett1() + this.sygnalWyswietlany.getd()) {
                    punkt = this.sygnalWyswietlany.wykres_punkty(punkt, ta);
                    this.sygnalWyswietlany.setPunktyY(punkt);
                    series.add(ta, punkt);
                    if (this.sygnalWyswietlany.gettyp() < 10)
                        ta = ta + this.sygnalWyswietlany.getkroczek();
                    else
                        ta = ta + this.sygnalWyswietlany.getkroczek() * 10;
                }
            } else if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.DYSKRETNY
                    && sygnalWyswietlany.getPunktyY().size() > 0) {
                punkt = sygnalWyswietlany.getPunktzindexu(0);
                int iloscProbek = (int) (this.sygnalWyswietlany.getPunktyY().size());
                for (int i = 1; i < iloscProbek; i++) {
                    punkt = this.sygnalWyswietlany.getPunktzindexu(i);
                    series.add(ta, punkt);
                    // if (this.sygnalWyswietlany.gettyp() < 10)
                    // ta = ta + this.sygnalWyswietlany.getkroczek();
                    // else
                    ta = ta + this.sygnalWyswietlany.getkroczek();
                }
            }

            XYSeriesCollection dataset = new XYSeriesCollection(series);
            JFreeChart chart;

            if ((this.sygnalWyswietlany.gettyp() < 10)
                    && (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY)) {
                chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
                        true, true, true);

                final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
                renderer.setSeriesLinesVisible(0, false);
            } else {
                chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
                        true, true, true);

                final XYPlot plot = chart.getXYPlot();
                final XYDotRenderer renderer = new XYDotRenderer();
                renderer.setDotHeight(3);
                renderer.setDotWidth(3);
                plot.setRenderer(renderer);

                final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
                rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            }

            ChartPanel chartpanel = new ChartPanel(chart);
            chartpanel.setDomainZoomable(true);

            this.add(chartpanel);
        }

        Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.bdb.weather.display.preferences.ColorPreferencePanel.java

public ColorPreferencePanel() {
    VBox vbox = new VBox();
    GridPane colorPanel = new GridPane();

    for (ColorPreferenceEntry entry : entries2) {
        ColorPicker colorPicker = new ColorPicker(preferences.getColorPref(entry.preferenceName));
        entry.button = colorPicker;//ww  w .  j  a  va  2s.c om
        colorPanel.add(new Label(entry.preferenceName), 0, entry.row);
        colorPanel.add(colorPicker, 1, entry.row);
    }

    GridPane plotColorPanel = new GridPane();

    int gridx = 0;
    int gridy = 0;

    //
    // Layout the column headers
    //
    for (int i = 0; i < COLOR_COL_HEADERS.length; i++) {
        gridx = i;
        plotColorPanel.add(new Label(COLOR_COL_HEADERS[i]), gridx, gridy);
    }

    //
    // Layout the row leaders
    //
    //c.anchor = GridBagConstraints.EAST;
    for (String header : COLOR_ROW_HEADERS) {
        gridx = 0;
        gridy++;
        plotColorPanel.add(new Label(header), gridx, gridy);

        gridx = 5;

        Set<String> names = ColorSchemeCollection.getColorSchemeNames();
        ComboBox<String> scheme = new ComboBox<>();
        scheme.getItems().addAll(names);
        scheme.setUserData(gridy);
        plotColorPanel.add(scheme, gridx, gridy);
        scheme.setOnAction((ActionEvent e) -> {
            ComboBox<String> cb = (ComboBox<String>) e.getSource();
            applyColorScheme((Integer) cb.getUserData(), cb.getSelectionModel().getSelectedItem());
        });
        gridx = 6;
        CheckBox showSeries = new CheckBox();
        showSeries.setUserData(gridy);
        plotColorPanel.add(showSeries, gridx, gridy);
        showSeries.setOnAction((ActionEvent e) -> {
            CheckBox cb = (CheckBox) e.getSource();
            int row = (Integer) cb.getUserData();
            for (ColorPreferenceEntry entry : entries) {
                if (entry.row == row) {
                    addRemoveSeries(entry.preferenceName, cb.isSelected());
                }
            }
            createSeriesData();
            configureRenderer();
        });
    }

    //c.anchor = GridBagConstraints.CENTER;
    for (ColorPreferenceEntry entry : entries) {
        gridx = entry.column;
        gridy = entry.row;
        ColorPicker button = new ColorPicker();
        button.setValue(preferences.getColorPref(entry.preferenceName));
        //button.setPrefSize(10, 10);
        button.setUserData(entry);
        plotColorPanel.add(button, gridx, gridy);
        entry.button = button;
    }

    JFreeChart chart = ChartFactory.createXYLineChart("Example", "X Axis", "Y Axis", dataset,
            PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(renderer);

    ChartViewer graphExamplePanel = new ChartViewer(chart);

    vbox.getChildren().addAll(colorPanel, plotColorPanel);
    setTop(vbox);
    setCenter(graphExamplePanel);
    FlowPane buttonPanel = new FlowPane();
    Button button = new Button("OK");
    button.setOnAction((ActionEvent e) -> {
        saveData();
    });
    buttonPanel.getChildren().add(button);
    setBottom(buttonPanel);
}