Example usage for org.jfree.chart JFreeChart getCategoryPlot

List of usage examples for org.jfree.chart JFreeChart getCategoryPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getCategoryPlot.

Prototype

public CategoryPlot getCategoryPlot() 

Source Link

Document

Returns the plot cast as a CategoryPlot .

Usage

From source file:net.pickapack.chart.BarPlotFrame.java

/**
 * Create a bar plot frame./*from w  w w.  j a  v  a  2 s .c  om*/
 *
 * @param barPlot the bar plot
 * @param domainAxisLabel the domain axis label
 * @param width the width
 * @param height the height
 */
public BarPlotFrame(BarPlot<ItemT> barPlot, String domainAxisLabel, int width, int height) {
    super(barPlot.getTitle());

    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

    for (ItemT item : barPlot.getItems()) {
        if (barPlot.getPredicate().apply(item)) {
            for (SubBarPlot<ItemT> subBarPlot : barPlot.getSubBarPlots()) {
                dataSet.addValue(subBarPlot.getGetValueCallback().apply(item), subBarPlot.getTitle(),
                        subBarPlot.getGetTitleCallback().apply(item));
            }
        }
    }

    JFreeChart chart = barPlot.isStacked()
            ? ChartFactory.createStackedBarChart(barPlot.getTitle(), domainAxisLabel, barPlot.getTitleY(),
                    dataSet, PlotOrientation.VERTICAL, true, true, false)
            : ChartFactory.createBarChart(barPlot.getTitle(), domainAxisLabel, barPlot.getTitleY(), dataSet,
                    PlotOrientation.VERTICAL, true, true, false);

    CategoryPlot plot = chart.getCategoryPlot();

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    ChartPanel chartPanel = new ChartPanel(chart, false);
    chartPanel.setPreferredSize(new Dimension(width, height));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(chartPanel);
}

From source file:playground.thibautd.utils.charts.ChartsAxisUnifier.java

public void applyUniformisation() {
    for (JFreeChart chart : charts) {
        Plot plot = chart.getPlot();//from w  ww .j  av  a  2  s.co  m
        ValueAxis xAxis = null;
        ValueAxis yAxis = null;

        if (plot instanceof XYPlot) {
            xAxis = unifyX ? chart.getXYPlot().getDomainAxis() : null;
            yAxis = unifyY ? chart.getXYPlot().getRangeAxis() : null;
        } else if (plot instanceof CategoryPlot) {
            yAxis = unifyY ? chart.getCategoryPlot().getRangeAxis() : null;
        }

        if (xAxis != null)
            xAxis.setRange(lowerX, upperX);
        if (yAxis != null)
            yAxis.setRange(lowerY, upperY);
    }
}

From source file:j2se.jfreechart.barchart.BarChart3DDemo1.java

/**
 * Creates a chart./*w  ww  .j ava2  s .com*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createBarChart3D("3D Bar Chart Demo", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0));
    final BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    return chart;

}

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

/**
 * Creates a sample chart.//from w  w w  .j  a va 2s.com
 * 
 * @param dataset  the dataset for the chart.
 * 
 * @return a sample chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 3", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            false, // tooltips
            false // urls
    );
    final CategoryPlot plot = chart.getCategoryPlot();
    //        final CategoryItemRenderer renderer = new ExtendedStackedBarRenderer();
    //      renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    //    plot.setRenderer(renderer);

    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);
    return chart;

}

From source file:org.metacsp.utility.UI.PlotActivityNetworkGantt.java

/**
 * Create a new Gantt JFrame//from  w w  w .  j a v a2  s.  c o m
 * @param s {@link ActivityNetworkSolver} to be plotted as Gantt
 * @param selectedVariables {@link Vector} of {@link ActivityNetworkSolver}'s component names (variable names) that will be plotted.
 * @param n {@link JFrame} title
 */
