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:iad_zad3.gui.Charts.java

public static JFreeChart getKmeansChart(final List<double[]> data, final List<double[]> centroids) {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("", "x", "y", createDataset(data, centroids),
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesShape(1, circleSmall);
    renderer.setSeriesPaint(1, Color.RED);
    renderer.setSeriesShape(0, circleBig);
    renderer.setSeriesPaint(0, Color.BLUE);
    ValueAxis domainAxis = xyPlot.getDomainAxis();
    domainAxis.setRange(DataStats.minVal[0] * 1.2, DataStats.maxVal[0] * 1.2);
    ValueAxis rangeAxis = xyPlot.getRangeAxis();
    rangeAxis.setRange(DataStats.minVal[1] * 1.2, DataStats.maxVal[1] * 1.2);
    jfreechart.setBackgroundPaint(Color.WHITE);
    return jfreechart;
}

From source file:unalcol.termites.boxplots.HybridGlobalInfoReport.java

private static void createChart(Hashtable<String, XYSeriesCollection> dataCollected) {
    System.out.println("dc" + dataCollected);
    for (String key : dataCollected.keySet()) {
        JFreeChart chart = ChartFactory.createXYLineChart(key, "Round number", "GlobalInfo",
                dataCollected.get(key), PlotOrientation.VERTICAL, true, true, false);

        XYPlot xyPlot = (XYPlot) chart.getPlot();
        NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
        domain.setRange(0.0, 10000.0);//from w w  w . j  a  v a2  s  . c  o  m

        FileOutputStream output;
        try {
            System.out.println("Key: " + key);
            output = new FileOutputStream(key + mazeMode + ".jpg");
            ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null);

        } catch (FileNotFoundException ex) {
            Logger.getLogger(ECALAgentsRight.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ECALAgentsRight.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:ec.ui.view.ARPView.java

static JFreeChart createARPChart() {
    JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);
    result.getTitle().setFont(TsCharts.CHART_TITLE_FONT);

    XYPlot plot = result.getXYPlot();

    plot.setNoDataMessage("Drop data here");
    plot.getRangeAxis().setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.getDomainAxis().setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);

    ((XYLineAndShapeRenderer) plot.getRenderer()).setAutoPopulateSeriesPaint(false);

    return result;
}

From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java

private static void formatColorTheme(JFreeChart chart, ColorTheme theme) {
    Plot rawPlot = chart.getPlot();//w  w  w .  j  ava2s . co  m

    Paint background = Color.BLACK;
    Paint foregroung = Color.WHITE;
    if (theme == ColorTheme.LIGHT) {
        background = Color.WHITE;
        foregroung = Color.BLACK;
    }

    chart.setBackgroundPaint(background);
    chart.getLegend().setBackgroundPaint(background);
    chart.getLegend().setItemPaint(foregroung);

    if (rawPlot instanceof XYPlot) {
        XYPlot plot = (XYPlot) rawPlot;
        plot.getDomainAxis().setLabelPaint(foregroung);
        plot.getRangeAxis().setLabelPaint(foregroung);
        plot.getDomainAxis().setTickLabelPaint(foregroung);
        plot.getDomainAxis().setTickMarkPaint(foregroung);
        plot.getRangeAxis().setTickLabelPaint(foregroung);
        plot.getRangeAxis().setTickMarkPaint(foregroung);
        plot.setBackgroundPaint(background);
        plot.setDomainGridlinePaint(foregroung);
        plot.setRangeGridlinePaint(foregroung);
    }
    if (rawPlot instanceof CategoryPlot) {
        CategoryPlot plot = (CategoryPlot) rawPlot;
        plot.getDomainAxis().setLabelPaint(foregroung);
        plot.getRangeAxis().setLabelPaint(foregroung);
        plot.getDomainAxis().setTickLabelPaint(foregroung);
        plot.getDomainAxis().setTickMarkPaint(foregroung);
        plot.getRangeAxis().setTickLabelPaint(foregroung);
        plot.getRangeAxis().setTickMarkPaint(foregroung);
        plot.setBackgroundPaint(background);
        plot.setDomainGridlinePaint(foregroung);
        plot.setRangeGridlinePaint(foregroung);
    }
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset("March 2007", 100D, new Day(1, 3, 2007), 31);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 4", "Date", "Value",
            xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setOrientation(PlotOrientation.VERTICAL);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("d-MMM-yyyy"));
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.red);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setTickLabelPaint(Color.red);
    DateAxis dateaxis1 = new DateAxis("Date");
    dateaxis1.setDateFormatOverride(new SimpleDateFormat("d-MMM-yyyy"));
    xyplot.setDomainAxis(1, dateaxis1);/*w w  w . j  a v a2  s .c o m*/
    xyplot.setDomainAxisLocation(1, AxisLocation.TOP_OR_LEFT);
    NumberAxis numberaxis1 = new NumberAxis("Value");
    numberaxis1.setAutoRangeIncludesZero(false);
    numberaxis1.setTickLabelPaint(Color.blue);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    XYDataset xydataset1 = createDataset("July 2007", 1000D, new Day(1, 7, 2007), 31);
    xyplot.setDataset(1, xydataset1);
    xyplot.mapDatasetToDomainAxis(1, 1);
    xyplot.mapDatasetToRangeAxis(1, 1);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
    xylineandshaperenderer.setSeriesPaint(0, Color.blue);
    xyplot.setRenderer(1, xylineandshaperenderer);
    return jfreechart;
}

