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:mainGUI.TrainingJFrame.java

private void initLineChartPanel() {
    series = new XYSeries("MSE");
    seriesCollection = new XYSeriesCollection(series);

    chart = ChartFactory.createXYLineChart("Training", "Epoch Number", "MSE", seriesCollection,
            PlotOrientation.VERTICAL, true, true, true);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);/*from  w w w . j a va2 s  .  co  m*/
    renderer.setBaseStroke(new BasicStroke(3));
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(renderer);

    chartPanel = new ChartPanel(chart);
    chartPanel.setSize(chartContainerPanel.getWidth(), chartContainerPanel.getHeight());

    chartContainerPanel.add(chartPanel);
}

From source file:org.jax.maanova.test.gui.VolcanoPlotPanel.java

private void updateDataPoints() {
    this.cachedXYData = null;
    XYProbeData xyData = this.getXYData();

    DefaultXYDataset xyDataSet = new DefaultXYDataset();
    int[] selectedIndices = this.selectedIndices;
    if (selectedIndices.length == 0) {
        xyDataSet.addSeries("data", new double[][] { xyData.getXData(), xyData.getYData() });
    } else {//from www  .  ja  va  2s.  c o  m
        double[] xData = xyData.getXData();
        double[] yData = xyData.getYData();
        int[] dataIndices = xyData.getProbeIndices();

        double[] normalXData = new double[xData.length - selectedIndices.length];
        double[] normalYData = new double[xData.length - selectedIndices.length];

        double[] selectedXData = new double[selectedIndices.length];
        double[] selectedYData = new double[selectedIndices.length];

        int selectionIndex = 0;
        for (int i = 0; i < xData.length; i++) {
            if (selectionIndex < selectedIndices.length && dataIndices[i] == selectedIndices[selectionIndex]) {
                // this is one of the selected points
                selectedXData[selectionIndex] = xData[i];
                selectedYData[selectionIndex] = yData[i];

                selectionIndex++;
            } else {
                // this is not a selected point
                normalXData[i - selectionIndex] = xData[i];
                normalYData[i - selectionIndex] = yData[i];
            }
        }

        xyDataSet.addSeries("data", new double[][] { normalXData, normalYData });
        xyDataSet.addSeries("selected data", new double[][] { selectedXData, selectedYData });
    }

    JFreeChart scatterPlot = ChartFactory.createScatterPlot(this.chartConfigurationDialog.getChartTitle(),
            this.chartConfigurationDialog.getXAxisLabel(), this.chartConfigurationDialog.getYAxisLabel(),
            xyDataSet, PlotOrientation.VERTICAL, false, false, false);

    XYPlot xyPlot = (XYPlot) scatterPlot.getPlot();
    xyPlot.setRenderer(PlotUtil.createSimpleScatterPlotRenderer());
    if (this.viewArea != null) {
        PlotUtil.rescaleXYPlot(this.viewArea, xyPlot);
    }

    this.saveGraphImageAction.setChart(scatterPlot);
    this.chartPanel.setChart(scatterPlot);
}

From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java

/**
 * Generates a Chart.//from  w  w  w . ja va 2 s  . c  o m
 *
 * @param title        the title of the chart.
 * @param data         the data to use in the chart.
 * @param xAxis        the variables to use on the xAxis.
 * @param yAxis        the variables to use on the yAxis.
 * @param orientation  the orientation
 * @param itemRenderer the type of renderer to use.
 * @return the generated chart.
 */
private JFreeChart createChart(String title, XYDataset data, ValueAxis xAxis, ValueAxis yAxis,
        PlotOrientation orientation, XYItemRenderer itemRenderer, GraphDefinition def) {
    int seriesCount = data.getSeriesCount();
    for (int i = 0; i < seriesCount; i++) {
        itemRenderer.setSeriesPaint(i, def.getInlineColor(i));
        itemRenderer.setSeriesOutlinePaint(i, def.getOutlineColor(i));
    }

    XYPlot plot = new XYPlot(data, xAxis, yAxis, null);
    plot.setOrientation(orientation);
    plot.setRenderer(itemRenderer);

    return createChart(title, plot);
}

