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

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

Introduction

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

Prototype

public ValueAxis getDomainAxis() 

Source Link

Document

Returns the domain axis with index 0.

Usage

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

@Override
public void setUseXLabels(final IScope scope, final IExpression expval) {
    // if there is something to do to use custom X axis
    final XYPlot pp = (XYPlot) chart.getPlot();

    ((NumberAxis) pp.getDomainAxis()).setNumberFormatOverride(new NumberFormat() {

        @Override//from  www.  j  a  v  a  2 s  . c om
        public StringBuffer format(final double number, final StringBuffer toAppendTo,
                final FieldPosition pos) {
            final int ind = chartdataset.XSeriesValues.indexOf(number);
            if (ind >= 0) {
                return new StringBuffer("" + chartdataset.Xcategories.get(ind));
            }
            return new StringBuffer("");

        }

        @Override
        public StringBuffer format(final long number, final StringBuffer toAppendTo, final FieldPosition pos) {
            return new StringBuffer("n" + number);
            // return new StringBuffer(String.format("%s", number));
        }

        @Override
        public Number parse(final String source, final ParsePosition parsePosition) {
            return null;
        }
    });

}

From source file:org.esa.beam.visat.toolviews.stat.HistogramPanel.java

private void updateXAxis() {
    final XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setLabel(getAxisLabel());
}

From source file:org.rioproject.examples.hospital.ui.PatientStatsPanel.java

private JFreeChart createTimeSeriesChart(TimeSeriesCollection dataSet, Color color) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataSet, true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getRenderer().setSeriesPaint(0, color);
    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);

    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setRange(0, 150);//from  w w  w. j  av  a  2 s .  c  o  m
    ValueAxis xAxis = plot.getDomainAxis();
    xAxis.setAutoRange(true);
    xAxis.setFixedAutoRange(5 * MINUTE);
    return chart;
}

From source file:org.ala.spatial.web.services.GDMWSController.java

