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:biz.ixnay.pivot.charts.skin.jfree.BarChartViewSkin.java

@Override
protected JFreeChart createChart() {
    BarChartView chartView = (BarChartView) getComponent();

    String title = chartView.getTitle();
    String horizontalAxisLabel = chartView.getHorizontalAxisLabel();
    String verticalAxisLabel = chartView.getVerticalAxisLabel();
    boolean showLegend = chartView.getShowLegend();

    String seriesNameKey = chartView.getSeriesNameKey();
    List<?> chartData = chartView.getChartData();

    // TODO Make plot orientation a style property

    JFreeChart chart;/*  ww  w. j  a v a  2 s . c  o  m*/
    ChartView.CategorySequence categories = chartView.getCategories();
    if (categories.getLength() > 0) {
        CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData);

        if (stacked && threeDimensional) {
            chart = ChartFactory.createStackedBarChart3D(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else if (stacked) {
            chart = ChartFactory.createStackedBarChart(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else if (threeDimensional) {
            chart = ChartFactory.createBarChart3D(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else {
            chart = ChartFactory.createBarChart(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        }

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryAxis domainAxis = plot.getDomainAxis();
        CategoryLabelPositions categoryLabelPositions = CategoryLabelPositions
                .createUpRotationLabelPositions(categoryLabelRotation);
        domainAxis.setCategoryLabelPositions(categoryLabelPositions);
    } else {
        // TODO Make the dateAxis argument a style property
        chart = ChartFactory.createXYBarChart(title, horizontalAxisLabel, false, verticalAxisLabel,
                new IntervalSeriesDataset(seriesNameKey, chartData), PlotOrientation.VERTICAL, showLegend,
                false, false);
    }

    return chart;
}

From source file:org.systemsbiology.mzxmlviewer.utilities.SpectrumComponent.java

public void setScan(Scan s) {
    if (chart == null) {
        data = new MyDataSet(s.getMassIntensityList());
        chart = ChartFactory.createXYBarChart("Spectrum @ " + s.getRetentionTime() + " s", "m/z", false,
                "intensity", data, PlotOrientation.VERTICAL, false, false, false);

        //chart.getXYPlot().setDomainAxis(new NumberAxis());
        //chart.getXYPlot().setRangeAxis(new NumberAxis());
        XYBarRenderer renderer = new XYBarRenderer();
        renderer.setSeriesItemLabelsVisible(0, new Boolean(true));
        chart.getXYPlot().setRenderer(renderer);
        removeAll();/*from w w w.j  a v  a2s .com*/
        add(new ChartPanel(chart));
        validate();
        repaint();
    }

    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(1);
    chart.setTitle("Spectrum @ " + format.format(s.getDoubleRetentionTime()) + " s");
    chart.getXYPlot().clearDomainMarkers();
    if (s.getMsLevel() == 2)
        chart.getXYPlot().addDomainMarker(new ValueMarker(s.getPrecursorMz()));
    data.setData(s.getMassIntensityList());
}

From source file:gov.redhawk.statistics.ui.views.StatisticsView.java

/**
 * This is a callback that will allow us to create the viewer and initialize it.
 *///www.  ja  v a  2s  .  c om
@Override
public void createPartControl(Composite comp) {

    parent = comp;
    parent.setLayout(GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(1).create());

    // Custom Action for the View's Menu
    CustomAction customAction = new CustomAction() {

        @Override
        public void run() {
            SettingsDialog dialog = new SettingsDialog(parent.getShell(), datalist.length, curIndex, numBars);
            dialog.create();
            if (dialog.open() == Window.OK) {
                numBars = dialog.getNumBars();
                curIndex = dialog.getSelectedIndex();
                refreshJob.schedule();
            }
        }
    };
    customAction.setText("Settings");
    getViewSite().getActionBars().getMenuManager().add(customAction);

    // creation of chart composite and selection of associated options
    Composite chartComposite = new Composite(parent, SWT.EMBEDDED);
    chartComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    chart = ChartFactory.createXYBarChart(null, null, false, null, dataSet, PlotOrientation.VERTICAL, false,
            true, false);

    org.eclipse.swt.graphics.Color backgroundColor = chartComposite.getBackground();
    chart.setBackgroundPaint(
            new Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue()));
    chart.getXYPlot().setBackgroundPaint(ChartColor.WHITE);

    Frame chartFrame = SWT_AWT.new_Frame(chartComposite);
    chartFrame.setBackground(
            new Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue()));
    chartFrame.setLayout(new GridLayout());

    ChartPanel jFreeChartPanel = new ChartPanel(chart);
    chartFrame.add(jFreeChartPanel);

    ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer();
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setMargin(0.05);
    renderer.setShadowVisible(false);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() {
        @Override
        public String generateLabel(XYDataset dataset, int series, int item) {
            return String.valueOf((int) (dataset.getYValue(series, item)));
        }
    });
    renderer.setBasePaint(new Color(139, 0, 0));
    renderer.setLegendItemLabelGenerator(new XYSeriesLabelGenerator() {

        @Override
        public String generateLabel(XYDataset ds, int i) {
            if (ds.getSeriesCount() == 2) {
                if (i == 0) {
                    return "Real";
                } else if (i == 1) {
                    return "Imaginary";
                } else {
                    return "Complex";
                }
            } else if (ds.getSeriesCount() > 1) {
                return "Dimension " + i;
            }

            return null;
        }
    });
    chart.getXYPlot().setRenderer(renderer);

    dataSet.addChangeListener(new DatasetChangeListener() {

        @Override
        public void datasetChanged(DatasetChangeEvent event) {
            chart.getPlot().datasetChanged(event);

        }
    });

    // creation of the statistics composite
    FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    section = toolkit.createSection(parent, Section.DESCRIPTION | Section.NO_TITLE | Section.CLIENT_INDENT);
    section.setBackground(parent.getBackground());
    section.setDescription("");
    section.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); // layout within parent

    // Composite for storing the data
    Composite composite = toolkit.createComposite(section, SWT.WRAP);
    composite.setBackground(parent.getBackground());
    composite.setLayout(GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(4).create());
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); // layout within parent
    toolkit.paintBordersFor(composite);
    section.setClient(composite);

    for (int j = 0; j < STAT_PROPS.length; j++) {
        Label label = new Label(composite, SWT.None);
        label.setText(STAT_PROPS[j] + ":");
        labels[j] = new Label(composite, SWT.None);
        labels[j].setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    }

}

From source file:org.geotoolkit.gui.swing.propertyedit.styleproperty.JAnalizePanel.java

public JFreeChart getChart(final int nbDivision) {
    XYSeries series = new XYSeries("Data");

    double before = analyze.getMinimum();
    for (float i = 1; i <= nbDivision; i++) {
        final double localmin = before;
        final double localmax = analyze.getMinimum()
                + (i / nbDivision) * (analyze.getMaximum() - analyze.getMinimum());
        before = localmax;//w  w  w  .  j a  v  a2 s  .  co  m
        long localsum = 0;

        for (Double d : analyze.getAllValues()) {
            if (i == 100) {
                //last element
                if (d >= localmin && d <= localmax) {
                    localsum++;
                }
            } else {
                if (d >= localmin && d < localmax) {
                    localsum++;
                }
            }
        }
        series.add(analyze.getMinimum() + (localmin + localmax) / 2, localsum);
    }

    XYSeriesCollection dataset = new XYSeriesCollection(series);

    JFreeChart chart = ChartFactory.createXYBarChart("", "", false, "", dataset, PlotOrientation.VERTICAL,
            false, false, false);

    XYPlot plot = chart.getXYPlot();
    ((XYBarRenderer) plot.getRenderer()).setShadowVisible(false);
    ((XYBarRenderer) plot.getRenderer()).setUseYInterval(false);
    ((XYBarRenderer) plot.getRenderer()).setMargin(0);

    chart.getPlot().setBackgroundAlpha(0);
    chart.setBackgroundPaint(new Color(0f, 0f, 0f, 0f));

    return chart;
}

From source file:com.wsntools.iris.tools.Graph.java

public void switchGraphType(int type) {

    if (type != charttype) {

        switch (type) {
        case 0://from w w w  .j  a  v a 2 s  .c o m
            setupChartType(ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL,
                    true, true, false));
            break;
        case 1:
            setupChartType(ChartFactory.createXYBarChart(null, null, false, null, null,
                    PlotOrientation.VERTICAL, true, true, false));
            break;
        }

        charttype = type;
    }

}