From source file:org.encog.workbench.dialogs.activation.EquationPanel.java

/**
 * Creates a line chart using the data from the supplied dataset.
 *
 * @param dataset  the dataset./*from  w  w w  . j  a v  a  2 s .c o  m*/
 *
 * @return The chart.
 */
public static JFreeChart createChart(XYDataset dataset, ActivationFunction activation, boolean normal) {

    String title;

    if (normal) {
        title = activation.getClass().getSimpleName();
    } else {
        if (activation.hasDerivative()) {
            title = "Derv of " + activation.getClass().getSimpleName();
        } else {
            title = "NO Derv of " + activation.getClass().getSimpleName();
        }
    }

    JFreeChart chart = ChartFactory.createXYLineChart(title, "input (x)", "output (y)", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();

    if (normal) {

        plot.setDomainZeroBaselineVisible(true);
        plot.setRangeZeroBaselineVisible(true);
        plot.setDomainPannable(true);
        plot.setRangePannable(true);
        ValueAxis xAxis = plot.getDomainAxis();
        xAxis.setLowerMargin(0.0);
        xAxis.setUpperMargin(0.0);
        XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
        r.setDrawSeriesLineAsPath(true);
        r.setSeriesStroke(0, new BasicStroke(1.5f));
        r.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 6.0f, 4.0f }, 0.0f));
        r.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 6.0f, 4.0f, 3.0f, 3.0f }, 0.0f));
        r.setSeriesStroke(3, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 4.0f, 4.0f }, 0.0f));
    }

    return chart;
}

From source file:com.orange.atk.results.logger.documentGenerator.GraphGenerator.java

/**
 * This function creates the measurement graph by using the JFreeChart
 * library. The X axis of the graph is in minutes.
 * //from   w  w w .j  a  v a2 s.  co m
 * @param plotList
 *            plotlist to save. Xvalues must be stored in milliseconds.
 * @param associatedName
 *            Name of the list
 * @param folderWhereResultsAreSaved
 *            folder where results are saved
 * @param yLabel
 *            Name of the y label
 * @param pictureFile
 *            name of the file
 * @param yDivisor
 *            use to divide measurements stored in the plotlist by yDivisor
 */
