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:classes.SharedClass.java

public void getStatistics() {
    result = db.select("member", new String[] { " count(id) id" }, new String[] { "id" },
            new String[] { "99999" }, "!=", "and");
    try {/* www  .j  av a2s . co m*/
        if (result.next()) {
            memberId = result.getInt("id");
        }
    } catch (SQLException ex) {
        Logger.getLogger(SharedClass.class.getName()).log(Level.SEVERE, null, ex);
        ex.printStackTrace();
    }

    //book
    result = db.select("book", new String[] { "count(id)" }, new String[] { "id" }, new String[] { "99999" },
            "!=", "and");
    try {
        if (result.next()) {
            bookId = result.getInt(1);
        }
    } catch (SQLException ex) {
        Logger.getLogger(SharedClass.class.getName()).log(Level.SEVERE, null, ex);
    }

    //operations
    result = db.select("operations", new String[] { "count(id)" }, new String[] { "type" },
            new String[] { "borrowed" }, "=", "and");
    try {
        if (result.next()) {
            operationsId = result.getInt(1);
        }
    } catch (SQLException ex) {
        Logger.getLogger(SharedClass.class.getName()).log(Level.SEVERE, null, ex);
    }
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    dataSet.setValue(memberId, "Percent", "Members");
    dataSet.setValue(bookId, "Percent", "Books");
    dataSet.setValue(operationsId, "Percent", "Borrowe books");
    JFreeChart chart = ChartFactory.createBarChart3D("Statistics", "Fields", "Percent", dataSet,
            PlotOrientation.VERTICAL, false, true, false);
    chart.setBackgroundPaint(Color.yellow);
    chart.getTitle().setPaint(Color.red);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeGridlinePaint(Color.blue);
    ChartFrame frame = new ChartFrame("Statistics", chart);
    frame.setLocationRelativeTo(null);
    frame.setSize(500, 550);
    frame.setVisible(true);
}

From source file:net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffHandler.java

/**
 * use default orientation or orientation of axis
 * /*ww w .  java2 s .  c  o m*/
 * @param event
 * @return
 */
public Orientation getOrientation(ChartGestureEvent event) {
    ChartEntity ce = event.getEntity();
    if (ce instanceof AxisEntity) {
        JFreeChart chart = event.getChart();
        PlotOrientation plotorient = PlotOrientation.HORIZONTAL;
        if (chart.getXYPlot() != null)
            plotorient = chart.getXYPlot().getOrientation();
        else if (chart.getCategoryPlot() != null)
            plotorient = chart.getCategoryPlot().getOrientation();

        Entity entity = event.getGesture().getEntity();
        if ((entity.equals(Entity.DOMAIN_AXIS) && plotorient.equals(PlotOrientation.VERTICAL))
                || (entity.equals(Entity.RANGE_AXIS) && plotorient.equals(PlotOrientation.HORIZONTAL)))
            orient = Orientation.HORIZONTAL;
        else
            orient = Orientation.VERTICAL;
    }
    return orient;
}

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

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

    super(title);
    final CategoryDataset dataset1 = createRandomDataset("Series 1");
    final JFreeChart chart = ChartFactory.createLineChart("Secondary Dataset Demo 2", "Category", "Value",
            dataset1, PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.white);

    this.plot = chart.getCategoryPlot();
    this.plot.setBackgroundPaint(Color.lightGray);
    this.plot.setDomainGridlinePaint(Color.white);
    this.plot.setRangeGridlinePaint(Color.white);
    //        this.plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));

    final NumberAxis rangeAxis = (NumberAxis) this.plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(false);

    final JPanel content = new JPanel(new BorderLayout());

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JButton button1 = new JButton("Add Dataset");
    button1.setActionCommand("ADD_DATASET");
    button1.addActionListener(this);

    final JButton button2 = new JButton("Remove Dataset");
    button2.setActionCommand("REMOVE_DATASET");
    button2.addActionListener(this);

    final JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(button1);
    buttonPanel.add(button2);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(content);

}

From source file:Reportes.BarChart.java

public ChartPanel reporteOrdenesEmpresa(DefaultCategoryDataset data) {
    JFreeChart chart = ChartFactory.createBarChart("Reporte de ordenes de trabajo por sede", "Sedes",
            "Cantidad", data, PlotOrientation.VERTICAL, true, true, true);

    CategoryPlot categoryP = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) categoryP.getRenderer();
    renderer.setMaximumBarWidth(0.35);//from  ww  w.j  av  a  2 s.com
    Color color = new Color(67, 165, 208);
    renderer.setSeriesPaint(0, color);

    ChartPanel panel = new ChartPanel(chart, true, true, true, false, false);
    panel.setSize(ancho, alto);

    return panel;
}

From source file:co.udea.edu.proyectointegrador.gr11.parqueaderoapp.domain.stadistics.graphics.implement.Grafica.java

