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:richclient.EvolutionChart.java

/**
 * Creates a chart./*from w  w w .jav a  2 s . c om*/
 *
 * @param dataset the data for the chart.
 *
 * @return a chart.
 */
public JFreeChart createChart(XYDataset dataset) {

    // create the chart
    final JFreeChart chart = ChartFactory.createXYLineChart("Market evolution", // chart title
            "Time", // x axis label
            "Value", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);
    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(1, true);
    plot.setRenderer(renderer);

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

    return chart;

}

From source file:IHM.compargraph.java

/**
 *
 * @param title/*www.ja va  2  s  .  co m*/
 * @param c1
 * @param c2
 * @param comp
 * 
 */
public compargraph(String title, ArrayList<ReleveMeteo> c1, ArrayList<ReleveMeteo> c2, String comp) {
    super(title);
    t1 = c1;
    t2 = c2;
    c = comp;

    // jp = new JInternalFrame("courbes");

    JFreeChart chart = createChart(createDataset());
    ChartPanel panel = new ChartPanel(chart);
    panel.setPreferredSize(new Dimension(500, 300));
    setContentPane(panel);
    //  jp.add(panel, BorderLayout.EAST);
    //  jp.setVisible(true);
    panel.setVisible(true);
    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.YELLOW);
    // sets thickness for series (using strokes)
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setRenderer(renderer);
    plot.setOutlinePaint(Color.BLUE);
    plot.setOutlineStroke(new BasicStroke(2.0f));
    plot.setBackgroundPaint(Color.DARK_GRAY);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.BLACK);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.BLACK);

}

From source file:org.gwaspi.reports.GenericReportGenerator.java

public static XYPlot buildQQPlot(OperationKey testOpKey, int df) throws IOException {

    if (df != 1 && df != 2) {
        throw new IllegalArgumentException("Only df = 1 or 2 is supported; it is " + df);
    }/*from w  w w  .  ja va  2  s  .com*/

    //<editor-fold defaultstate="expanded" desc="PLOT DEFAULTS">
    final Config config = Config.getSingleton();
    final Color background = config.getColor(PLOT_QQ_BACKGROUND_CONFIG, PLOT_QQ_BACKGROUND_DEFAULT);
    final Color actual = config.getColor(PLOT_QQ_ACTUAL_CONFIG, PLOT_QQ_ACTUAL_DEFAULT);
    final Color sigma = config.getColor(PLOT_QQ_SIGMA_CONFIG, PLOT_QQ_SIGMA_DEFAULT);
    final Color mu = config.getColor(PLOT_QQ_MU_CONFIG, PLOT_QQ_MU_DEFAULT);
    //</editor-fold>

    //<editor-fold defaultstate="expanded" desc="GET X^2">
    List<Double> obsChiSqrVals = assembleQQPlotData(testOpKey);

    int N = obsChiSqrVals.size();
    List<Double> expChiSqrDist;
    if (df == 1) {
        expChiSqrDist = Chisquare.getChiSquareDistributionDf1(N, 1.0f);
    } else { // df == 2
        expChiSqrDist = Chisquare.getChiSquareDistributionDf2(N, 1.0f);
    }
    Collections.sort(expChiSqrDist);
    //</editor-fold>

    //<editor-fold defaultstate="expanded" desc="GET CONFIDENCE BOUNDARY">
    InputStream boundaryStream = GenericReportGenerator.class
            .getResourceAsStream("/samples/chisqrboundary-df" + df + ".txt");
    InputStreamReader isr = new InputStreamReader(boundaryStream);
    BufferedReader inputBufferReader = new BufferedReader(isr);

    Double stopValue = expChiSqrDist.get(N - 1);
    Double currentValue = 0d;
    List<Double[]> boundary = new ArrayList<Double[]>();
    while (currentValue <= stopValue) {
        String l = inputBufferReader.readLine();
        if (l == null) {
            break;
        }
        String[] cVals = l.split(",");
        Double[] slice = new Double[3];
        slice[0] = Double.parseDouble(cVals[0]);
        slice[1] = Double.parseDouble(cVals[1]);
        slice[2] = Double.parseDouble(cVals[2]);
        currentValue = slice[1];
        boundary.add(slice);
    }
    inputBufferReader.close();
    //</editor-fold>

    XYSeriesCollection dataSeries = new XYSeriesCollection();
    XYSeries seriesData = new XYSeries("X");
    XYSeries seriesRef = new XYSeries("Expected");

    for (int i = 0; i < obsChiSqrVals.size(); i++) {
        double obsVal = obsChiSqrVals.get(i);
        double expVal = expChiSqrDist.get(i);

        seriesData.add(expVal, obsVal);
        seriesRef.add(expVal, expVal);
    }

    //constant chi-square boundaries
    XYSeries seriesLower = new XYSeries("2 boundary");
    XYSeries seriesUpper = new XYSeries("");
    for (Double[] slice : boundary) {
        seriesUpper.add(slice[1], slice[0]);
        seriesLower.add(slice[1], slice[2]);
    }

    dataSeries.addSeries(seriesData);
    dataSeries.addSeries(seriesRef);
    dataSeries.addSeries(seriesUpper);
    dataSeries.addSeries(seriesLower);
    final XYDataset data = dataSeries;

    //create QQ plot
    final boolean withLegend = true;
    JFreeChart chart = ChartFactory.createScatterPlot("QQ-plot", "Exp X", "Obs X", data,
            PlotOrientation.VERTICAL, withLegend, false, false);

    final XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
    renderer.setSeriesPaint(0, actual);
    renderer.setSeriesPaint(1, mu);
    renderer.setSeriesPaint(2, sigma);
    renderer.setSeriesPaint(3, sigma);

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0));
    renderer.setSeriesShape(1, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0));
    renderer.setSeriesShape(2, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0));
    renderer.setSeriesShape(3, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0));

    plot.setRenderer(renderer);

    // PLOT BACKGROUND COLOR
    plot.setBackgroundPaint(background); // Hue, saturation, brightness

    return plot;
}