public PlotActivityNetworkGantt(ActivityNetworkSolver s, Vector<String> selectedVariables, String n) {
    super(n);
    this.solver = s;
    this.selectedVariables = selectedVariables;

    GanttRenderer renderer = new GanttRenderer();
    renderer.setBaseItemLabelFont(new Font("Tahoma", Font.PLAIN, 11));

    JFreeChart chart = ChartFactory.createGanttChart(null, // "Channel", //
            "Activities & Resources", // domain axis label
            null, // "Time", // range axis label
            createDataset(), // data
            false, // do not include legend
            false, // no tooltips
            false // urls
    );

    chart.getCategoryPlot().setRenderer(renderer);
    renderer.setSeriesPaint(0, Color.green.darker());
    renderer.setSeriesPaint(1, Color.red.darker());
    renderer.setItemMargin(-0.5);

    chart.getCategoryPlot().setRangeAxis(new NumberAxis());

    chart.getCategoryPlot().getRangeAxis().setLabelFont(new Font("Arial", Font.PLAIN, 14));
    chart.getCategoryPlot().getDomainAxis().setLabelFont(new Font("Arial", Font.PLAIN, 14));
    chart.getCategoryPlot().getDomainAxis().setTickLabelsVisible(true);
    chart.getCategoryPlot().getRangeAxis().setAutoRange(false);

    chartPanel = new ChartPanel(chart);
    chartPanel.setDomainZoomable(true);
    chartPanel.setRangeZoomable(true);

    setContentPane(new JScrollPane(chartPanel));
    this.setPreferredSize(new Dimension(800, 600));
    this.setSize(new Dimension(800, 600));
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.setVisible(true);
}

From source file:j2se.jfreechart.barchart.BarChart3DDemo3.java

/**
 * Creates a chart.//w w w . j  a  v a 2s . co m
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createBarChart3D("3D Bar Chart Demo", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0));

    final CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    final BarRenderer r = (BarRenderer) renderer;
    r.setMaximumBarWidth(0.05);

    return chart;

}

From source file:view.PnStatistic.java

private ChartPanel createBarChart(CategoryDataset dataset) {
    JFreeChart barChart = ChartFactory.createBarChart3D("Thng k", "Th?i gian", "Thu nhp", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(barChart);
    CategoryPlot plot = barChart.getCategoryPlot();
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    numberAxis.setNumberFormatOverride(new NumberFormat() {
        @Override/*from w w  w . ja  va2 s .  c  om*/
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
            return new StringBuffer(CommonFunction.convertDoubleToMoney(number));
        }

        @Override
        public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
            return new StringBuffer(CommonFunction.convertDoubleToMoney(number));
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    });
    return chartPanel;
}

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

/**
 * Returns the chart.//w w  w . ja va  2  s  .  co m
 * 
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createBarChart(chartTitle, domainLabel, rangeLabel, dataset,
            PlotOrientation.VERTICAL, false, //!legendPanelOn,
            true, false);
    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    ValueAxis rangeAxis = plot.getRangeAxis();

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    DecimalFormat labelFormatter = new DecimalFormat("##,###.##");
    labelFormatter.setNegativePrefix("(");
    labelFormatter.setNegativeSuffix(")");
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", labelFormatter));
    renderer.setBaseItemLabelsVisible(true);

    //setCategorySummary(dataset);
    return chart;
}

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

/**
 * Creates a chart./*  w  w  w  .j  av a 2  s .  com*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createBarChart3D("3D Bar Chart Demo", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0));

    final CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    final BarRenderer r = (BarRenderer) renderer;
    r.setMaxBarWidth(0.05);

    return chart;

}

From source file:User.Interface.SupplierAdminRole.ReviewSalesJPanel.java

private void displayBarCharts() {

    //check if the supplier has products in the product list
    if (supplierAdminOrganization.getMedicalDeviceCatalog().getMedicalDeviceList().size() < 0) {
        JOptionPane.showMessageDialog(this, "No products found from selected supplier.", "Warning",
                JOptionPane.WARNING_MESSAGE);
        return;//from   ww  w .j  a v a  2 s  .  c o  m
    }

    MedicalDevice[] product;
    product = new MedicalDevice[100];

    int numberOfProducts = supplierAdminOrganization.getMedicalDeviceCatalog().getMedicalDeviceList().size();
    DefaultCategoryDataset dataSetProduct = new DefaultCategoryDataset();

    for (int i = 0; i < numberOfProducts; i++) {
        product[i] = supplierAdminOrganization.getMedicalDeviceCatalog().getMedicalDeviceList().get(i);
        int soldQuantity = 0;
        soldQuantity = product[i].getSoldQuantity();
        String prodName = product[i].getDeviceName();
        dataSetProduct.setValue(soldQuantity, "Medical Device", prodName);
    }

    JFreeChart chartProduct = ChartFactory.createBarChart("Supplier Performance Report", "Products",
            "Number of Products Sold", dataSetProduct, PlotOrientation.VERTICAL, false, true, false);

    CategoryPlot p1 = chartProduct.getCategoryPlot();
    p1.setRangeGridlinePaint(Color.black);
    ChartFrame frame1 = new ChartFrame("Supplier Performance Report", chartProduct);
    frame1.setVisible(true);
    frame1.setSize(400, 400);
    Point pt1 = new Point(0, 0);
    frame1.setLocation(pt1);
}