public static void generateGraphWithJFreeChart(PlotList plotList, String associatedName,
        String folderWhereResultsAreSaved, String yLabel, String pictureFile, float yDivisor) {

    // Create a new XYSeries
    // XYSeries are used to represent couples of (x,y) values.
    XYSeries data = new XYSeries(associatedName);

    int size = plotList.getSize();
    if (size == 0) {
        // no element in graphics, exit
        //Logger.getLogger(this.getClass() ).warn("Nothing in graph");
        return;
    }

    // Find the initial value of the time
    // Due to the fact that getX(i) <= getX(i+1),
    // min({0<=i<size / getX(i)}) = getX(0)
    long initialValue = plotList.getX(0);

    XYSeriesCollection series = new XYSeriesCollection(data);
    if (!plotList.getunit().equals(""))
        yLabel += " (" + plotList.getunit() + ")";
    // Create a new XY graph.
    //JFreeChart chart = ChartFactory.createXYLineChart("", "Time", yLabel, series, PlotOrientation.VERTICAL, true, true, false);
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", "Time (min:sec)", yLabel, series, true, true,
            false);
    // Set the graph format
    XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    //axis.setTickUnit(new DateTickUnit(DateTickUnit.SECOND, 10));
    RelativeDateFormat rdf = new RelativeDateFormat(initialValue);
    rdf.setSecondFormatter(new DecimalFormat("00"));
    axis.setDateFormatOverride(rdf);

    // Fill the JFreeChart object which will be used to create the Graph
    for (int i = 0; i < size; i++) {
        // xvalue must be in
        double xval = ((Long) plotList.getX(i)).doubleValue();
        float yval = plotList.getY(i).floatValue() / yDivisor;
        // Logger.getLogger(this.getClass() ).debug(associatedName + " [" + (((Long)
        // plotList.getX(i)).floatValue() - initialValue)
        // / XDIVISOR +"] "+ yval);
        data.add(xval, yval);
    }

    ValueAxis rangeAxis = plot.getRangeAxis();
    Long min = plotList.getMin();
    Long max = plotList.getMax();
    double diff = (max - min) * 0.02;
    if (diff == 0)
        diff = max * 0.0001;

    rangeAxis.setLowerBound((min - diff) / yDivisor);
    rangeAxis.setUpperBound((max + diff) / yDivisor);
    //      Logger.getLogger(this.getClass() ).debug("(" + (min / yDivisor) * 0.98 + " - "
    //            + (min / yDivisor) * 0.98 + ")");
    //      Logger.getLogger(this.getClass() ).debug("Bound = " + rangeAxis.getLowerBound() + " - "
    //            + rangeAxis.getUpperBound());
    //      Logger.getLogger(this.getClass() ).debug("Margin = " + rangeAxis.getLowerMargin() + " - "
    //            + rangeAxis.getUpperMargin());
    //      Logger.getLogger(this.getClass() ).debug("NB AXIS = " + plot.getRangeAxisCount());

    // save the chart in a picture file.
    BufferedImage bufImage = chart.createBufferedImage(640, 480);
    File fichier = new File(pictureFile);
    try {
        if (!ImageIO.write(bufImage, "png", fichier)) {
            return;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("Scatter Plot Demo 1", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, false, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setNoDataMessage("NO DATA");
    xyplot.setDomainZeroBaselineVisible(true);
    xyplot.setRangeZeroBaselineVisible(true);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setSeriesOutlinePaint(0, Color.black);
    xylineandshaperenderer.setUseOutlinePaint(true);
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    numberaxis.setTickMarkInsideLength(2.0F);
    numberaxis.setTickMarkOutsideLength(0.0F);
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setTickMarkInsideLength(2.0F);
    numberaxis1.setTickMarkOutsideLength(0.0F);
    return jfreechart;
}

From source file:com.compomics.pepshell.view.statistics.JFreeChartPanel.java

private static void setupPlot(XYPlot xYPlot) {
    // set background to white and grid color to black
    xYPlot.setBackgroundPaint(Color.white);
    xYPlot.setRangeGridlinePaint(Color.black);
    // hide the border of the sorrounding box
    xYPlot.setOutlinePaint(Color.white);
    // get domanin and range axes
    ValueAxis domainAxis = xYPlot.getDomainAxis();
    ValueAxis rangeAxis = xYPlot.getRangeAxis();
    // set label paint for axes to black
    domainAxis.setLabelPaint(Color.black);
    rangeAxis.setLabelPaint(Color.black);
    // set font for labels, both on domain and range axes
    domainAxis.setLabelFont(new Font("Tahoma", Font.BOLD, 12));
    rangeAxis.setLabelFont(new Font("Tahoma", Font.BOLD, 12));
}

From source file:PerformanceGraph.java

/**
 * Plots the performance graph of the best fitness value so far versus the
 * number of function calls (NFC)./*from   w ww .j a v a  2s.com*/
 * 
 * @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();
    }*/
}