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

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

Introduction

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

Prototype

public void setDomainAxis(ValueAxis axis) 

Source Link

Document

Sets the domain axis for the plot and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaActivityWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 *///from   w  w  w.j  av  a  2  s .co  m
private JFreeChart getGraphic(int[] activities, int[] activitiesParticipatingAtHome,
        int[] activitiesParticipatingNotAtHome, int[] activitiesNotParticipatingAtHome,
        int[] activitiesNotParticipatingNotAtHome) {

    final XYSeriesCollection xyData = new XYSeriesCollection();
    XYSeries dataSerie;

    dataSerie = new XYSeries("total activity performing agents in evacuated area", false, true);
    for (int i = 0; i < activities.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, activities[i]);
    }
    xyData.addSeries(dataSerie);

    dataSerie = new XYSeries("participating agents performing a home activity in evacuated area", false, true);
    for (int i = 0; i < activitiesParticipatingAtHome.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, activitiesParticipatingAtHome[i]);
    }
    xyData.addSeries(dataSerie);

    dataSerie = new XYSeries("participating agents performing an other activity in evacuated area", false,
            true);
    for (int i = 0; i < activitiesParticipatingNotAtHome.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, activitiesParticipatingNotAtHome[i]);
    }
    xyData.addSeries(dataSerie);

    dataSerie = new XYSeries("not participating agents performing a home activity in evacuated area", false,
            true);
    for (int i = 0; i < activitiesNotParticipatingAtHome.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, activitiesNotParticipatingAtHome[i]);
    }
    xyData.addSeries(dataSerie);

    dataSerie = new XYSeries("not participating agents performing an other activity in evacuated area", false,
            true);
    for (int i = 0; i < activitiesNotParticipatingNotAtHome.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, activitiesNotParticipatingNotAtHome[i]);
    }
    xyData.addSeries(dataSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart(
            "activity performing agents in evacuated area, it." + this.iteration, "time", "# agents", xyData,
            PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}

From source file:playground.dgrether.analysis.categoryhistogram.CategoryHistogramWriter.java

public JFreeChart getGraphic(final CategoryHistogram histo, final String modeName) {
    this.checkIndex(histo);
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries departuresSerie = new XYSeries(this.departuresName, false, true);
    final XYSeries arrivalsSerie = new XYSeries(this.arrivalsName, false, true);
    final XYSeries onRouteSerie = new XYSeries(this.enRouteName, false, true);
    Integer enRoute = 0;//from  w w  w  .ja va 2s.co  m
    for (int i = histo.getFirstIndex() - 2; i <= histo.getLastIndex() + 2; i++) {
        int departures = histo.getDepartures(modeName, i);
        int arrivals = histo.getArrivals(modeName, i);
        int stuck = histo.getAbort(modeName, i);
        enRoute = enRoute + departures - arrivals - stuck;
        double hour = i * histo.getBinSizeSeconds() / 60.0 / 60.0;
        departuresSerie.add(hour, departures);
        arrivalsSerie.add(hour, arrivals);
        onRouteSerie.add(hour, enRoute);
    }
    xyData.addSeries(departuresSerie);
    xyData.addSeries(arrivalsSerie);
    xyData.addSeries(onRouteSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart(
            this.title + ", " + modeName + ", " + "it." + histo.getIteration(), "time [h]", yTitle, xyData,
            PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));

    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(1.0f));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);

    return chart;
}

From source file:ec.nbdemetra.ui.chart3d.functions.Functions2DChart.java

private void configureAxis(XYPlot plot) {
    NumberAxis xAxis = new NumberAxis();
    xAxis.setAutoRange(true);//from  www  . java  2 s . c  om
    xAxis.setAutoRangeIncludesZero(false);
    plot.setDomainAxis(xAxis);

    NumberAxis yAxis = new NumberAxis();
    yAxis.setAutoRange(true);
    yAxis.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(yAxis);
}

From source file:org.matsim.core.utils.charts.XYLineChart.java