From source file:regresiones.RegresionSimple.java

public void Resolver(JTabbedPane resultados) {

    for (int i = 0; i < 9; i++) {
        sumatorias[i] = 0.0;//from  w ww.j ava2s .c  om
    }
    try {
        System.out.println("TOTAL DE DATOS: " + N);
        for (int i = 0; i < N; i++) {
            xiyi[i] = datos[i][0] * datos[i][1];
            System.out.println("X*Y" + i + ": " + xiyi[i]);
            x2[i] = datos[i][0] * datos[i][0]; //elevamos al cuadrado las x's
            y2[i] = datos[i][1] * datos[i][1]; //elevamos al cuadrado las y's
            sumatorias[0] += datos[i][0]; //sumatoria de x
            sumatorias[1] += datos[i][1]; //sumatoria de y

        }
        //sumatoria de xi*yi
        for (int j = 0; j < N; j++) {
            sumatorias[2] += xiyi[j];
        }

        //sumatoria de x^2
        for (int j = 0; j < N; j++) {
            sumatorias[3] += x2[j];
        }

        //sumatoria de y^2
        for (int j = 0; j < N; j++) {
            sumatorias[4] += y2[j];
        }

        mediax = sumatorias[0] / N;
        mediay = sumatorias[1] / N;

        System.out.println("RAIS 25: " + Math.sqrt(25));

        DecimalFormat df = new DecimalFormat("##.##");
        df.setRoundingMode(RoundingMode.DOWN);
        System.out.println("redondeo x^2-- " + df.format(sumatorias[3]));
        System.out.println("redondeo y^2-- " + df.format(sumatorias[4]));
        redondeoSumatoriax2 = Double.parseDouble(df.format(sumatorias[3]));
        redondeoSumatoriay2 = Double.parseDouble(df.format(sumatorias[4]));
        dxy = ((sumatorias[2]) / N) - mediax * mediay;
        dy = Math.sqrt(((redondeoSumatoriay2 / N) - (mediay * mediay)));
        dx = Math.sqrt(((redondeoSumatoriax2 / N) - (mediax * mediax)));

        b1 = ((sumatorias[2] * N) - sumatorias[0] * sumatorias[1])
                / ((sumatorias[3] * N) - (sumatorias[0] * sumatorias[0]));
        b0 = (sumatorias[1] / N) - ((b1 * sumatorias[0]) / N);

        // Y ESTIMADA
        for (int i = 0; i < N; i++) {
            yEstimada[i] = b0 + (b1 * datos[i][0]);
        }

        Se = Math.sqrt((sumatorias[4] - (b0 * sumatorias[1]) - (b1 * sumatorias[2])) / (N - 2));
        r = dxy / (dx * dy);
        System.out.println("sum x: " + sumatorias[0]);
        System.out.println("sum y: " + sumatorias[1]);
        System.out.println("sum x*y: " + sumatorias[2]);
        System.out.println("sum x^2: " + sumatorias[3]);
        System.out.println("sum y^2: " + sumatorias[4]);
        System.out.println("DX7: " + dxy);
        System.out.println("DY: " + dy);
        System.out.println("DX: " + dx);
        System.out.println("B0: " + b0);
        System.out.println("B1: " + b1);

        // mostramos resultados para la pestaa resultados***********************************************************************
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBackground(Color.white);
        JLabel titulo = new JLabel("Resultados");//creamos el titulo
        panel.add(titulo, BorderLayout.PAGE_START);//lo agregamos al inicio
        jtable = new JTable();//creamos la tabla a mostrar
        jtable.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 0), 2, true));
        jtable.setFont(new java.awt.Font("Arial", 1, 14));
        jtable.setColumnSelectionAllowed(true);
        jtable.setCursor(new java.awt.Cursor(java.awt.Cursor.N_RESIZE_CURSOR));
        jtable.setInheritsPopupMenu(true);
        jtable.setMinimumSize(new java.awt.Dimension(80, 80));
        String[] titulos = { "X", "Y", "Xi*Yi", "X2", "Y2", "Y estimada" };//los titulos de la tabla
        arregloFinal = new String[N][6];
        DecimalFormat formato = new DecimalFormat("0.00");
        for (int i = 0; i < N; i++) {//armamos el arreglo
            arregloFinal[i][0] = datos[i][0] + ""; //X
            arregloFinal[i][1] = datos[i][1] + "";//Y
            arregloFinal[i][2] = formato.format(xiyi[i]);
            arregloFinal[i][3] = formato.format(x2[i]);
            arregloFinal[i][4] = formato.format(y2[i]);
            arregloFinal[i][5] = formato.format(yEstimada[i]);
        }
        DefaultTableModel TableModel = new DefaultTableModel(arregloFinal, titulos);
        jtable.setModel(TableModel);
        JScrollPane jScrollPane1 = new JScrollPane();
        jScrollPane1.setViewportView(jtable);
        jtable.getColumnModel().getSelectionModel()
                .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        panel.add(jScrollPane1, BorderLayout.CENTER);
        JPanel panel2 = new JPanel(new GridLayout(0, 4));//creo un panel con rejilla de 4 columnas
        JLabel etiquetaN = new JLabel("N");
        JTextField cajaN = new JTextField();
        cajaN.setText(N + "");
        JLabel etiquetab0 = new JLabel("b0");
        JTextField cajab0 = new JTextField();
        cajab0.setText(b0 + "");
        JLabel etiquetab1 = new JLabel("b1");
        JTextField cajab1 = new JTextField();
        cajab1.setText(b1 + "");
        JLabel etiquetadxy = new JLabel("DXy");
        JTextField cajadxy = new JTextField();
        cajadxy.setText(dxy + "");
        JLabel etiquetadx = new JLabel("DX");
        JTextField cajadx = new JTextField();
        cajadx.setText(dx + "");
        JLabel etiquetady = new JLabel("DY");
        JTextField cajady = new JTextField();
        cajady.setText(dy + "");
        JLabel etiquetaR = new JLabel("R");
        JTextField cajaR = new JTextField();
        cajaR.setText(r + "");
        JLabel etiquetaSE = new JLabel("SE");
        JTextField cajaSE = new JTextField();
        cajaSE.setText(Se + "");
        JButton boton = new JButton("Exportar a PDF");
        boton.addActionListener(this);
        panel2.add(etiquetaN);
        panel2.add(cajaN);
        panel2.add(etiquetab0);
        panel2.add(cajab0);
        panel2.add(etiquetab1);
        panel2.add(cajab1);
        panel2.add(etiquetadxy);
        panel2.add(cajadxy);
        panel2.add(etiquetadx);
        panel2.add(cajadx);
        panel2.add(etiquetady);
        panel2.add(cajady);
        panel2.add(etiquetaR);
        panel2.add(cajaR);
        panel2.add(etiquetaSE);
        panel2.add(cajaSE);
        panel2.add(boton);
        panel.add(panel2, BorderLayout.SOUTH);//agrego el panel2 con rejilla en el panel principal al sur
        resultados.addTab("resultado", panel);
        //**************************************************************************************
        //intervalos de confianza
        JPanel intervalos = new JPanel(new BorderLayout());
        JPanel variables = new JPanel(new GridLayout(0, 2));
        JLabel variableX1 = new JLabel("X1");
        cajaVariableX1 = new JTextField();
        boton = new JButton("calcular");
        boton.addActionListener(this);
        JLabel variableEfectividad = new JLabel("Efectividad");
        String[] efectividades = { "80", "85", "90", "95", "99" };
        combo = new JComboBox(efectividades);
        variables.add(variableX1);
        variables.add(cajaVariableX1);
        variables.add(variableEfectividad);
        variables.add(combo);
        variables.add(boton);//comentario
        //cometario2
        intervalos.add(variables, BorderLayout.NORTH);
        jtable2 = new JTable();//creamos la tabla a mostrar
        jtable2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 0), 2, true));
        jtable2.setFont(new java.awt.Font("Arial", 1, 14));
        jtable2.setColumnSelectionAllowed(true);
        jtable2.setCursor(new java.awt.Cursor(java.awt.Cursor.N_RESIZE_CURSOR));
        jtable2.setInheritsPopupMenu(true);
        jtable2.setMinimumSize(new java.awt.Dimension(80, 80));
        String[] titulos2 = { "Y estimada", "Li", "Ls" };//los titulos de la tabla
        String[][] pruebaIntervalos = { { "", "", "" } };
        DefaultTableModel TableModel2 = new DefaultTableModel(pruebaIntervalos, titulos2);
        jtable2.setModel(TableModel2);
        JScrollPane jScrollPane2 = new JScrollPane();
        jScrollPane2.setViewportView(jtable2);
        jtable2.getColumnModel().getSelectionModel()
                .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        intervalos.add(jScrollPane2, BorderLayout.CENTER);
        resultados.addTab("intervalos", intervalos);
        // ***********************************************************************
        JPanel graficas = new JPanel(new GridLayout(0, 1));
        XYDataset dataset = createSampleDataset();
        JFreeChart chart = ChartFactory.createXYLineChart("Grafica", "X", "Y", dataset,
                PlotOrientation.VERTICAL, true, false, false);
        XYPlot plot = (XYPlot) chart.getPlot();
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(0, true);
        renderer.setSeriesShapesVisible(0, true);
        renderer.setSeriesLinesVisible(1, true);
        renderer.setSeriesShapesVisible(1, true);
        plot.setRenderer(renderer);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
        graficas.add(chartPanel);//agregamos la primer grafica
        resultados.addTab("Graficas", graficas);
        //IMPRIMIR JTABLE
        /* MessageFormat headerFormat = new MessageFormat("MI CABECERA");
         MessageFormat footerFormat = new MessageFormat("- Pgina {0} -");
         jtable.print(PrintMode.FIT_WIDTH, headerFormat, footerFormat);
         */

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.ApproximationSetViewer.java

