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:org.matsim.contrib.dvrp.util.chart.ScheduleChartUtils.java

public static <T extends Task> JFreeChart chartSchedule(List<? extends Vehicle> vehicles,
        DescriptionCreator<T> descriptionCreator, PaintSelector<T> paintSelector) {
    // data/*from   www.jav  a2s  .  c  om*/
    TaskSeriesCollection dataset = createScheduleDataset(vehicles, descriptionCreator);
    XYTaskDataset xyTaskDataset = new XYTaskDataset(dataset);

    // chart
    JFreeChart chart = ChartFactory.createXYBarChart("Schedules", "Time", false, "Vehicles", xyTaskDataset,
            PlotOrientation.HORIZONTAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();

    // Y axis
    String[] series = new String[vehicles.size()];
    for (int i = 0; i < series.length; i++) {
        series[i] = vehicles.get(i).getId().toString();
    }

    SymbolAxis symbolAxis = new SymbolAxis("Vehicles", series);
    symbolAxis.setGridBandsVisible(false);
    plot.setDomainAxis(symbolAxis);

    // X axis
    plot.setRangeAxis(new DateAxis("Time", TimeZone.getTimeZone("GMT"), Locale.getDefault()));

    // Renderer
    XYBarRenderer xyBarRenderer = new ChartTaskRenderer<T>(dataset, paintSelector);
    xyBarRenderer.setUseYInterval(true);
    plot.setRenderer(xyBarRenderer);

    return chart;
}

From source file:org.matsim.contrib.dvrp.util.chart.ScheduleCharts.java

public static JFreeChart chartSchedule(Collection<? extends Vehicle> vehicles,
        DescriptionCreator descriptionCreator, PaintSelector paintSelector) {
    // data//ww  w. j a  v  a 2 s .com
    TaskSeriesCollection dataset = createScheduleDataset(vehicles, descriptionCreator);
    XYTaskDataset xyTaskDataset = new XYTaskDataset(dataset);

    // chart
    JFreeChart chart = ChartFactory.createXYBarChart("Schedules", "Time", false, "Vehicles", xyTaskDataset,
            PlotOrientation.HORIZONTAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();

    // Y axis
    String[] series = new String[vehicles.size()];
    int i = 0;
    for (Vehicle v : vehicles) {
        series[i++] = v.getId().toString();
    }

    SymbolAxis symbolAxis = new SymbolAxis("Vehicles", series);
    symbolAxis.setGridBandsVisible(false);
    plot.setDomainAxis(symbolAxis);

    // X axis
    plot.setRangeAxis(new DateAxis("Time", TimeZone.getTimeZone("GMT"), Locale.getDefault()));

    // Renderer
    XYBarRenderer xyBarRenderer = new ChartTaskRenderer(dataset, paintSelector);
    xyBarRenderer.setUseYInterval(true);
    plot.setRenderer(xyBarRenderer);

    return chart;
}

From source file:playground.johannes.socialnets.GraphStatistics.java

public static JFreeChart makeChart(Histogram1D hist, String title) {
    final XYSeriesCollection data = new XYSeriesCollection();
    final XYSeries wave = new XYSeries(title, false, true);

    for (int i = 0; i < 100; i++) {
        wave.add(hist.xAxis().binCentre(i), hist.binHeight(i));
    }/*from   w w  w  .j a v a  2  s.c om*/

    data.addSeries(wave);

    final JFreeChart chart = ChartFactory.createXYStepChart("title", "x", "y", data, PlotOrientation.VERTICAL,
            true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

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

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date",
            "Price Per Unit", xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    PeriodAxis periodaxis = new PeriodAxis("Quarter", new Quarter(), new Quarter());
    periodaxis.setAutoRangeTimePeriodClass(org.jfree.data.time.Quarter.class);
    PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[1];
    aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Quarter.class,
            new QuarterDateFormat(TimeZone.getDefault(), QuarterDateFormat.ROMAN_QUARTERS));
    periodaxis.setLabelInfo(aperiodaxislabelinfo);
    xyplot.setDomainAxis(periodaxis);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }/*from  w  w  w  .  j  a v a 2 s.c  o m*/
    return jfreechart;
}

From source file:de.aidger.view.utils.Charts.java

/**
 * Creates a xy area chart./*from  w  w  w.  j av  a2  s  .  com*/
 * 
 * @param title
 *            the diagram title
 * @param dataset
 *            the dataset.
 * @param width
 *            the width of the chart as image
 * @param height
 *            the height of the chart as image
 * @return the xy area chart as image
 */
public static ImageIcon createXYAreaChart(String title, XYDataset dataset, int width, int height) {
    JFreeChart chart = ChartFactory.createXYAreaChart(title, "", "", dataset, PlotOrientation.VERTICAL, false,
            false, false);

    Font titleFont = UIManager.getFont("TitledBorder.font");

    chart.setBackgroundPaint(null);
    chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14));
    chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor"));
    chart.setBorderPaint(null);

    XYPlot plot = chart.getXYPlot();
    plot.setInsets(new RectangleInsets(10, 1, 5, 1));
    plot.setBackgroundPaint(null);
    plot.setOutlineVisible(false);
    plot.setNoDataMessage(_("No data to display."));

    ValueAxis domainAxis = new DateAxis();
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setTickLabelFont(UIManager.getFont("RootPane.font"));

    ValueAxis rangeAxis = new NumberAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    plot.setDomainAxis(domainAxis);
    plot.setRangeAxis(rangeAxis);

    plot.setForegroundAlpha(0.5f);

    return new ImageIcon(chart.createBufferedImage(width, height));
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart chart = ChartFactory.createXYLineChart("DeviationRenderer - Demo 3", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    ////www  .jav a  2  s  . com
    DeviationRenderer renderer = new DeviationRenderer(false, false);
    renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    renderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1));
    renderer.setSeriesFillPaint(0, Color.red);
    renderer.setSeriesFillPaint(1, Color.orange);
    renderer.setSeriesFillPaint(2, Color.green);
    plot.setRenderer(renderer);
    //
    DateAxis domainAxis = new DateAxis("Date");
    domainAxis.setLowerMargin(0.0D);
    domainAxis.setUpperMargin(0.0D);
    plot.setDomainAxis(domainAxis);
    NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis();
    valueAxis.setRange(-40D, 40D);
    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ChartUtilities.applyCurrentTheme(chart);
    return chart;
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java