private JFreeChart createChart(final String title, final String categoryAxisLabel, final String valueAxisLabel,
        final XYSeriesCollection dataset) {
    JFreeChart c = ChartFactory.createXYLineChart(title, categoryAxisLabel, valueAxisLabel, dataset,
            PlotOrientation.VERTICAL, true, // legend?
            false, // tooltips?
            false // URLs?
    );/*from www.j  a v a  2  s.c o m*/
    if (this.isLogarithmicAxis) {
        XYPlot p = (XYPlot) c.getPlot();
        LogarithmicAxis axis_x = new LogarithmicAxis(this.xAxisLabel);
        LogarithmicAxis axis_y = new LogarithmicAxis(this.yAxisLabel);
        axis_x.setAllowNegativesFlag(false);
        axis_y.setAllowNegativesFlag(false);
        p.setDomainAxis(axis_x);
        p.setRangeAxis(axis_y);
    }
    return c;
}

From source file:org.yooreeka.util.gui.XyLogGui.java

public XyLogGui(String title, double[] x, double[] y) {

    super(title);

    errMsg = new StringBuilder();
    setLoopInt(x.length);//from  w w w  .j  av a2 s .c o m

    if (checkX(x) && checkY(x.length, y)) {

        XYSeries xydata = new XYSeries(title);

        for (int i = 0; i < loopInt; i++) {

            if (x[i] == C.ZERO_DOUBLE || x[i] < 0) {
                x[i] = C.SMALL_DOUBLE;
            }

            if (y[i] == C.ZERO_DOUBLE || y[i] < 0) {
                y[i] = C.SMALL_DOUBLE;
            }

            xydata.add(x[i], y[i]);
        }

        xycollection = new XYSeriesCollection(xydata);

        final JFreeChart chart = ChartFactory.createXYLineChart(title + " (XY Plot)", "X", "Y", xycollection,
                PlotOrientation.VERTICAL, true, true, false);

        final XYPlot plot = chart.getXYPlot();

        final NumberAxis domainAxis = new NumberAxis("x");
        plot.setDomainAxis(domainAxis);

        final NumberAxis logRangeAxis = new LogarithmicAxis("Log(y)");
        plot.setRangeAxis(logRangeAxis);

        chart.setBackgroundPaint(Color.white);
        plot.setOutlinePaint(Color.black);

        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    } else {
        System.err.println(errMsg.toString());
    }
}

From source file:playground.dgrether.analysis.charts.DgAvgDeltaUtilsGroupChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("Income [Chf / Year]");
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]");
    plot.setDomainAxis(xAxis);
    plot.setRangeAxis(yAxis);//from   w  ww.j  a va2 s. co  m

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    renderer2.setSeriesItemLabelsVisible(0, true);
    renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    plot.setDataset(0, this.dataset);
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer2.setSeriesOutlineStroke(0, new BasicStroke(3.0f));
    renderer2.setSeriesPaint(0, colorScheme.getColor(1, "a"));
    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    return chart;
}

From source file:org.yooreeka.util.gui.XyGui.java

public XyGui(String title, double[] x) {

    super(title);

    errMsg = new StringBuilder();
    setLoopInt(x.length);/*ww w. j a v a  2 s .  c  om*/

    if (checkX(x)) {

        XYSeries xydata = new XYSeries(title);

        for (int i = 0; i < loopInt; i++) {
            xydata.add(x[i], C.ZERO_DOUBLE);
        }

        xycollection = new XYSeriesCollection(xydata);

        final JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", xycollection,
                PlotOrientation.VERTICAL, true, true, false);

        final XYPlot plot = chart.getXYPlot();

        final NumberAxis domainAxis = new NumberAxis("x");
        plot.setDomainAxis(domainAxis);

        final NumberAxis rangeAxis = new NumberAxis("y");
        plot.setRangeAxis(rangeAxis);

        chart.setBackgroundPaint(Color.white);
        plot.setOutlinePaint(Color.black);

        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    } else {
        System.err.println(errMsg.toString());
    }
}

From source file:org.yooreeka.util.gui.XyGui.java