/**
 * Updates the display.  This method must only be invoked on the event
 * dispatch thread.// ww  w  . j  av a 2 s  .  c o m
 */
protected void update() {
    XYSeriesCollection dataset = new XYSeriesCollection();

    //generate approximation set
    for (int seedIndex : seedList.getSelectedIndices()) {
        Accumulator accumulator = accumulators.get(seedIndex);
        int index = 0;

        if (!accumulator.keySet().contains("Approximation Set")) {
            continue;
        }

        while ((index < accumulator.size("NFE") - 1)
                && ((Integer) accumulator.get("NFE", index) < slider.getValue())) {
            index++;
        }

        List<?> list = (List<?>) accumulator.get("Approximation Set", index);
        XYSeries series = new XYSeries(localization.getString("text.seed", seedIndex + 1), false, true);

        for (Object object : list) {
            Solution solution = (Solution) object;
            series.add(getValue(solution, 0), getValue(solution, 1));
        }

        dataset.addSeries(series);
    }

    //generate reference set
    if (referenceSet != null) {
        XYSeries series = new XYSeries(localization.getString("text.referenceSet"), false, true);

        for (Solution solution : referenceSet) {
            series.add(getValue(solution, 0), getValue(solution, 1));
        }

        dataset.addSeries(series);
    }

    JFreeChart chart = ChartFactory.createScatterPlot(getTitle() + " @ " + slider.getValue() + " NFE",
            (String) xAxisSelection.getSelectedItem(), (String) yAxisSelection.getSelectedItem(), dataset,
            PlotOrientation.VERTICAL, true, true, false);

    //set the renderer to only display shapes
    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);

    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        Paint paint = paintHelper.get(dataset.getSeriesKey(i));
        renderer.setSeriesPaint(i, paint);
    }

    plot.setRenderer(renderer);

    //set the zoom based on the user's preferences
    if ((initialRangeBounds == null) || (initialDomainBounds == null)) {
        initialRangeBounds = plot.getRangeAxis().getRange();
        initialDomainBounds = plot.getDomainAxis().getRange();
    }

    if (useInitialBounds.isSelected()) {
        plot.getRangeAxis().setRange(initialRangeBounds);
        plot.getDomainAxis().setRange(initialDomainBounds);
    } else if (useZoomBounds.isSelected()) {
        if ((zoomRangeBounds == null) || (zoomDomainBounds == null)) {
            zoomRangeBounds = initialRangeBounds;
            zoomDomainBounds = initialDomainBounds;
        }

        plot.getRangeAxis().setRange(zoomRangeBounds);
        plot.getDomainAxis().setRange(zoomDomainBounds);
    } else if (useReferenceSetBounds.isSelected()) {
        if (referenceRangeBounds.getLength() > 0.0) {
            plot.getRangeAxis().setRange(referenceRangeBounds);
        }

        if (referenceDomainBounds.getLength() > 0.0) {
            plot.getDomainAxis().setRange(referenceDomainBounds);
        }
    }

    //register with the chart to receive zoom events
    chart.addChangeListener(this);

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

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputScatter.java