From source file:com.romraider.logger.ecu.ui.tab.LoggerChartPanel.java

private void configurePlot(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(BLACK);//w ww. j av a 2 s.co  m
    plot.getDomainAxis().setLabelPaint(WHITE);
    plot.getRangeAxis().setLabelPaint(WHITE);
    plot.getDomainAxis().setTickLabelPaint(LIGHT_GREY);
    plot.getRangeAxis().setTickLabelPaint(LIGHT_GREY);
    plot.setDomainGridlinePaint(DARK_GREY);
    plot.setRangeGridlinePaint(DARK_GREY);
    plot.setOutlinePaint(DARK_GREY);
    plot.setRenderer(buildScatterRenderer(2, RED));
}

From source file:statUtil.TurnMovementPlot.java

public TurnMovementPlot(String title) throws IOException {
    super(title);
    Data data = CSVData.getCSVData(TURN_CSV_LOG);
    JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y",
            XYDatasetGenerator.generateXYDataset(data.csvData));
    final XYPlot xyPlot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesStroke(0, new BasicStroke(3f));
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, true);
    Shape cross = ShapeUtilities.createDiagonalCross(2f, 0.5f);
    renderer.setSeriesShape(1, cross);//from  w  ww  . ja v a  2  s  . c  om
    xyPlot.setRenderer(renderer);
    xyPlot.setQuadrantOrigin(new Point(0, 0));

    int i = 0;
    for (Double[] csvRow : data.csvData) {
        if (i % 20 == 1) {
            final XYTextAnnotation annotation = new XYTextAnnotation(Double.toString(csvRow[3]), csvRow[0],
                    csvRow[1]);
            annotation.setFont(new Font("SansSerif", Font.PLAIN, 10));
            xyPlot.addAnnotation(annotation);
        }
        i++;
    }

    int width = (int) Math.round(data.maxX - data.minX) + 50;
    int height = (int) Math.round(data.maxY - data.minY) + 50;
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(width, height));
    setContentPane(chartPanel);
    File XYChart = new File(FILE_PATH + "\\TurnMovementPlot.png");
    ChartUtilities.saveChartAsPNG(XYChart, chart, width, height);
}

From source file:carfuzzy.Operations.java

