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.jfree.chart.demo.XYTaskDatasetDemo1.java

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYBarChart("XYTaskDatasetDemo1", "Resource", false, "Timing",
            intervalxydataset, PlotOrientation.HORIZONTAL, true, false, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setRangePannable(true);/* www .  j  a  v a  2s. c o m*/
    SymbolAxis symbolaxis = new SymbolAxis("Series", new String[] { "Team A", "Team B", "Team C", "Team D" });
    symbolaxis.setGridBandsVisible(false);
    xyplot.setDomainAxis(symbolaxis);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setUseYInterval(true);
    xyplot.setRangeAxis(new DateAxis("Timing"));
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PaintScaleFactory.java

public static ValueAxis getPaintScaleAxis(double lower, double upper, String label) {
    // return a simple axis for the scale
    double inc = (upper - lower) / maxDivisions;

    final XYSeries s1 = new XYSeries("Series 1");

    for (int i = 0; i < maxDivisions; i++) {
        s1.add(i, i * inc);/*from  w ww  .  ja  v  a2  s.  c o m*/
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(s1);

    JFreeChart chart = ChartFactory.createXYLineChart("Axis Demo", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, false);

    final XYPlot plot = chart.getXYPlot();
    final NumberAxis domainAxis = new NumberAxis("xish");
    final NumberAxis rangeAxis = new NumberAxis(label);
    plot.setDomainAxis(domainAxis);
    plot.setRangeAxis(rangeAxis);
    return plot.getRangeAxis();
}

From source file:org.matsim.analysis.LegHistogramChart.java

static JFreeChart getGraphic(final LegHistogram.DataFrame dataFrame, final String mode, int iteration) {
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries departuresSerie = new XYSeries("departures", false, true);
    final XYSeries arrivalsSerie = new XYSeries("arrivals", false, true);
    final XYSeries onRouteSerie = new XYSeries("en route", false, true);
    int onRoute = 0;
    for (int i = 0; i < dataFrame.countsDep.length; i++) {
        onRoute = onRoute + dataFrame.countsDep[i] - dataFrame.countsArr[i] - dataFrame.countsStuck[i];
        double hour = i * dataFrame.binSize / 60.0 / 60.0;
        departuresSerie.add(hour, dataFrame.countsDep[i]);
        arrivalsSerie.add(hour, dataFrame.countsArr[i]);
        onRouteSerie.add(hour, onRoute);
    }//w  w  w  . j a  v  a  2 s . c o m

    xyData.addSeries(departuresSerie);
    xyData.addSeries(arrivalsSerie);
    xyData.addSeries(onRouteSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart("Leg Histogram, " + mode + ", it." + iteration,
            "time", "# persons", 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(2.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);

    return chart;
}

From source file:org.matsim.contrib.socnetsim.usage.analysis.CourtesyHistogramListener.java

static JFreeChart getGraphic(final CourtesyHistogram.DataFrame dataFrame, int iteration, String actType) {
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries helloSeries = new XYSeries("hello", false, true);
    final XYSeries goodbyeSerie = new XYSeries("goodbye", false, true);
    final XYSeries togetherSerie = new XYSeries("pairs together", false, true);
    int together = 0;
    for (int i = 0; i < dataFrame.countsHello.length; i++) {
        together = together + dataFrame.countsHello[i] - dataFrame.countsGoodbye[i];
        double hour = i * dataFrame.binSize / 60.0 / 60.0;
        helloSeries.add(hour, dataFrame.countsHello[i]);
        goodbyeSerie.add(hour, dataFrame.countsGoodbye[i]);
        togetherSerie.add(hour, together);
    }/*  w ww  . jav  a  2s.  co m*/

    xyData.addSeries(helloSeries);
    xyData.addSeries(goodbyeSerie);
    xyData.addSeries(togetherSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart(
            "Courtesy Statistics," + "actType " + actType + " it." + iteration, "time", "# persons", 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(2.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);

    return chart;
}

From source file:org.radargun.reporting.BarPlotGenerator.java

/**
 * @param operation Name of the plotted operation
 * @param ranges ranges[0] = min, ranges[ranges.length - 1] = max
 * @param counts counts[i] is number of entries with value >= ranges[i - 1] and < ranges[i]
 * @param reportDir// w ww .  java2 s  .  c o m
 * @param filename
 * @throws IOException
 */
public static void generate(String operation, long[] ranges, long[] counts, String reportDir, String filename)
        throws IOException {
    XYSeries series = new XYSeries(operation + " response times");
    long totalCount = 0;
    for (long count : counts) {
        totalCount += count;
    }
    double left = Math.log10(ranges[0]);
    double right = Math.log10(ranges[ranges.length - 1]);

    for (int i = 0; i < counts.length; i++) {
        series.add(Math.log10(ranges[i]), (double) counts[i] / totalCount);
    }
    series.add(right, 0d);
    XYDataset dataset = new XYSeriesCollection(series);
    JFreeChart chart = ChartFactory.createXYStepAreaChart(operation + " response time histogram",
            "Response time", "Percentage", dataset, PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis d = (NumberAxis) plot.getDomainAxis();
    d.setRange(left, right);
    d.setStandardTickUnits(new HistoTickUnitSource());
    plot.setDomainAxis(d);
    FileOutputStream output = new FileOutputStream(new File(reportDir + File.separator + filename));
    ChartUtilities.writeChartAsPNG(output, chart, 1024, 768);
    output.close();
}

From source file:umberto.WeightedClusterCoefficient.ChartUtils.java

public static void scaleLogarithmicChart(JFreeChart chart, XYSeries dSeries, boolean normalized) {
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis logxaxis = new LogarithmicAxis(plot.getDomainAxis().getLabel());
    NumberAxis logyaxis = new LogarithmicAxis(plot.getRangeAxis().getLabel());
    plot.setRangeAxis(logyaxis);/*from w w w .ja v a 2s .co  m*/
    plot.setDomainAxis(logxaxis);
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("Logarithmic Axis Demo 2", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    LogarithmicAxis logarithmicaxis = new LogarithmicAxis("X");
    logarithmicaxis.setExpTickLabelsFlag(true);
    logarithmicaxis.setStrictValuesFlag(false);
    LogarithmicAxis logarithmicaxis1 = new LogarithmicAxis("Y");
    logarithmicaxis1.setAllowNegativesFlag(true);
    logarithmicaxis1.setLog10TickLabelsFlag(true);
    xyplot.setDomainAxis(logarithmicaxis);
    xyplot.setRangeAxis(logarithmicaxis1);
    return jfreechart;
}

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

public static JFreeChart createStackedAreaChart(String title, XYSeriesCollection areaData,
        XYSeriesCollection lineData, String xLabel, String yLabel, ColorTheme theme) {

    final ValueAxis xAxis = new NumberAxis(xLabel);
    final ValueAxis yAxis = new NumberAxis(yLabel);
    XYPlot mainPlot = new XYPlot();
    mainPlot.setDomainAxis(xAxis);
    mainPlot.setRangeAxis(yAxis);//w w w  .j a va2 s. c o  m

    mainPlot.setForegroundAlpha(0.9f);

    //[ stacked area
    DefaultTableXYDataset areaDs = new DefaultTableXYDataset();
    for (int i = 0; i < areaData.getSeriesCount(); i++) {
        areaDs.addSeries(areaData.getSeries(i));
    }
    XYItemRenderer stackedRenderer = new StackedXYAreaRenderer2();
    mainPlot.setDataset(areaDs);
    mainPlot.setRenderer(stackedRenderer);

    Color[] colors = generateJetSpectrum(areaData.getSeriesCount());
    for (int i = 0; i < areaData.getSeriesCount(); i++) {
        stackedRenderer.setSeriesPaint(i, colors[i]);
    }
    //]

    //[ lines
    if (lineData != null) {
        XYItemRenderer lineRenderer = new StandardXYItemRenderer();
        DefaultTableXYDataset lineDs = new DefaultTableXYDataset();
        for (int i = 0; i < lineData.getSeriesCount(); i++) {
            lineDs.addSeries(lineData.getSeries(i));
        }
        mainPlot.setDataset(1, lineDs);
        mainPlot.setRenderer(1, lineRenderer);

        colors = new Color[] { Color.black, Color.red, Color.darkGray };
        for (int i = 0; i < lineData.getSeriesCount(); i++) {
            lineRenderer.setSeriesPaint(i, colors[i % colors.length]);
            lineRenderer.setSeriesStroke(i, new BasicStroke(2f));
        }
    }
    //]

    mainPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true);

    formatColorTheme(chart, theme);

    return chart;
}

From source file:de.laures.cewolf.taglib.CewolfChartFactory.java

public static JFreeChart getOverlaidChartInstance(String chartType, String title, String xAxisLabel,
        String yAxisLabel, int xAxisType, int yAxisType, List plotDefinitions)
        throws ChartValidationException, DatasetProduceException {
    final int chartTypeConst = getChartTypeConstant(chartType);
    final AxisFactory axisFactory = AxisFactory.getInstance();
    switch (chartTypeConst) {
    case OVERLAY_XY:
        ValueAxis domainAxis = (ValueAxis) axisFactory.createAxis(ORIENTATION_HORIZONTAL, xAxisType,
                xAxisLabel);//from  ww w  . j  av a  2 s .c om
        // get main plot
        PlotDefinition mainPlotDef = (PlotDefinition) plotDefinitions.get(0);
        check((Dataset) mainPlotDef.getDataset(), XYDataset.class, chartType);
        XYPlot plot = (XYPlot) mainPlotDef.getPlot(chartTypeConst);
        plot.setDomainAxis(domainAxis);
        plot.setRangeAxis((ValueAxis) axisFactory.createAxis(ORIENTATION_VERTICAL, yAxisType, yAxisLabel));
        //plot.setRenderer(new StandardXYItemRenderer());
        // add second and later datasets to main plot
        for (int plotidx = 1; plotidx < plotDefinitions.size(); plotidx++) {
            PlotDefinition subPlotDef = (PlotDefinition) plotDefinitions.get(plotidx);
            check((Dataset) subPlotDef.getDataset(), XYDataset.class, chartType);
            plot.setDataset(plotidx, (XYDataset) subPlotDef.getDataset());

            int rendererIndex = PlotTypes.getRendererIndex(subPlotDef.getType());
            XYItemRenderer rend = (XYItemRenderer) PlotTypes.getRenderer(rendererIndex);
            plot.setRenderer(plotidx, rend);
        }
        return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    case OVERLAY_CATEGORY://added by lrh 2005-07-11
        CategoryAxis domainAxis2 = (CategoryAxis) axisFactory.createAxis(ORIENTATION_HORIZONTAL, xAxisType,
                xAxisLabel);
        // get main plot
        mainPlotDef = (PlotDefinition) plotDefinitions.get(0);
        check((Dataset) mainPlotDef.getDataset(), CategoryDataset.class, chartType);
        CategoryPlot plot2 = (CategoryPlot) mainPlotDef.getPlot(chartTypeConst);
        plot2.setDomainAxis(domainAxis2);
        plot2.setRangeAxis((ValueAxis) axisFactory.createAxis(ORIENTATION_VERTICAL, yAxisType, yAxisLabel));
        //plot.setRenderer(new StandardXYItemRenderer());
        // add second and later datasets to main plot
        for (int plotidx = 1; plotidx < plotDefinitions.size(); plotidx++) {
            PlotDefinition subPlotDef = (PlotDefinition) plotDefinitions.get(plotidx);
            check((Dataset) subPlotDef.getDataset(), CategoryDataset.class, chartType);
            plot2.setDataset(plotidx, (CategoryDataset) subPlotDef.getDataset());

            int rendererIndex = PlotTypes.getRendererIndex(subPlotDef.getType());
            CategoryItemRenderer rend2 = (CategoryItemRenderer) PlotTypes.getRenderer(rendererIndex);
            plot2.setRenderer(plotidx, rend2);
        }
        return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot2, true);
    default:
        throw new UnsupportedChartTypeException(chartType + " is not supported.");
    }
}

From source file:ec.ui.view.res.ResidualsView.java

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

    XYPlot plot = result.getXYPlot();

    DateAxis domainAxis = new DateAxis();
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    domainAxis.setLowerMargin(0);/*ww  w . j a  va2s .co m*/
    domainAxis.setUpperMargin(0);
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelInsets(new RectangleInsets(10, 5, 10, 2));
    rangeAxis.setLowerMargin(0.02);
    rangeAxis.setUpperMargin(0.02);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setShadowVisible(false);
    renderer.setDrawBarOutline(true);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setAutoPopulateSeriesOutlinePaint(false);

    return result;
}