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:ec.ui.view.RevisionSaSeriesView.java

private void configureAxis(XYPlot plot) {
    SimpleDateFormat sdf = new SimpleDateFormat("MM-yyyy");
    DateAxis dateAxis = new DateAxis();
    dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    dateAxis.setDateFormatOverride(sdf);
    plot.setDomainAxis(dateAxis);
    NumberAxis yaxis = new NumberAxis();
    if (range != null) {
        yaxis.setRange(range);//from  w  w w. jav a 2 s.  c  o m
    }
    plot.setRangeAxis(yaxis);
}

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

@Override
public JFreeChart createChart() {
    XYSeriesCollection dataset = this.createDataSet();
    XYPlot plot = new XYPlot();
    DgAxisBuilder axisBuilder = new DgDefaultAxisBuilder();
    ValueAxis xAxis = axisBuilder.createValueAxis("Simulation Time");
    //    xAxis.setRange(this.controllerConfig.getFirstIteration(), this.controllerConfig.getLastIteration() + 2);
    ValueAxis yAxis = axisBuilder.createValueAxis("Travel Time");
    //    yAxis.setRange(-0.05, 0.3);
    //    xAxis.setVisible(false);
    //    xAxis.setFixedAutoRange(1.0);
    plot.setDomainAxis(xAxis);
    plot.setRangeAxis(yAxis);//from   w  ww.j  ava  2s .  c  om

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, false);
    renderer2.setSeriesItemLabelsVisible(0, true);
    //    renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    plot.setDataset(0, dataset);
    renderer2.setSeriesStroke(0, new BasicStroke(1.0f));
    renderer2.setSeriesOutlineStroke(0, new BasicStroke(1.0f));
    renderer2.setSeriesPaint(0, colorScheme.getColor(1, "a"));
    renderer2.setSeriesStroke(1, new BasicStroke(1.0f));
    renderer2.setSeriesOutlineStroke(1, new BasicStroke(1.0f));
    renderer2.setSeriesPaint(1, colorScheme.getColor(2, "a"));
    renderer2.setSeriesStroke(2, new BasicStroke(1.0f));
    renderer2.setSeriesOutlineStroke(2, new BasicStroke(1.0f));
    renderer2.setSeriesPaint(2, colorScheme.getColor(3, "a"));
    renderer2.setSeriesStroke(3, new BasicStroke(1.0f));
    renderer2.setSeriesOutlineStroke(3, new BasicStroke(1.0f));
    renderer2.setSeriesPaint(3, colorScheme.getColor(4, "a"));

    plot.setRenderer(0, renderer2);

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

From source file:net.sourceforge.processdash.ui.web.psp.TimeLogPhaseWaterfallChart.java

private JFreeChart createChart(IntervalXYDataset dataset, ProcessUtil process, List<String> phases,
        GapSkipTracker gaps) {/*ww w.ja v  a 2s . c o m*/
    JFreeChart result = ChartFactory.createXYBarChart(null, null, true, null, dataset, PlotOrientation.VERTICAL,
            false, true, false);

    XYPlot xyplot = (XYPlot) result.getPlot();
    DateAxis dateAxis = new DateAxis(null);
    dateAxis.setTickMarksVisible(false);
    dateAxis.setTickLabelsVisible(false);
    dateAxis.setLowerMargin(0.01);
    dateAxis.setUpperMargin(0.01);
    setupGaps(gaps, dateAxis, xyplot);
    xyplot.setDomainAxis(dateAxis);

    String[] phaseNameList = new String[phases.size()];
    for (int i = 0; i < phaseNameList.length; i++)
        phaseNameList[i] = Translator.translate(phases.get(i));
    SymbolAxis symbolaxis = new SymbolAxis(null, phaseNameList);
    symbolaxis.setGridBandsVisible(false);
    xyplot.setRangeAxis(symbolaxis);

    final XYBarRenderer renderer = (XYBarRenderer) xyplot.getRenderer();
    renderer.setUseYInterval(true);
    renderer.setDrawBarOutline(true);
    renderer.setBaseOutlinePaint(Color.black);

    new PhaseChartColorer(process, phases) {
        public void setItemColor(Object key, int pos, Color c) {
            renderer.setSeriesPaint(pos, c);
        }
    }.run();

    int exceptionSeries = dataset.getSeriesCount() - 1;
    renderer.setSeriesPaint(exceptionSeries, EXCEPTION_PAINT);
    renderer.setSeriesFillPaint(exceptionSeries, EXCEPTION_PAINT);
    renderer.setSeriesOutlinePaint(exceptionSeries, EXCEPTION_PAINT);

    renderer.setBaseToolTipGenerator(new TooltipGenerator());

    xyplot.setBackgroundPaint(Color.white);
    xyplot.setDomainGridlinesVisible(false);
    xyplot.setRangeGridlinePaint(Color.lightGray);
    xyplot.setDrawingSupplier(DRAWING_SUPPLIER_FACTORY.newDrawingSupplier());

    result.setAntiAlias(false);
    result.setTextAntiAlias(true);

    parameters.put("title", resources.getString("Title"));

    return result;
}