/**
 * Updates the axis-related properties of a plot.
 * /*from  www .ja  v  a 2 s .  c  o m*/
 * @param aPlot
 *            Plot to be updated.
 * @param aAxes
 *            Axis-related visual settings to be applied.
 * @param aGrid
 *            Grid-related visual settings to be applied.
 */
private static void updateAxes(XYPlot aPlot, AxesSettings aAxes, GridSettings aGrid, Range aDomainDataRange,
        Range aRangeDataRange) {

    aPlot.setDomainAxis(createAxis(aAxes, true, aDomainDataRange));
    aPlot.setRangeAxis(createAxis(aAxes, false, aRangeDataRange));

    aPlot.setDomainGridlinesVisible(aGrid.getVerticalGridLines()); // set gridlines for X axis
    aPlot.setDomainGridlinePaint(aGrid.getGridLinesColor()); // set color of domain gridline

    aPlot.setRangeGridlinesVisible(aGrid.getHorizontalGridLines()); // set gridlines for Y axis
    aPlot.setRangeGridlinePaint(aGrid.getGridLinesColor()); // set color of range gridline
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Difference Chart Demo 1", "Time", "Value",
            xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYDifferenceRenderer xydifferencerenderer = new XYDifferenceRenderer(Color.green, Color.red, false);
    xydifferencerenderer.setRoundXCoordinates(true);
    xyplot.setDomainCrosshairLockedOnData(true);
    xyplot.setRangeCrosshairLockedOnData(true);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    xyplot.setRenderer(xydifferencerenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    DateAxis dateaxis = new DateAxis("Time");
    dateaxis.setLowerMargin(0.0D);/* w  w  w  . j ava2 s  . c o m*/
    dateaxis.setUpperMargin(0.0D);
    xyplot.setDomainAxis(dateaxis);
    xyplot.setForegroundAlpha(0.5F);
    return jfreechart;
}

From source file:ec.util.chart.swing.JTimeSeriesRendererSupportDemo.java

private static JFreeChart createTsChart() {
    XYPlot plot = new XYPlot();

    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

    DateAxis domainAxis = new DateAxis();
    domainAxis.setTickLabelsVisible(false);
    domainAxis.setLowerMargin(0.02);/* ww  w.j av a 2s. c  om*/
    domainAxis.setUpperMargin(0.02);
    plot.setDomainAxis(domainAxis);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelsVisible(false);
    rangeAxis.setLowerMargin(0.02);
    rangeAxis.setUpperMargin(0.02);
    plot.setRangeAxis(rangeAxis);

    JFreeChart result = new JFreeChart("", null, plot, true);
    result.setPadding(new RectangleInsets(5, 5, 5, 5));
    result.getLegend().setFrame(BlockBorder.NONE);
    result.getLegend().setBackgroundPaint(null);

    return result;
}

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

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

    XYPlot plot = result.getXYPlot();

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setShadowVisible(false);//from w w  w  . j  a v  a  2  s .co m
    renderer.setDrawBarOutline(true);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setAutoPopulateSeriesOutlinePaint(false);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);

    NumberAxis domainAxis = new NumberAxis();
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    return result;
}