public static void generateCharts123(String outputdir) {
    try {/*from w  w  w .jav  a2 s. c o  m*/
        IniReader ir = new IniReader(outputdir + "/gdm_params.txt");
        double intercept = ir.getDoubleValue("GDMODEL", "Intercept");

        // 1. read the ObservedVsPredicted.csv file
        System.out.println("Loading csv data");
        CSVReader csv = new CSVReader(new FileReader(outputdir + "ObservedVsPredicted.csv"));
        List<String[]> rawdata = csv.readAll();
        double[][] dataCht1 = new double[2][rawdata.size() - 1];
        double[][] dataCht2 = new double[2][rawdata.size() - 1];

        // for Chart 1: obs count
        int[] obscount = new int[11];
        for (int i = 0; i < obscount.length; i++) {
            obscount[i] = 0;
        }

        System.out.println("populating data");
        for (int i = 1; i < rawdata.size(); i++) {
            String[] row = rawdata.get(i);
            double obs = Double.parseDouble(row[4]);
            dataCht1[0][i - 1] = Double.parseDouble(row[6]);
            dataCht1[1][i - 1] = obs;

            dataCht2[0][i - 1] = Double.parseDouble(row[5]) - intercept;
            dataCht2[1][i - 1] = obs;

            int obc = (int) Math.round(obs * 10);
            obscount[obc]++;
        }

        DefaultXYDataset dataset1 = new DefaultXYDataset();
        dataset1.addSeries("", dataCht1);

        DefaultXYDataset dataset2 = new DefaultXYDataset();
        dataset2.addSeries("", dataCht2);

        DefaultCategoryDataset dataset3 = new DefaultCategoryDataset();
        for (int i = 0; i < obscount.length; i++) {
            String col = "0." + i + "-0." + (i + 1);
            if (i == 10) {
                col = "0.9-1.0";
            }
            dataset3.addValue(obscount[i] + 100, "col", col);
        }
        generateChartByType("Response Histogram", "Observed Dissimilarity Class", "Number of Site Pairs",
                dataset3, outputdir, "bar", "resphist");

        XYDotRenderer renderer = new XYDotRenderer();
        //Shape cross = ShapeUtilities.createDiagonalCross(3, 1);
        //renderer.setSeriesShape(0, cross);
        renderer.setDotWidth(3);
        renderer.setDotHeight(3);
        renderer.setSeriesPaint(0, Color.BLACK);

        JFreeChart jChart1 = ChartFactory.createScatterPlot(
                "Observed versus predicted compositional dissimilarity",
                "Predicted Compositional Dissimilarity", "Observed Compositional Dissimilarity", dataset1,
                PlotOrientation.VERTICAL, false, false, false);
        jChart1.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));

        XYPlot plot = (XYPlot) jChart1.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setDomainZeroBaselineVisible(true);
        plot.setRangeZeroBaselineVisible(true);
        plot.setDomainGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRenderer(0, renderer);

        NumberAxis domain = (NumberAxis) plot.getDomainAxis();
        domain.setAutoRangeIncludesZero(false);
        domain.setAxisLineVisible(false);
        domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        NumberAxis range = (NumberAxis) plot.getRangeAxis();
        range.setAutoRangeIncludesZero(false);
        range.setAxisLineVisible(false);
        range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        double dMinPred = domain.getRange().getLowerBound();
        double dMaxPred = domain.getRange().getUpperBound();

        double dMinObs = range.getRange().getLowerBound();
        double dMaxObs = range.getRange().getUpperBound();

        System.out.println("1..pred.min.max: " + dMinPred + ", " + dMaxPred);

        int regressionLineSegs = 10;
        double dInc = (dMaxPred - dMinPred) / regressionLineSegs;
        double[][] dataReg1 = new double[2][regressionLineSegs + 1];
        DefaultXYDataset dsReg1 = new DefaultXYDataset();
        int i = 0;
        for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) {
            dataReg1[0][i] = d;
            dataReg1[1][i] = d;
        }
        dsReg1.addSeries("", dataReg1);
        XYSplineRenderer regressionRenderer = new XYSplineRenderer();
        regressionRenderer.setBaseSeriesVisibleInLegend(true);
        regressionRenderer.setSeriesPaint(0, Color.RED);
        regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f));
        regressionRenderer.setBaseShapesVisible(false);
        plot.setDataset(1, dsReg1);
        plot.setRenderer(1, regressionRenderer);

        System.out.println("Writing image....");
        ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/obspredissim.png"), jChart1, 600, 400);

        // For chart 3
        JFreeChart jChart2 = ChartFactory.createScatterPlot(
                "Observed compositional dissimilarity vs predicted ecological distance",
                "Predicted ecological distance", "Observed Compositional Dissimilarity", dataset2,
                PlotOrientation.VERTICAL, false, false, false);
        jChart2.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));

        plot = (XYPlot) jChart2.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setDomainZeroBaselineVisible(true);
        plot.setRangeZeroBaselineVisible(true);
        plot.setDomainGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRenderer(0, renderer);

        domain = (NumberAxis) plot.getDomainAxis();
        domain.setAutoRangeIncludesZero(false);
        domain.setAxisLineVisible(false);
        domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        range = (NumberAxis) plot.getRangeAxis();
        range.setAutoRangeIncludesZero(false);
        range.setAxisLineVisible(false);
        range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        dMinPred = domain.getRange().getLowerBound();
        dMaxPred = domain.getRange().getUpperBound();

        dMinObs = range.getRange().getLowerBound();
        dMaxObs = range.getRange().getUpperBound();

        System.out.println("2.pred.min.max: " + dMinPred + ", " + dMaxPred);

        regressionLineSegs = 10;
        dInc = (dMaxPred - dMinPred) / regressionLineSegs;
        dataReg1 = new double[2][regressionLineSegs + 1];
        dsReg1 = new DefaultXYDataset();
        i = 0;
        for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) {
            dataReg1[0][i] = d;
            dataReg1[1][i] = (1.0 - Math.exp(-d));
        }
        dsReg1.addSeries("", dataReg1);
        regressionRenderer.setBaseSeriesVisibleInLegend(true);
        regressionRenderer.setSeriesPaint(0, Color.RED);
        regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f));
        regressionRenderer.setBaseShapesVisible(false);
        plot.setDataset(1, dsReg1);
        plot.setRenderer(1, regressionRenderer);

        System.out.println("Writing image....");
        ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/dissimdist.png"), jChart2, 600, 400);

    } catch (Exception e) {
        System.out.println("Unable to generate charts 2 and 3:");
        e.printStackTrace(System.out);
    }
}

From source file:com.vgi.mafscaling.LogPlay.java