From source file:vteaexploration.plottools.panels.XYChartPanel.java

public void setChartPanelRanges(int axis, double low, double high) {
    XYPlot plot = (XYPlot) this.chartPanel.getChart().getPlot();
    ValueAxis newaxis = new NumberAxis();
    newaxis.setLowerBound(low);// w w  w.  ja va2 s  .c om
    newaxis.setUpperBound(high);
    if (axis == XYChartPanel.XAXIS) {
        plot.setDomainAxis(newaxis);
    } else if (axis == XYChartPanel.YAXIS) {
        plot.setRangeAxis(newaxis);
    }
}

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

private JFreeChart getGraphic() {
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries insideSerie = new XYSeries("total inside area", false, true);
    final XYSeries residentsSerie = new XYSeries("residents inside area", false, true);
    final XYSeries commutersSerie = new XYSeries("commuters inside area", false, true);

    for (int i = 0; i < plotData.size(); i++) {
        PlotData pd = plotData.get(i);//from w  ww . j  a  v a  2  s. c om
        double hour = pd.time / 3600.0;
        insideSerie.add(hour, pd.commuterAgentCount + pd.residentAgentCount);
        residentsSerie.add(hour, pd.residentAgentCount);
        commutersSerie.add(hour, pd.commuterAgentCount);
    }
    xyData.addSeries(insideSerie);
    xyData.addSeries(residentsSerie);
    xyData.addSeries(commutersSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart("agents inside area", "time [hour]", "# agents",
            xyData, PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    NumberAxis na = new NumberAxis("time [hour]");
    na.setRange(0, maxTime / 3600.0);
    na.setLabelFont(plot.getRangeAxis().getLabelFont());
    na.setTickLabelFont(plot.getRangeAxis().getTickLabelFont());
    plot.setDomainAxis(na);
    return chart;
}

From source file:org.squale.squaleweb.util.graph.AreaMaker.java

/**
 * @return le diagramme JFreeChart// ww w . j  a  v a  2s . co  m
 */
protected JFreeChart getChart() {
    JFreeChart retChart = super.getChart();
    if (null == retChart) {
        retChart = ChartFactory.createXYAreaChart(mTitle, mXLabel, mYLabel, mDataSet, PlotOrientation.VERTICAL,
                false, false, false);
        final XYPlot plot = retChart.getXYPlot();

        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setNumberFormatOverride(new DecimalFormat("########0.0"));
        // rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

        // Format de l'axe des dates
        final ValueAxis domainAxis = new DateAxis(mXLabel);
        domainAxis.setLowerMargin(0.0);
        domainAxis.setUpperMargin(0.0);
        ((DateAxis) domainAxis).setDateFormatOverride(mDateFormat);
        plot.setDomainAxis(domainAxis);

        super.setChart(retChart);
    }
    return retChart;
}

From source file:org.projectforge.statistics.TimesheetDisciplineChartBuilder.java

private JFreeChart create(final TimeSeries series1, final TimeSeries series2, final Shape shape,
        final Stroke stroke, final boolean showAxisValues, final String valueAxisUnitKey) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series1);/*from www .j ava 2  s .c  o m*/
    dataset.addSeries(series2);
    final JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
            true, true, false);

    final XYDifferenceRenderer renderer = new XYDifferenceRenderer(new Color(238, 176, 176),
            new Color(135, 206, 112), true);
    renderer.setSeriesPaint(0, new Color(222, 23, 33));
    renderer.setSeriesPaint(1, new Color(64, 169, 59));
    if (shape != null) {
        renderer.setSeriesShape(0, shape);
        renderer.setSeriesShape(1, shape);
    } else {
        final Shape none = new Rectangle();
        renderer.setSeriesShape(0, none);
        renderer.setSeriesShape(1, none);
    }
    renderer.setSeriesStroke(0, stroke);
    renderer.setSeriesStroke(1, stroke);
    renderer.setSeriesVisibleInLegend(0, false);
    renderer.setSeriesVisibleInLegend(1, false);
    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    final DateAxis xAxis = new DateAxis();
    xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    xAxis.setVisible(showAxisValues);
    plot.setDomainAxis(xAxis);
    final NumberAxis yAxis;
    if (showAxisValues == true) {
        yAxis = new NumberAxis(PFUserContext.getLocalizedString(valueAxisUnitKey));
    } else {
        yAxis = new NumberAxis();
    }
    yAxis.setVisible(showAxisValues);
    plot.setRangeAxis(yAxis);
    plot.setOutlineVisible(false);
    return chart;
}