@Override
protected void initRenderer(final IScope scope) {
    // TODO Auto-generated method stub
    final XYPlot plot = (XYPlot) this.chart.getPlot();
    defaultrenderer = new myXYErrorRenderer();
    plot.setRenderer((myXYErrorRenderer) defaultrenderer);

}

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);
    chartPanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
    chartPanel.add(saveGraphButton);/*w ww . j a  v  a  2s.com*/
    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:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.LinePlot.java

@Override
protected void update() {
    XYDataset dataset = null;/* w  w w  . j a  v  a 2s  .c  o  m*/

    //generate the plot data
    if (controller.getShowIndividualTraces()) {
        dataset = new DefaultTableXYDataset();

        for (ResultKey key : frame.getSelectedResults()) {
            generateIndividualSeries(key, (DefaultTableXYDataset) dataset);
        }
    } else {
        dataset = new YIntervalSeriesCollection();

        for (ResultKey key : frame.getSelectedResults()) {
            generateQuantileSeries(key, (YIntervalSeriesCollection) dataset);
        }
    }

    //create the chart
    JFreeChart chart = ChartFactory.createXYLineChart(metric, localization.getString("text.NFE"),
            localization.getString("text.value"), dataset, PlotOrientation.VERTICAL, false, true, false);
    final XYPlot plot = chart.getXYPlot();

    //setup the series renderer
    if (controller.getShowIndividualTraces()) {
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            Paint paint = frame.getPaintHelper().get(dataset.getSeriesKey(i));

            renderer.setSeriesStroke(i, new BasicStroke(1f, 1, 1));
            renderer.setSeriesPaint(i, paint);
        }

        plot.setRenderer(renderer);
    } else {
        DeviationRenderer renderer = new DeviationRenderer(true, false);

        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            Paint paint = frame.getPaintHelper().get(dataset.getSeriesKey(i));

            renderer.setSeriesStroke(i, new BasicStroke(3f, 1, 1));
            renderer.setSeriesPaint(i, paint);
            renderer.setSeriesFillPaint(i, paint);
        }

        plot.setRenderer(renderer);
    }

    //create the legend
    final LegendItemCollection items = plot.getLegendItems();
    Iterator<?> iterator = items.iterator();
    Set<ResultKey> uniqueKeys = new HashSet<ResultKey>();

    while (iterator.hasNext()) {
        LegendItem item = (LegendItem) iterator.next();

        if (uniqueKeys.contains(item.getSeriesKey())) {
            iterator.remove();
        } else {
            uniqueKeys.add((ResultKey) item.getSeriesKey());
        }
    }

    LegendItemSource source = new LegendItemSource() {

        @Override
        public LegendItemCollection getLegendItems() {
            return items;
        }

    };

    LegendTitle legend = new LegendTitle(source);
    legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    legend.setFrame(new LineBorder());
    legend.setBackgroundPaint(Color.WHITE);
    legend.setPosition(RectangleEdge.BOTTOM);
    chart.addLegend(legend);

    //scale the axes
    final NumberAxis domainAxis = new NumberAxis();
    domainAxis.setAutoRange(true);
    plot.setDomainAxis(domainAxis);

    //add overlay
    if (controller.getShowLastTrace() && !controller.getShowIndividualTraces()
            && (controller.getLastAccumulator() != null)
            && controller.getLastAccumulator().keySet().contains(metric)) {
        DefaultTableXYDataset dataset2 = new DefaultTableXYDataset();
        XYSeries series = new XYSeries(localization.getString("text.last"), false, false);

        for (int i = 0; i < controller.getLastAccumulator().size(metric); i++) {
            series.add((Number) controller.getLastAccumulator().get("NFE", i),
                    (Number) controller.getLastAccumulator().get(metric, i));
        }

        dataset2.addSeries(series);

        XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
        renderer2.setSeriesStroke(0, new BasicStroke(1f, 1, 1));
        renderer2.setSeriesPaint(0, Color.BLACK);

        plot.setDataset(1, dataset2);
        plot.setRenderer(1, renderer2);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    }

    //update the chart in the GUI
    removeAll();
    add(new ChartPanel(chart), BorderLayout.CENTER);
    revalidate();
    repaint();
}