private void createPlayer(JPanel panel) {
    playerPanel = new JPanel();
    GridBagLayout gbl_playerPanel = new GridBagLayout();
    gbl_playerPanel.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 };
    gbl_playerPanel.rowHeights = new int[] { 0, 0, 0, 0 };
    gbl_playerPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
    gbl_playerPanel.rowWeights = new double[] { 0.0, 0.0 };
    playerPanel.setLayout(gbl_playerPanel);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.insets = insets0;//from  www  . j a v  a2  s  .  c o m
    gbc.anchor = GridBagConstraints.PAGE_START;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 0;
    gbc.gridy = 0;

    progressBar = new JSlider(0, 0, 0);
    progressBar.setMinimum(0);
    progressBar.setMaximum(lastRow);
    setProgressBar(logDataTable.getSelectedRow());
    progressBar.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            int row = progressBar.getValue();
            if (playing) {
                if (row == lastRow || (endPlay >= 0 && endPlay < row)) {
                    stop();
                    return;
                }
                if (showMarker) {
                    Rectangle2D dataArea = logView.getChartPanel().getChartRenderingInfo().getPlotInfo()
                            .getDataArea();
                    XYPlot plot = (XYPlot) logView.getChartPanel().getChart().getPlot();
                    double x = plot.getDomainAxis().valueToJava2D(row, dataArea, plot.getDomainAxisEdge());
                    boolean isLeft = (x < (dataArea.getMaxX() - dataArea.getMinX()) / 2) ? true : false;
                    logView.setMarkers(row, isLeft);
                }
            }
            logDataTable.getTable().setRowSelectionInterval(row, row);
            logDataTable.getTable().changeSelection(row, logDataTable.getSelectedColumn(), false, false);
            double x, y, z;
            int origXCol, origYCol, origZCol;
            synchronized (lock) {
                for (TableHolder tableHolder : tables) {
                    try {
                        origXCol = logDataTable.getCurrentIndexForOriginalColumn(tableHolder.xColIdx);
                        origYCol = logDataTable.getCurrentIndexForOriginalColumn(tableHolder.yColIdx);
                        origZCol = logDataTable.getCurrentIndexForOriginalColumn(tableHolder.zColIdx);
                        x = Double.valueOf(logDataTable.getValueAt(row, origXCol).toString());
                        y = Double.valueOf(logDataTable.getValueAt(row, origYCol).toString());
                        if (origZCol > 0)
                            z = Double.valueOf(logDataTable.getValueAt(row, origZCol).toString());
                        else
                            z = Double.NaN;
                        tableHolder.table.setCurrentPoint(x, y, z);
                    } catch (Exception ex) {
                        JOptionPane
                                .showMessageDialog(null,
                                        "Invalid numeric value in column " + (tableHolder.xColIdx + 1)
                                                + ", row " + (row + 1),
                                        "Invalid value", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }
            }
        }
    });
    gbc.weightx = 1.0;
    gbc.gridwidth = gbl_playerPanel.columnWidths.length;
    playerPanel.add(progressBar, gbc);

    stopButton = addPlayerButton(0, new ImageIcon(getClass().getResource("/stop.png")));
    rewButton = addPlayerButton(1, new ImageIcon(getClass().getResource("/rew.png")));
    playButton = addPlayerButton(2, playIcon);
    ffwButton = addPlayerButton(3, new ImageIcon(getClass().getResource("/ffw.png")));
    showIntepCells = addCheckBox(4, "Show interpolation cells");
    showSignifCells = addCheckBox(5, "Show significant cell");
    showTraceLine = addCheckBox(6, "Show trace line");
    showTraceMarker = addCheckBox(7, "Show plot trace marker");

    gbc.weightx = 0.0;
    gbc.gridwidth = 0;
    gbc.gridy = 1;
    panel.add(playerPanel, gbc);
}

From source file:speedbagalg.OscopeView.java

/**
 * Creates new form OscopeView//from  www  . ja va  2 s . co m
 */