From source file:eu.hydrologis.jgrass.charting.impl.JGrassXYBarChart.java

public JFreeChart getChart(String title, String xLabel, String yLabel, PlotOrientation porient,
        boolean withLegend, boolean withTooltips, boolean withUrls) {
    if (porient == null) {
        porient = PlotOrientation.VERTICAL;
    }/*from   w  ww . j a v  a  2  s .c o  m*/

    theChart = ChartFactory.createXYBarChart(title, xLabel, false, yLabel, dataset, porient, withLegend,
            withTooltips, withUrls);
    // also create the plot obj for customizations
    thePlot = theChart.getXYPlot();
    renderer = (XYBarRenderer) ((XYPlot) thePlot).getRenderer();

    return theChart;
}

From source file:org.knime.knip.core.ui.imgviewer.panels.HistogramBC.java

private JFreeChart createChart(final String title, final List<XYSeries> series) {
    final XYSeriesCollection data = new XYSeriesCollection();
    for (XYSeries xys : series) {
        data.addSeries(xys);/*  www  . ja v a  2  s.  c o  m*/
    }
    final JFreeChart chart = ChartFactory.createXYBarChart(title, null, false, null, data,
            PlotOrientation.VERTICAL, false, true, false);
    setTheme(chart);
    // chart.getXYPlot().setForegroundAlpha(0.50f);
    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.XYBarChartDemo2.java

/** 
 * Creates a chart.//ww  w. jav  a 2  s  .c  om
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(IntervalXYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            true, rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            //false,   // when choose no legend, the color order used in chart is different 
            true, false);

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new ClusteredXYBarRenderer());

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yy"), new DecimalFormat("#,##0.00")));
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    // OPTIONAL CUSTOMISATION COMPLETED.

    //setXSummary(dataset);  X is time
    return chart;
}

From source file:org.graphstream.algorithm.measure.ChartConnectivityMeasure.java

public JFreeChart createChart(PlotParameters params) throws PlotException {
    JFreeChart chart;//from ww w  . j a va 2s  .c  o m
    XYSeriesCollection dataset = new XYSeriesCollection();

    dataset.addSeries(vertexConnectivity.getXYSeries());
    dataset.addSeries(edgeConnectivity.getXYSeries());

    switch (params.type) {
    case LINE:
        chart = ChartFactory.createXYLineChart(params.title, params.xAxisLabel, params.yAxisLabel, dataset,
                params.orientation, params.showLegend, false, false);
        break;
    case BAR:
        chart = ChartFactory.createXYBarChart(params.title, params.xAxisLabel, false, params.yAxisLabel,
                dataset, params.orientation, params.showLegend, false, false);
        break;
    case SCATTER:
        chart = ChartFactory.createScatterPlot(params.title, params.xAxisLabel, params.yAxisLabel, dataset,
                params.orientation, params.showLegend, false, false);
        break;
    default:
        throw new PlotException("unsupported plot type");
    }

    return chart;
}

From source file:be.nbb.demetra.dfm.output.simulation.RMSEGraphView.java

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

    XYPlot plot = result.getXYPlot();/* w w w . j  a  va2s . c  om*/

    plot.setDataset(DFM_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(DFM_INDEX, dfmRenderer);
    plot.mapDatasetToDomainAxis(DFM_INDEX, 0);
    plot.mapDatasetToRangeAxis(DFM_INDEX, 0);

    plot.setDataset(ARIMA_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(ARIMA_INDEX, arimaRenderer);
    plot.mapDatasetToDomainAxis(ARIMA_INDEX, 0);
    plot.mapDatasetToRangeAxis(ARIMA_INDEX, 0);

    plot.setDataset(STDEV_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(STDEV_INDEX, stdevRenderer);
    plot.mapDatasetToDomainAxis(STDEV_INDEX, 0);
    plot.mapDatasetToRangeAxis(STDEV_INDEX, 0);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

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

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

    return result;
}