public JFreeChart drawAggregation(FIS[] fis) {

    XYSeriesCollection aggregationDataset = new XYSeriesCollection();
    for (int i = 0; i < 4; i++) {
        aggregationDataset.addSeries(fis[i].getImplication());
    }//w w  w. j  a v  a2  s. co  m
    //aggregationDataset.getSeries(0).setKey("Agjujugregation");
    JFreeChart chart = setToChart(aggregationDataset, "Aggregation");

    XYPlot plot = chart.getXYPlot();
    XYAreaRenderer renderer = new XYAreaRenderer();
    renderer.setSeriesVisibleInLegend(false, true);
    renderer.setSeriesItemLabelsVisible(0, false, true);
    renderer.setSeriesItemLabelsVisible(3, true);
    renderer.setPaint(Color.RED.darker(), true);
    plot.setRenderer(renderer);
    ValueAxis xaxis = plot.getDomainAxis();
    xaxis.setRange(0, 10);
    return chart;
}

From source file:org.deegree.graphics.charts.ChartsBuilder.java

/**
 * Configures the pie chart according to the stored configurations file
 *
 * @param chart//  w  w w  . j a  v a  2  s  .  co m
 * @param chartConfigs
 *            to configure the output chart
 * @return configured JFreeChart
 */
protected JFreeChart configLineChart(JFreeChart chart, ChartConfig chartConfigs) {

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(chartConfigs.isLineRenderLines(),
            chartConfigs.isLineRenderShapes());

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(renderer);
    return chart;
}

From source file:com.seniorproject.augmentedreality.test.LineChartDemo6.java

/**
 * Creates a chart.//  ww w  .ja v a2s .co m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart Demo 6", // 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...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

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

    return chart;

}

From source file:org.deegree.graphics.charts.ChartsBuilder.java

/**
 * Creates an XY Line chart/*www  . ja v a 2  s.  c  o m*/
 *
 * @param title
 * @param keyedValues
 *            key is the category name, value is a series tupels Format: key = x1,y1;x2,y2;x3,y3 Example row1 =
 *            2,3;4,10 Note that x and y have to be numbers
 * @param width
 *            of the output image
 * @param height
 *            height of the output image
 * @param legend
 *            for the output chart
 * @param tooltips
 *            for the output de.latlon.charts
 * @param orientation
 *            Horiyontal or vertical chart
 * @param imageType
 *            of the output image
 * @param horizontalAxisName
 *            Name of the Horizontal Axis
 * @param verticalAxisName
 *            Name of the vertical Axis
 * @param chartConfigs
 *            to configure the output chart, or null to use the default ChartConfig
 * @return BufferedImage representing the generated chart
 * @throws IncorrectFormatException
 */
public BufferedImage createXYLineChart(String title, QueuedMap<String, String> keyedValues, int width,
        int height, boolean legend, boolean tooltips, int orientation, String imageType,
        String horizontalAxisName, String verticalAxisName, ChartConfig chartConfigs)
        throws IncorrectFormatException {
    XYDataset dataset = convertMapToXYSeriesDataSet(keyedValues);

    JFreeChart chart = null;
    chart = ChartFactory.createXYLineChart(title, horizontalAxisName, verticalAxisName, dataset,
            translateToPlotOrientation(orientation), legend, tooltips, false);

    XYSplineRenderer renderer = new XYSplineRenderer();
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(renderer);
    if (chartConfigs == null) {
        chartConfigs = this.chartConfigs;
    }
    return createBufferedImage(configLineChart(chart, chartConfigs), width, height, imageType);
}

From source file:flexflux.analyses.result.ParetoAnalysisResult.java

public void plot() {

    XYSeriesCollection dataset = new XYSeriesCollection();

    int i = 1;/*from  w  w  w. ja va 2 s .  c om*/
    for (Objective obj : oneDResults.keySet()) {

        XYSeries series = new XYSeries(obj.getName());

        for (double val : oneDResults.get(obj)) {

            series.add(i, val);
        }

        dataset.addSeries(series);
        i++;
    }

    // create the chart...

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

    ChartPanel chartPanel = new ChartPanel(chart);

    XYPlot plot = chart.getXYPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setDomainGridlinePaint(Color.GRAY);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(false);
    renderer.setShapesVisible(true);
    plot.setRenderer(renderer);

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

    JFrame frame = new JFrame("Pareto analysis one dimension results");
    frame.add(chartPanel);

    frame.pack();

    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setVisible(true);

    for (PP2DResult r : twoDResults.keySet()) {

        r.plot();

    }

    for (PP3DResult r : threeDResults.keySet()) {

        r.plot();

    }

}