/*    
    public OscopeView(String fileName)
    {
this.fileName = fileName;
initComponents();
updateThread = new RunnableMember2(this, "updateGUI");
ChartFactory.setChartTheme(new StandardChartTheme("JFree/Shadow", true));
// create a dataset...
int maxAge = 2400;
this.xData = new TimeSeries("X axis");
this.xData.setMaximumItemAge(maxAge);
this.yData = new TimeSeries("Y axis");
this.yData.setMaximumItemAge(maxAge);
this.zData = new TimeSeries("Z axis");
this.zData.setMaximumItemAge(maxAge);
this.averageData = new TimeSeries("Avg. Data");
this.averageData.setMaximumItemAge(maxAge);
//this.windSpeedSeries = new TimeSeries("Wind Speed");
//this.windSpeedSeries.setMaximumItemAge(maxAge);
//this.rainSeries = new TimeSeries("Rain 24hrs");
//this.rainSeries.setMaximumItemAge(maxAge);
        
final TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(xData);
dataset.addSeries(yData);
dataset.addSeries(zData);
dataset.addSeries(averageData);
        
//dataset.addSeries(windSpeedSeries);
//dataset.addSeries(rainSeries);
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Accel Data",
        "Time",
        "Value",
        dataset,
        true,
        true,
        false);
final XYPlot plot = chart.getXYPlot();
        
ValueAxis axis = plot.getDomainAxis();
axis.setAutoRange(true);
axis = plot.getRangeAxis();
axis.setRange(-1000.0, 10000.0);
        
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);
        
// create and display a frame...
thePanel = new ChartPanel(chart);
        
Dimension d = new Dimension(200, 100);
thePanel.setSize(d);
thePanel.setPreferredSize(d);
BorderLayout layout = new BorderLayout();
jPanelOscope.setLayout(layout);
jPanelOscope.add(thePanel, BorderLayout.CENTER);
        
plotXCheckBox.setSelected(plotX);
plotYCheckBox.setSelected(plotY);
plotZCheckBox.setSelected(plotZ);
    }
*/
public OscopeView(String fileName) {
    this.fileName = fileName;
    initComponents();
    updateThread = new RunnableMember2(this, "updateGUI");
    ChartFactory.setChartTheme(new StandardChartTheme("JFree/Shadow", true));
    // create a dataset...
    this.xData = new XYSeries("Min");
    //this.xData.setMaximumItemAge(maxAge);
    this.yData = new XYSeries("Peak");
    //this.yData.setMaximumItemAge(maxAge);
    this.zData = new XYSeries("Z axis");
    //this.zData.setMaximumItemAge(maxAge);
    this.averageData = new XYSeries("Avg. Data");
    //this.averageData.setMaximumItemAge(maxAge);
    //this.windSpeedSeries = new TimeSeries("Wind Speed");
    //this.windSpeedSeries.setMaximumItemAge(maxAge);
    //this.rainSeries = new TimeSeries("Rain 24hrs");
    //this.rainSeries.setMaximumItemAge(maxAge);

    final XYSeriesCollection dataset = new XYSeriesCollection();
    //SlidingCategoryDataset dataset = new SlidingCategoryDataset(0, 10);
    dataset.addSeries(xData);
    dataset.addSeries(yData);
    dataset.addSeries(zData);
    dataset.addSeries(averageData);

    //dataset.addSeries(windSpeedSeries);
    //dataset.addSeries(rainSeries);
    chart = ChartFactory.createXYLineChart("Accel Data", "Time", "Value", dataset, PlotOrientation.VERTICAL,
            true, true, false);
    final XYPlot plot = chart.getXYPlot();

    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(false);
    axis.setRange(minStart, maxDomain);
    axis = plot.getRangeAxis();
    axis.setRange(vMin, vMax);

    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);

    // create and display a frame...
    thePanel = new ChartPanel(chart);

    Dimension d = new Dimension(200, 100);
    thePanel.setSize(d);
    thePanel.setPreferredSize(d);
    BorderLayout layout = new BorderLayout();
    jPanelOscope.setLayout(layout);
    jPanelOscope.add(thePanel, BorderLayout.CENTER);

    plotXCheckBox.setSelected(plotX);
    plotYCheckBox.setSelected(plotY);
    plotZCheckBox.setSelected(plotZ);

    vMaxSpinner.setValue(vMax);
}

From source file:edu.ucla.stat.SOCR.chart.demo.BubbleChartDemo1.java

