Example usage for org.jfree.chart.renderer.xy XYItemRenderer setPaint

List of usage examples for org.jfree.chart.renderer.xy XYItemRenderer setPaint

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYItemRenderer setPaint.

Prototype

public void setPaint(Paint paint);

Source Link

Document

Sets the paint to be used for ALL series, and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:PerformanceGraph.java

/**
 * Plots the performance graph of the best fitness value so far versus the
 * number of function calls (NFC)./*from www  . ja  v  a2  s. c  o m*/
 * 
 * @param bestFitness A linked hashmap mapping the NFC to the best fitness value
 * found so far.
 * @param fitnessFunction The name of the fitness function, used for the title and the
 * name of the file that is saved, e.g. "De Jong".
 */
public static void plot(LinkedHashMap<Integer, Double> bestFitness, String fitnessFunction) {
    /* Create an XYSeries plot */
    XYSeries series = new XYSeries("Best Fitness Value Vs. Number of Function Calls");

    /* Add the NFC and best fitness value data to the series */
    for (Integer NFC : bestFitness.keySet()) {
        /* Jfreechart crashes if double values are too large! */
        if (bestFitness.get(NFC) <= 10E12) {
            series.add(NFC.doubleValue(), bestFitness.get(NFC).doubleValue());
        }
    }

    /* Add the x,y series data to the dataset */
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);

    /* Plot the data as an X,Y line chart */
    JFreeChart chart = ChartFactory.createXYLineChart("Best Fitness Value Vs. Number of Function Calls",
            "Number of Function Calls (NFC)", "Best Fitness Value", dataset, PlotOrientation.VERTICAL, false,
            true, false);

    /* Configure the chart settings such as anti-aliasing, background colour */
    chart.setAntiAlias(true);

    XYPlot plot = chart.getXYPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);
    plot.setDomainGridlinePaint(Color.black);

    /* Set the domain range from 0 to NFC */
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(0.0, ControlVariables.MAX_FUNCTION_CALLS.doubleValue());

    /* Logarithmic range axis */
    plot.setRangeAxis(new LogAxis());

    /* Set the thickness and colour of the lines */
    XYItemRenderer renderer = plot.getRenderer();
    BasicStroke thickLine = new BasicStroke(3.0f);
    renderer.setSeriesStroke(0, thickLine);
    renderer.setPaint(Color.BLACK);

    /* Display the plot in a JFrame */
    ChartFrame frame = new ChartFrame(fitnessFunction + " Best Fitness Value", chart);
    frame.setVisible(true);
    frame.setSize(1000, 600);

    /* Save the plot as an image named after fitness function
    try
    {
       ChartUtilities.saveChartAsJPEG(new File("plots/" + fitnessFunction + ".jpg"), chart, 1600, 900);
    }
    catch (IOException e)
    {
       e.printStackTrace();
    }*/
}

From source file:net.vanosten.dings.swing.SummaryView.java

public void displayTimeSeriesChart(final TimeSeriesCollection averageScore, final int maxScoreRange,
        final TimeSeriesCollection numberOfEntries, final int maxTotalRange) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series", "Date", "Average Score",
            averageScore, true, true, false);

    chart.setBackgroundPaint(Color.white);
    final XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYItemRenderer renderer1 = plot.getRenderer();
    renderer1.setPaint(Color.blue);

    //axis 1//w ww. j ava2s  .c o m
    final NumberAxis axis1 = new NumberAxis("Average Score");
    axis1.setLabelPaint(Color.blue);
    axis1.setTickLabelPaint(Color.blue);
    axis1.setRange(0.0d, maxScoreRange + 1);
    plot.setRangeAxis(0, axis1);

    //axis 2
    final NumberAxis axis2 = new NumberAxis("Number of Entries");
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    axis2.setRange(0.0d, 10 * (((int) (maxTotalRange / 10)) + 1));
    plot.setRangeAxis(1, axis2);

    plot.setDataset(1, numberOfEntries);
    plot.mapDatasetToRangeAxis(1, 1);
    final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setPaint(Color.red);
    plot.setRenderer(1, renderer2);

    placeChart(chart);
}

From source file:org.vast.stt.renderer.JFreeChart.XYPlotBuilder.java

public void visit(LineStyler styler) {
    styler.resetIterators();//from w ww  .j  a  va  2s  .  c  o m
    if (styler.getNumPoints() == 0)
        return;

    // create dataset and renderer
    XYDataset dataset = new ChartXYDataset(currentItem.getName(), styler);
    XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES);

    // curve color and width
    LinePointGraphic point = styler.getPoint(0);
    renderer.setPaint(new Color(point.r, point.g, point.b, point.a));
    renderer.setStroke(new BasicStroke(point.width));

    // add new dataset and corresponding renderer and range axis
    addDataSet(dataset, renderer);
}

From source file:org.vast.stt.renderer.JFreeChart.XYPlotBuilder.java

public void visit(PointStyler styler) {
    styler.resetIterators();/*  w  w w .  j  av a2 s  . com*/
    if (styler.getNumPoints() == 0)
        return;

    // create dataset and renderer            
    XYDataset dataset = new ChartXYDataset(currentItem.getName(), styler);
    XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);

    // point color and size
    PointGraphic point = styler.getPoint(0);
    renderer.setPaint(new Color(point.r, point.g, point.b, point.a));

    // point shape
    Shape shape = null;
    switch (point.shape) {
    case SQUARE:
        shape = new Rectangle2D.Float(-point.size / 2, -point.size / 2, point.size, point.size);
        break;

    case CIRCLE:
        shape = new Ellipse2D.Float(-point.size / 2, -point.size / 2, point.size, point.size);
        break;

    case TRIANGLE:
        int[] xPoints = new int[] { -(int) point.size / 2, 0, (int) point.size / 2 };
        int[] yPoints = new int[] { (int) point.size / 2, -(int) point.size / 2, (int) point.size / 2 };
        shape = new Polygon(xPoints, yPoints, 3);
        break;
    }
    renderer.setShape(shape);

    // add new dataset and corresponding renderer and range axis
    addDataSet(dataset, renderer);
}