Example usage for org.jfree.chart ChartFactory createXYBarChart

List of usage examples for org.jfree.chart ChartFactory createXYBarChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createXYBarChart.

Prototype

public static JFreeChart createXYBarChart(String title, String xAxisLabel, boolean dateAxis, String yAxisLabel,
        IntervalXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips,
        boolean urls) 

Source Link

Document

Creates and returns a default instance of an XY bar chart.

Usage

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

public static JFreeChart chartSchedule(Collection<? extends Vehicle> vehicles,
        DescriptionCreator descriptionCreator, PaintSelector paintSelector) {
    // data// w  w w . j ava2  s .co m
    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:com.googlecode.logVisualizer.chart.VerticalXYBarChartBuilder.java

private JFreeChart createChart(final IntervalXYDataset dataset) {
    final JFreeChart chart = ChartFactory.createXYBarChart(getTitle(), xLable, false, yLable, dataset,
            PlotOrientation.VERTICAL, isIncludeLegend(), true, false);
    final XYPlot plot = (XYPlot) chart.getPlot();
    final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();

    double lastXValue = 0;
    if (dataset.getSeriesCount() > 0)
        lastXValue = dataset.getXValue(0, dataset.getItemCount(0) - 1);

    plot.setDomainAxis(new FixedZoomNumberAxis(lastXValue));
    plot.setNoDataMessage("No data available");
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    setBarShadowVisible(chart, false);/*from  w  ww  .  ja  v a  2 s. c  om*/

    plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (dataset.getSeriesCount() > 0)
        plot.getDomainAxis().setUpperBound(lastXValue);
    plot.getDomainAxis().setLowerBound(0);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setUpperMargin(0.1);

    return chart;
}

From source file:edu.psu.citeseerx.misc.charts.CiteChartBuilderJFree.java

protected JFreeChart buildChart(Document doc) throws SQLException {

    Long clusterid = doc.getClusterID();
    if (clusterid == null) {
        return null;
    }/*w  ww.  j av a 2s .c  o m*/

    java.util.List<ThinDoc> citingDocs = citedao.getCitingDocuments(clusterid, 0, MAX_CITING);
    XYDataset dataset = collectData(citingDocs);
    if (dataset.getItemCount(0) <= 1) {
        return null;
    }

    XYBarDataset ivl_dataset = new XYBarDataset(dataset, 15.0);
    JFreeChart chart = ChartFactory.createXYBarChart(null, "Year", true, "Citation Count", ivl_dataset,
            PlotOrientation.VERTICAL, false, false, false);
    chart.setBackgroundPaint(Color.WHITE);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();

    NumberAxis axis = (NumberAxis) plot.getDomainAxis();
    axis.setNumberFormatOverride(NumberFormat.getIntegerInstance());
    //axis.setTickUnit(new DateTickUnit(DateTickUnit.YEAR, -1));
    //axis.setDateFormatOverride(new SimpleDateFormat("yyyy"));
    return chart;

}

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

/**
 * Constructs the demo application./*from w ww . j  a  v a  2 s  . com*/
 *
 * @param title  the frame title.
 */
public XYBarChartDemo4(final String title) {

    super(title);

    final IntervalXYDataset dataset = createDataset();

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

    // then customise it a little...
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue));
    final XYPlot plot = (XYPlot) chart.getPlot();
    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
    setContentPane(chartPanel);

}

From source file:utils.HistogramFrame.java

/**
 * Uses the XYDataset to fill a XYBarChart Histogram. 
 *///  w w  w .  ja va2 s .  c  o m
private void createChart() {
    this.chart = ChartFactory.createXYBarChart(this.title, this.label, false, "", this.dataset,
            PlotOrientation.VERTICAL, false, false, false);
    this.chart.getPlot();
}

From source file:gchisto.gui.panels.gctimeline.ChartPanel.java

/**
 * It creates a chart for the given dataset and adds the chart to the panel.
 *
 * @param dataset The dataset that will provide the values for the chart.
 *///w w  w.  j  av a 2s  .c o  m
private void addChart() {
    JFreeChart chart = ChartFactory.createXYBarChart(getTitle(), "Elapsed Time (sec)", false,
            "Time" + unitSuffix(), dataset, PlotOrientation.VERTICAL, true, true, false);
    chart.addProgressListener(locker);
    XYPlot plot = (XYPlot) chart.getPlot();
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setToolTipGenerator(dataset);

    groupActivatingTable = new GroupActivatingPanel(dataset, locker);

    org.jfree.chart.ChartPanel chartPanel = new org.jfree.chart.ChartPanel(chart);
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, groupActivatingTable, chartPanel);
    splitPane.setDividerLocation(200);
    mainPanel().add(BorderLayout.CENTER, splitPane);
}

From source file:gchisto.gui.panels.gcdistribution.ChartPanelSingle.java

/**
 * It creates a chart for the given dataset and adds the chart to the panel.
 *
 * @param dataset The dataset that will provide the values for the chart.
 *///from www  .j  a v a2 s .co  m