@Override
public void updateChartForVehicleType(JFreeChart vehicleTypeChart,
        List<TipoVehiculoEstadistica> estadisticasVehiculo) {
    DefaultCategoryDataset categoryDataset = createDataForVehicleType(estadisticasVehiculo);
    CategoryPlot categoryPlot = vehicleTypeChart.getCategoryPlot();
    categoryPlot.setDataset(categoryDataset);
}

From source file:Reportes.BarChart.java

public ChartPanel reporteCantidadVehiculosPorSede(DefaultCategoryDataset data) {
    JFreeChart chart = ChartFactory.createBarChart("Reporte de cantidad de vehiculos por sede", "Sedes",
            "Cantidad", data, PlotOrientation.VERTICAL, true, true, true);

    CategoryPlot categoryP = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) categoryP.getRenderer();
    renderer.setMaximumBarWidth(0.35);/*w  ww  .ja  v a  2 s.c  o  m*/
    Color color = new Color(67, 165, 208);
    renderer.setSeriesPaint(0, color);

    ChartPanel panel = new ChartPanel(chart, true, true, true, false, false);
    panel.setSize(ancho, alto);

    return panel;
}

From source file:org.pentaho.chart.plugin.jfreechart.chart.bar.JFreeLayeredBarChartGenerator.java

/**
 * Creates layered bar chart and creates range axis for it.
 * </p>//from  w ww . j  a  va2s  . c o m
 * @param chartDocContext Current chart's document context
 * @param data Current chart data
 * @return Returns JFree layered bar chart.
 */
protected JFreeChart doCreateChart(final ChartDocumentContext chartDocContext, final ChartTableModel data) {
    final JFreeChart chart = createChart(chartDocContext, data, JFreeBarChartTypes.DEFAULT);
    /*
     * Doing all the render stuff and then off to create range axis.
     * NOTE: The chart object will be updated.
     */
    final LayeredBarRenderer renderer = new LayeredBarRenderer();
    renderer.setDrawBarOutline(false);
    chart.getCategoryPlot().setRenderer(renderer);
    chart.getCategoryPlot().setRowRenderingOrder(SortOrder.DESCENDING);

    createRangeAxis(chartDocContext, data, chart);
    return chart;
}

From source file:Software_Jframes.chart.java

public void barchart(JDesktopPane jdesktop) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    try {//from  ww  w  .j a v  a  2  s.  c o m
        ResultSet rs = db.statement().executeQuery("select date,name,amount from other_exp");
        while (rs.next()) {
            String date = rs.getString("date");
            String name = rs.getString("name");
            String amnt = rs.getString("Amount");
            int amount = Integer.parseInt(amnt);
            dataset.setValue(amount, name, date);
        }
    } catch (Exception e) {
    }

    JFreeChart chart = ChartFactory.createBarChart("Other Expenses for Last week", "Date", "Expense", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setBackgroundPaint(Color.WHITE);
    p.setRangeGridlinePaint(Color.black);
    ChartPanel panel = new ChartPanel(chart);
    jdesktop.add(panel).setSize(550, 230);
}

From source file:Reportes.BarChart.java

public ChartPanel reporteCantidadCotizacionesEmpresa(DefaultCategoryDataset data) {
    JFreeChart chart = ChartFactory.createBarChart("Reporte de cantidad de cotizaciones por sede", "Sede",
            "Cantidad", data, PlotOrientation.VERTICAL, true, true, true);

    CategoryPlot categoryP = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) categoryP.getRenderer();
    renderer.setMaximumBarWidth(0.35);/*from w  ww.  java 2  s .c  o m*/
    Color color = new Color(67, 165, 208);
    renderer.setSeriesPaint(0, color);

    ChartPanel panel = new ChartPanel(chart, true, true, true, false, false);
    panel.setSize(ancho, alto);

    return panel;
}

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

/**
 * Returns the chart.//ww  w  .j  a  va 2 s.  c  om
 * 
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createWaterfallChart(chartTitle, domainLabel, rangeLabel, dataset,
            PlotOrientation.VERTICAL, !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();

    // create a custom tick unit collection...
    DecimalFormat formatter = new DecimalFormat("##,###");
    formatter.setNegativePrefix("(");
    formatter.setNegativeSuffix(")");
    TickUnits standardUnits = new TickUnits();
    standardUnits.add(new NumberTickUnit(5, formatter));
    standardUnits.add(new NumberTickUnit(10, formatter));
    standardUnits.add(new NumberTickUnit(20, formatter));
    standardUnits.add(new NumberTickUnit(50, formatter));
    standardUnits.add(new NumberTickUnit(100, formatter));
    standardUnits.add(new NumberTickUnit(200, formatter));
    standardUnits.add(new NumberTickUnit(500, formatter));
    standardUnits.add(new NumberTickUnit(1000, formatter));
    standardUnits.add(new NumberTickUnit(2000, formatter));
    standardUnits.add(new NumberTickUnit(5000, formatter));
    rangeAxis.setStandardTickUnits(standardUnits);

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

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

    setCategorySummary(dataset);
    return chart;
}