/**
 * Creates a chart./*from   w w  w.j av a2  s  .com*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(XYZDataset dataset) {
    JFreeChart chart = ChartFactory.createBubbleChart(chartTitle, domainLabel, rangeLabel, dataset,
            PlotOrientation.VERTICAL, !legendPanelOn, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(0.65f);

    //    SOCRBubbleRenderer renderer = new SOCRBubbleRenderer(dataset);
    //    plot.setRenderer((XYItemRenderer)renderer);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setLegendItemLabelGenerator(new SOCRScaledBubbleSeriesLabelGenerator(zScale));

    // increase the margins to account for the fact that the auto-range 
    // doesn't take into account the bubble size...
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setLowerMargin(0.15);
    domainAxis.setUpperMargin(0.15);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);
    return chart;
}

From source file:kardex.graficakardex.java

public graficakardex() {
    datosxy.removeAllSeries();//  w  w  w .  java2  s. co m
    //sxy.add(x[0], y[0]);
    y = new double[kardex.valor.length];
    y = kardex.valor;
    int n = y.length;
    for (int i = 0; i < n; i++) {
        sxy.add(i, y[i]);
        // System.out.print(x[i]+"-"+i+" ");
    }
    datosxy.addSeries(sxy);
    graficaxy = ChartFactory.createXYLineChart("Grafica de Stock de Producto", "transacciones", "cantidades",
            datosxy, PlotOrientation.VERTICAL, true, true, true);
    graficaxy.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) graficaxy.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);

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    configurarDomainAxis(domainAxis);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }
}

From source file:com.haskins.cloudtrailviewer.feature.MetricsFeature.java

private void showChart(String service) {

    final TimeSeriesCollection chartData = generateTimeSeriesData(service);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(service, "Time", "Calls", chartData, false, true,
            false);/*from www  . j a va  2  s . com*/

    // draw outter line
    XYLineAndShapeRenderer lineAndShapeRenderer = new XYLineAndShapeRenderer();
    lineAndShapeRenderer.setPaint(new Color(64, 168, 228, 75));
    lineAndShapeRenderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 6, 6));
    lineAndShapeRenderer.setSeriesShapesFilled(0, true);
    lineAndShapeRenderer.setSeriesShapesVisible(0, true);
    lineAndShapeRenderer.setUseOutlinePaint(true);
    lineAndShapeRenderer.setUseFillPaint(true);

    // draw filled area
    XYAreaRenderer renderer = new XYAreaRenderer();
    renderer.setPaint(new Color(64, 168, 228, 50));

    // configure Plot
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlineVisible(false);

    plot.setDataset(0, chartData);
    plot.setDataset(1, chartData);

    plot.setRenderer(0, lineAndShapeRenderer);
    plot.setRenderer(1, renderer);

    plot.getDomainAxis().setLowerMargin(0);
    plot.getDomainAxis().setUpperMargin(0);

    // format chart title
    TextTitle t = chart.getTitle();
    t.setFont(new Font("Arial", Font.BOLD, 14));

    // Cross Hairs
    xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f));
    xCrosshair.setLabelVisible(true);
    xCrosshair.setLabelGenerator(new DateTimeCrosshairLabelGenerator());

    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    crosshairOverlay.addDomainCrosshair(xCrosshair);

    // Create the panel
    chartPanel = new ChartPanel(chart);
    chartPanel.setMinimumDrawWidth(0);
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    chartPanel.setMinimumDrawHeight(0);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    chartPanel.setMouseZoomable(true, false);
    chartPanel.setDomainZoomable(true);
    chartPanel.setRangeZoomable(false);
    chartPanel.addChartMouseListener(this);
    chartPanel.addOverlay(crosshairOverlay);

    // update the display
    chartCards.removeAll();
    chartCards.add(chartPanel, "");
    chartCards.revalidate();
}

From source file:entrenamiento.grafica.java

public grafica() {
    XYSeries sxy = new XYSeries("pesos");
    datosxy.removeAllSeries();//from  w ww .  ja v a2  s  . c o m
    //sxy.add(x[0], y[0]);
    y = new double[Entrenamiento.valor.length];
    y = Entrenamiento.valor;
    int n = y.length;
    for (int i = 0; i < n; i++) {
        sxy.add(i, y[i]);
        // System.out.print(x[i]+"-"+i+" ");
    }
    datosxy.addSeries(sxy);
    graficaxy = ChartFactory.createXYLineChart("Grafica de Progreso", "tiempo", "RM-pesos", datosxy,
            PlotOrientation.VERTICAL, true, true, true);
    graficaxy.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) graficaxy.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);

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    configurarDomainAxis(domainAxis);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }
}