From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.MatrixChart.java

private void buildMainChart(String title, String subTitle, String xAxisLabel, String yAxisLabel,
        String fileName) {//from   www .j  a v a 2 s .  c o  m
    final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.createMatrixDataSet());

    final JFreeChart chart = ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, true, true, false);

    chart.addSubtitle(new TextTitle(subTitle));
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.WHITE));
    chart.removeLegend();

    // Perform customizations starts here ...
    final XYPlot plot1 = chart.getXYPlot();

    plot1.setDomainGridlinesVisible(false);
    plot1.setRangeGridlinesVisible(false);
    plot1.setForegroundAlpha(0.5f);
    plot1.setDomainAxis(new CustomAxis(plot1.getDomainAxis().getLabel()));
    plot1.setRangeAxis(new CustomAxis(plot1.getRangeAxis().getLabel()));

    // Custumize the domain axis ( y )
    final NumberAxis domainAxis = (NumberAxis) plot1.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setRange(-1, this.array.length);

    // Custumize the range axis ( y )
    final NumberAxis rangeAxis = (NumberAxis) plot1.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setRange(-1, this.array.length);

    // Create custom renderer
    StandardXYItemRenderer ren = new CustomRenderer(false);
    ren.setSeriesItemLabelPaint(0, Color.BLACK);
    plot1.setRenderer(ren);
    this.mainChart = chart;
}

From source file:org.jfree.chart.demo.PeriodAxisDemo1.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();
    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);
        xylineandshaperenderer.setBaseItemLabelsVisible(true);
    }//from w  w  w  .  j  av a  2 s  .co m
    PeriodAxis periodaxis = new PeriodAxis("Date");
    periodaxis.setTimeZone(TimeZone.getTimeZone("Pacific/Auckland"));
    periodaxis.setAutoRangeTimePeriodClass(org.jfree.data.time.Month.class);
    periodaxis.setMajorTickTimePeriodClass(org.jfree.data.time.Month.class);
    PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[2];
    aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class,
            new SimpleDateFormat("MMM"), new RectangleInsets(2D, 2D, 2D, 2D), new Font("SansSerif", 1, 10),
            Color.blue, false, new BasicStroke(0.0F), Color.lightGray);
    aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Year.class,
            new SimpleDateFormat("yyyy"));
    periodaxis.setLabelInfo(aperiodaxislabelinfo);
    xyplot.setDomainAxis(periodaxis);
    return jfreechart;
}

From source file:web.diva.server.unused.ProfilePlotGenerator.java

/**
 * Creates a line chart (based on an {@link XYDataset}) with default
 * settings.//from  w  w  w .  ja  va2s. c o  m
 *
 * @param title the chart title (<code>null</code> permitted).
 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted).
 * @param dataset the dataset for the chart (<code>null</code> permitted).
 * @param orientation the plot orientation (horizontal or vertical)
 * (<code>null</code> NOT permitted).
 * @param legend a flag specifying whether or not a legend is required.
 * @param tooltips configure chart to generate tool tips?
 * @param urls configure chart to generate URLs?
 *
 * @return The chart.
 */
private JFreeChart createXYLineChart(String title, String[] columnIds, XYDataset dataset,
        PlotOrientation orientation, boolean legend, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    Font f = new Font("ARIAL", 1, 7);
    //        NumberAxis xAxis = new NumberAxis(xAxisLabel);
    //        xAxis.setAutoRangeIncludesZero(false);
    SymbolAxis xAxis = new SymbolAxis("", columnIds);
    xAxis.setAxisLineVisible(false);
    xAxis.setGridBandsVisible(false);
    xAxis.setVerticalTickLabels(true);
    xAxis.setVisible(true);

    xAxis.setTickLabelPaint(shadowColor);
    xAxis.setTickLabelFont(f);
    xAxis.setFixedDimension(51.0);

    boolean auto = xAxis.getAutoRangeIncludesZero();
    xAxis.setAutoRangeIncludesZero(true ^ auto);
    xAxis.setTickUnit(new NumberTickUnit(1));
    xAxis.setRange(0, columnIds.length);
    //        NumberAxis yAxis = new NumberAxis(yAxisLabel);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setAutoRangeIncludesZero(true ^ auto);
    yAxis.setAxisLineVisible(false);
    yAxis.setTickLabelFont(f);
    yAxis.setTickLabelPaint(Color.BLUE);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseShapesVisible(false);
    renderer.setPaint(shadowColor);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);

    plot.setBackgroundPaint(Color.WHITE);

    plot.setDomainGridlinePaint(shadowColor);
    plot.setRangeGridlinePaint(shadowColor);
    plot.setOutlinePaint(Color.BLUE);
    //        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    //        plot.setRenderer(renderer);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE);

    plot.setDomainAxis(xAxis);

    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;

}