From source file:web.diva.server.model.LineChartGenerator.java

/**
 * Creates a chart.// ww  w  . java 2 s  .c om
 *
 * @param dataset the data for the chart.
 * @param lcr the line chart result
 *
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset, String[] colors, String[] columnIds, int[] selection) {

    final JFreeChart chart = ChartFactory.createXYLineChart("", // chart title
            "", // x axis label
            "", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            false, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    if (selection == null) {
        for (int x = 0; x < colors.length; x++) {

            renderer.setSeriesShapesVisible(x, false);
            renderer.setSeriesPaint(x, imgGenerator.hex2Rgb(colors[x]));

        }
    } else {
        for (int x = 0; x < selection.length; x++) {

            renderer.setSeriesShapesVisible(x, false);
            renderer.setSeriesPaint(x, imgGenerator.hex2Rgb(colors[selection[x]]));

        }

    }

    plot.setRenderer(renderer);

    SymbolAxis rangeAxis = new SymbolAxis("", columnIds);
    rangeAxis.setGridBandsVisible(false);
    rangeAxis.setVerticalTickLabels(true);
    rangeAxis.setVisible(true);
    //        rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 1));
    rangeAxis.setFixedDimension(51.0);

    boolean auto = rangeAxis.getAutoRangeIncludesZero();
    rangeAxis.setAutoRangeIncludesZero(true ^ auto);
    rangeAxis.setTickUnit(new NumberTickUnit(1));
    rangeAxis.setRange(0, columnIds.length);

    plot.setDomainAxis(rangeAxis);

    return chart;

}

From source file:treegross.standsimulation.TgGrafik.java

public JFreeChart createChart(Stand st) {
    // create the dataset...
    XYSeriesCollection dataset = new XYSeriesCollection();
    for (int i = 0; i < st.nspecies; i++) {
        XYSeries series = new XYSeries(st.sp[i].spDef.shortName);
        //          DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (int k = 0; k < st.ntrees; k++) {
            if ((st.tr[k].d > 0) && st.tr[k].out < 0 && st.tr[k].code == st.sp[i].code)
                series.add(st.tr[k].d, st.tr[k].h);

        }/*  ww w  .  j  a  v a  2 s .  com*/
        dataset.addSeries(series);
    }
    //     
    JFreeChart chart = ChartFactory.createScatterPlot(messages.getString("heightDiameter"),
            messages.getString("dbh"), messages.getString("height"), dataset,
            org.jfree.chart.plot.PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = chart.getXYPlot();
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    //
    //         XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < st.nspecies; i++) {
        renderer.setSeriesLinesVisible(i, false);
        renderer.setSeriesPaint(i,
                new Color(st.sp[i].spDef.colorRed, st.sp[i].spDef.colorGreen, st.sp[i].spDef.colorBlue));
    }
    plot.setRenderer(renderer);

    return chart;
}