private void addChart() {
    JFreeChart chart = ChartFactory.createXYBarChart(getTitle(), "Buckets (sec)", false, "Count", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.addProgressListener(locker);
    XYPlot plot = (XYPlot) chart.getPlot();
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setToolTipGenerator(dataset);

    groupActivatingPanel = new GroupActivatingPanel(dataset, locker);

    org.jfree.chart.ChartPanel chartPanel = new org.jfree.chart.ChartPanel(chart);
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, groupActivatingPanel, chartPanel);
    splitPane.setDividerLocation(200);
    mainPanel().add(BorderLayout.CENTER, splitPane);
}

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

/**
 * Constructs the demo application./* w  ww . j  av a 2s  . c  o  m*/
 *
 * @param title  the frame title.
 */
public XYBarChartDemo(final String title) {

    super(title);

    final TimeSeriesCollection data = DemoDatasetFactory.createTimeSeriesCollection1();
    data.setDomainIsPointsInTime(false);
    final JFreeChart chart = ChartFactory.createXYBarChart(title, "X", true, "Y", data,
            PlotOrientation.VERTICAL, true, false, false);

    // then customise it a little...
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue));

    final XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    final StandardXYToolTipGenerator generator = new StandardXYToolTipGenerator("{1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0.00"));
    renderer.setToolTipGenerator(generator);

    final XYPlot plot = chart.getXYPlot();
    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
    setContentPane(chartPanel);

}

From source file:org.operamasks.faces.render.graph.BarChartRenderer.java

protected JFreeChart createChart(UIChart comp) {
    Dataset dataset = createDataset(comp);
    JFreeChart chart = null;//from  w  w  w . j  av  a 2  s  .  c  o  m

    if (dataset instanceof CategoryDataset) {
        if (comp.isStacked()) {
            if (comp.isEffect3D()) {
                chart = ChartFactory.createStackedBarChart3D(null, null, null, (CategoryDataset) dataset,
                        getChartOrientation(comp), false, false, false);
            } else {
                chart = ChartFactory.createStackedBarChart(null, null, null, (CategoryDataset) dataset,
                        getChartOrientation(comp), false, false, false);
            }
        } else {
            if (comp.isEffect3D()) {
                chart = ChartFactory.createBarChart3D(null, null, null, (CategoryDataset) dataset,
                        getChartOrientation(comp), false, false, false);
            } else {
                chart = ChartFactory.createBarChart(null, null, null, (CategoryDataset) dataset,
                        getChartOrientation(comp), false, false, false);
            }
        }
    } else if (dataset instanceof IntervalXYDataset) {
        chart = ChartFactory.createXYBarChart(null, null, (dataset instanceof TimeSeriesCollection), null,
                (IntervalXYDataset) dataset, getChartOrientation(comp), false, false, false);
    }

    return chart;
}

From source file:com.marvelution.jira.plugins.hudson.charts.BuildResultsRatioChartGenerator.java

/**
 * {@inheritDoc}//  w  w  w.j  a v a  2  s  .c  o m
 */
@Override
public ChartHelper generateChart() {
    final Map<Integer, Build> buildMap = new HashMap<Integer, Build>();
    final CategoryTableXYDataset dataSet = new CategoryTableXYDataset();
    for (Build build : builds) {
        buildMap.put(Integer.valueOf(build.getBuildNumber()), build);
        dataSet.add(Double.valueOf(build.getBuildNumber()), Double.valueOf(build.getDuration()),
                getI18n().getText("hudson.charts.duration"));
    }
    final JFreeChart chart = ChartFactory.createXYBarChart("", "", false,
            getI18n().getText("hudson.charts.duration"), dataSet, PlotOrientation.VERTICAL, false, false,
            false);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderVisible(false);
    final BuildResultRenderer renderer = new BuildResultRenderer(server, buildMap);
    renderer.setBaseItemLabelFont(ChartDefaults.defaultFont);
    renderer.setBaseItemLabelsVisible(false);
    renderer.setMargin(0.0D);
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));
    renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer.setBaseToolTipGenerator(renderer);
    renderer.setURLGenerator(renderer);
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.setAxisOffset(new RectangleInsets(1.0D, 1.0D, 1.0D, 1.0D));
    xyPlot.setRenderer(renderer);
    final NumberAxis domainAxis = new NumberAxis();
    domainAxis.setLowerBound(Collections.min(buildMap.keySet()));
    domainAxis.setUpperBound(Collections.max(buildMap.keySet()));
    final TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    domainAxis.setStandardTickUnits(ticks);
    xyPlot.setDomainAxis(domainAxis);
    final DateAxis rangeAxis = new DateAxis();
    final DurationFormat durationFormat = new DurationFormat();
    rangeAxis.setDateFormatOverride(durationFormat);
    rangeAxis.setLabel(getI18n().getText("hudson.charts.duration"));
    xyPlot.setRangeAxis(rangeAxis);
    ChartUtil.setupPlot(xyPlot);
    return new ChartHelper(chart);
}