public XyGui(String title, double[] x, double[] y) {

    super(title);

    errMsg = new StringBuilder();
    setLoopInt(x.length);/*from w ww . j av  a2  s.com*/

    if (checkX(x) && checkY(x.length, y)) {

        XYSeries xydata = new XYSeries(title);

        for (int i = 0; i < loopInt; i++) {
            xydata.add(x[i], y[i]);
        }

        xycollection = new XYSeriesCollection(xydata);

        final JFreeChart chart = ChartFactory.createXYLineChart(title + " (XY Plot)", "X", "Y", xycollection,
                PlotOrientation.VERTICAL, true, true, false);

        final XYPlot plot = chart.getXYPlot();

        final NumberAxis domainAxis = new NumberAxis("x");
        plot.setDomainAxis(domainAxis);

        final NumberAxis rangeAxis = new NumberAxis("y");
        plot.setRangeAxis(rangeAxis);

        chart.setBackgroundPaint(Color.white);
        plot.setOutlinePaint(Color.black);

        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    } else {
        System.err.println(errMsg.toString());
    }
}

From source file:playground.thibautd.utils.charts.BoxAndWhiskersChart.java

private void createChart() {
    boolean legend = false;

    this.createDataSet();

    this.chart = ChartFactory.createBoxAndWhiskerChart(this.chartTitle, this.xAxisLabel, this.yAxisLabel,
            this.boxes, legend);

    XYPlot plot = this.chart.getXYPlot();
    plot.setDomainAxis(new NumberAxis(this.xAxisLabel));
    plot.getDomainAxis().configure();//from  ww  w . jav a2s .  c  om

    if (plotStdDev) {
        XYErrorRenderer renderer = new XYErrorRenderer();
        // in black
        renderer.setErrorPaint(Color.BLACK);
        // only plot Y error
        renderer.setDrawXError(false);
        // do not render average (already done by the B&W)
        renderer.setBaseShapesVisible(false);
        plot.setRenderer(1, renderer);
        plot.setDataset(1, deviationBars);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    }

    //this.addMatsimLogo();

    //try {
    //   this.addDefaultFormatting();
    //} catch (NullPointerException e) {
    //   // occurs if no legend
    //}

    //this.chart.setBackgroundPaint(Color.white);
    plot.setBackgroundPaint(Color.white);
    XYBoxAndWhiskerRenderer renderer = (XYBoxAndWhiskerRenderer) plot.getRenderer();
    //renderer.setFillBox(false);
    //renderer.setSeriesOutlinePaint(0, Color.black);
    //renderer.setSeriesPaint(0, Color.black);
    renderer.setBoxPaint(renderer.getSeriesPaint(0));
    //auto-adjust
    renderer.setBoxWidth(-1);
}

From source file:org.jgrasstools.gears.utils.chart.Scatter.java

public JFreeChart getChart() {
    if (chart == null) {
        chart = ChartFactory.createXYLineChart(title, // chart title
                xLabel,//from www.j  a  v a 2s . c  o m
                // domain axis label
                yLabel,
                // range axis label
                dataset,
                // data
                PlotOrientation.VERTICAL,
                // orientation
                false,
                // include legend
                true,
                // tooltips?
                false
        // URLs?
        );

        XYPlot plot = (XYPlot) chart.getPlot();
        if (xLog) {
            LogAxis xAxis = new LogAxis("");
            xAxis.setBase(10);
            plot.setDomainAxis(xAxis);
        }
        if (yLog) {
            LogAxis yAxis = new LogAxis("");
            yAxis.setBase(10);
            plot.setRangeAxis(yAxis);
        }

        ValueAxis rangeAxis = plot.getRangeAxis();
        if (rangeAxis instanceof NumberAxis) {
            NumberAxis axis = (NumberAxis) rangeAxis;
            axis.setAutoRangeIncludesZero(false);
        }

        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
        double x = 1.5;
        double w = x * 2;
        renderer.setSeriesShape(0, new Ellipse2D.Double(-x, x, w, w));
        setShapeLinesVisibility(plot);
    }
    return chart;
}