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:edu.ucla.stat.SOCR.chart.demo.EventFrequencyDemo1.java

protected JFreeChart createLegend(CategoryDataset dataset) {

    //  JFreeChart chart = ChartFactory.createAreaChart(
    JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );//from  w w  w  . java2s  .  c om

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = chart.getCategoryPlot();

    LineAndShapeRenderer renderer = new LineAndShapeRenderer(false, true);
    plot.setRenderer(renderer);
    return chart;

}

From source file:view.statistics.RequestStatsAndPrediction.java

/**
 * Creates new form PredictRequests/*from   www . ja  v a2s. c om*/
 */
public RequestStatsAndPrediction() throws FileNotFoundException, IOException {
    initComponents();
    FileInputStream imgStream = null;
    File imgfile = new File("..\\BBMS\\src\\images\\drop.png");
    imgStream = new FileInputStream(imgfile);
    BufferedImage bi = ImageIO.read(imgStream);
    ImageIcon myImg = new ImageIcon(bi);
    this.setFrameIcon(myImg);
    setTitle("Request Statistics and Prediction");
    sdcontroller = new SampleDetailsController();
    Calendar calendar = Calendar.getInstance();
    yearChooser.setStartYear(calendar.get(Calendar.YEAR));
    monthChooser.setMonth(calendar.get(calendar.MONTH) + 1);

    int year = yearChooser.getYear();
    int month = monthChooser.getMonth() + 1;

    int currentYear = Calendar.getInstance().get(Calendar.YEAR);
    int currentMonth = Calendar.getInstance().get(Calendar.MONTH) + 1;

    int data[][] = null;

    try {
        data = sdcontroller.getYearlyRequestCountsOf(month);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(RequestStatsAndPrediction.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(RequestStatsAndPrediction.class.getName()).log(Level.SEVERE, null, ex);
    }

    if (year >= currentYear && month >= currentMonth) {

        try {
            predictText.setText(Predictions.getPredictedRequestsOf(year, month) + "");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(RequestStatsAndPrediction.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(RequestStatsAndPrediction.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        JOptionPane.showMessageDialog(this,
                "Predictions available only for future months. Only the graph will be drawn", "Error",
                JOptionPane.ERROR_MESSAGE);
        predictText.setText("Invalid input!");
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if (data != null) {
        for (int i = 0; i < data[0].length; i++) {
            dataset.setValue(data[1][i], "Bla bla bla", data[0][i] + "");
        }
    }

    JFreeChart chart = ChartFactory.createLineChart3D(
            "Yearly Blood Request Count For The Month of " + getMontName(month + ""), "Year", "Request Count",
            dataset, PlotOrientation.VERTICAL, false, true, false);
    chart.setBackgroundPaint(Color.PINK);
    chart.getTitle().setPaint(Color.RED);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.BLUE);

    ChartPanel panel = new ChartPanel(chart);
    panel.setPreferredSize(new java.awt.Dimension(200, 350));
    chartAreaPanel.setLayout(new GridLayout());
    chartAreaPanel.removeAll();
    chartAreaPanel.revalidate();
    chartAreaPanel.add(panel);
    chartAreaPanel.repaint();

    this.repaint();

}

From source file:cgpanalyser.gui.EvoInfoChart.java

private JFreeChart createChart(final CategoryDataset dataset, long[] gateFuncsCounts,
        GateFuctionsAll gateFuncsAll) {/*ww w  .j a va 2s.  c  om*/

    final JFreeChart chart = ChartFactory.createBarChart(null, "Function", "Usage", dataset,
            PlotOrientation.VERTICAL, false, true, false);

    //match colors of bars to colors in function file (or black if not specified)
    Paint[] colors = new Paint[gateFuncsCounts.length];
    for (byte i = 0; i < colors.length; i++) {
        colors[i] = gateFuncsAll.getColorIfAvailable(i);
    }
    final CategoryItemRenderer renderer = new CustomRenderer(colors);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRenderer(renderer);
    ((BarRenderer) plot.getRenderer()).setBarPainter(new StandardBarPainter()); //no gradient

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    //CategoryAxis axis = plot.getDomainAxis();
    //NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); //set x axis tick
    //xAxis.setVerticalTickLabels(true); //set x axis text rotation

    return chart;

}

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

@Override
public JFreeChart createBarChartToVehicleType(List<TipoVehiculoEstadistica> tipoVehiculos) {
    //Se crea el conjunto de datos para realizar el grafico de barras

    DefaultCategoryDataset dataset = createDataForVehicleType(tipoVehiculos);

    //Se crea el grafico de barras
    JFreeChart chart = ChartFactory.createBarChart3D(TITLE_OF_BAR_CHART, //Titulo del grfico
            DOMAIN_AXIS_LABEL, //Nombre del dominio
            RANGE_AXIS_LABEL, //Nombre del Rango
            dataset, //Conjunto de datos
            PlotOrientation.VERTICAL, //Orientacion del grafico
            true, //Incluye leyendas
            true, false);// www . j ava2s .c  o m
    //Se pinta el fondo de blanco
    chart.setBackgroundPaint(Color.WHITE);

    //Se pintan el fondo del grafico de gris y las lineas de blanco
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    categoryPlot.setBackgroundPaint(Color.LIGHT_GRAY);
    categoryPlot.setDomainGridlinePaint(Color.WHITE);
    categoryPlot.setRangeGridlinePaint(Color.WHITE);
    categoryPlot.setNoDataMessage(NO_DATA_TO_DISPLAY);

    //Se configura para que solo muestre nmeros enteros
    NumberAxis rangeAxis = (NumberAxis) categoryPlot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    BarRenderer barRenderer = (BarRenderer) categoryPlot.getRenderer();
    barRenderer.setDrawBarOutline(false);

    return chart;
}

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

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

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(0xBBBBDD));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setMaximumBarWidth(0.10);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);

    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

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

/**
 * Creates a sample chart.//from w  ww.j a  va  2 s.c o  m
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(0xBBBBDD));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setMaxBarWidth(0.10);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);

    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:view.ResultsPanel.java

public void showHistogram(List<ElementaryMode> modes) {

    //for the JTable
    DefaultTableModel tableModel = new DefaultTableModel();
    JTable tableResult = new JTable();
    tableResult.setModel(tableModel);/*from  w  w  w  .  j  a va 2s  . c  om*/

    tableModel.addColumn("Reaction");
    tableModel.addColumn("Presence in the modes");

    tableResult.setAutoCreateRowSorter(true);

    Map<Reaction, Double> stats = new HashMap<Reaction, Double>();

    DecimalFormat df = new DecimalFormat("0.00");

    for (ElementaryMode em : modes) {
        for (Reaction r : em.getContent().keySet()) {
            if (em.getContent().containsKey(r)) {
                if (!stats.containsKey(r)) {
                    stats.put(r, 1.0);
                } else {
                    Reaction key = r;
                    Double value = stats.get(r) + 1;
                    stats.remove(key);
                    stats.put(key, value);
                }
            }
        }
    }

    for (Reaction r : stats.keySet()) {
        tableModel
                .addRow(new Object[] { r, String.valueOf(df.format(stats.get(r) * 100 / modes.size())) + "%" });
    }

    JFrame statisticFrame = new JFrame();
    statisticFrame.add(new JScrollPane(tableResult), BorderLayout.CENTER);
    statisticFrame.setVisible(true);
    statisticFrame.setSize(400, 350);
    statisticFrame.setTitle("Representativeness of each reaction");
    statisticFrame.setLocation(500, 600);

    //histogram
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Map<Integer, Integer> data = new TreeMap<Integer, Integer>();
    int maxSize = 0;
    for (ElementaryMode em : modes) {
        int modeLength = em.getContent().size();
        if (modeLength > maxSize) {
            maxSize = modeLength;
        }
        if (data.containsKey(modeLength)) {
            int value = data.get(modeLength) + 1;
            data.put(modeLength, value);
        } else {
            data.put(modeLength, 1);
        }
    }

    for (int i = 1; i < maxSize; i++) {
        if (!data.containsKey(i)) {
            data.put(i, 0);
        }
    }
    for (int key : data.keySet()) {
        dataset.addValue(Integer.valueOf((data.get(key))), "test", Integer.valueOf(key));
    }

    String plotTitle = "Number of reactions per elementary mode";
    String xaxis = "Reaction number";
    String yaxis = "Elementary mode number";
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = false;
    boolean toolTips = false;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createBarChart3D(plotTitle, xaxis, yaxis, dataset, orientation, show,
            toolTips, urls);

    CategoryPlot plot = chart.getCategoryPlot();
    CategoryAxis axis = plot.getDomainAxis();

    plot.getDomainAxis(0).setLabelFont(plot.getDomainAxis().getLabelFont().deriveFont(new Float(11)));

    ChartFrame frame = new ChartFrame("Elementary modes", chart);
    frame.setVisible(true);
    frame.setSize(400, 350);
    frame.setLocation(500, 100);

}

From source file:com.thalesgroup.hudson.plugins.cppcheck.graph.CppcheckGraph.java

/**
 * Creates a Cppcheck trend graph/*from  w w  w  . j ava 2s .c om*/
 *
 * @return the JFreeChart graph object
 */
protected JFreeChart createGraph() {

    final JFreeChart chart = ChartFactory.createLineChart(null, // chart title
            null, // unused
            yLabel, // range axis label
            categoryDataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerBound(0);
    rangeAxis.setAutoRange(true);

    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(2.0f));
    applyColorPalette(renderer);

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0));

    return chart;
}

From source file:jp.ac.tohoku.ecei.sb.metabolome.lims.gui.MainWindowController.java

public JFreeChart getChartForGlobalQC() {
    IntensityMatrixImpl intensityMatrix = dataManager.getIntensityMatrix();
    if (intensityMatrix == null)
        return null;
    List<Sample> globalQCList = intensityMatrix.getGlobalQCSamples();
    log.info("global QC {}", globalQCList.size());
    if (globalQCList.size() == 0)
        return null;
    List<Injection> injections = intensityMatrix.getInjectionsBySample(globalQCList.get(0));

    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    for (Injection one : injections) {
        dataset.add(Arrays.asList(intensityMatrix.getColumn(one)).stream().map((o) -> ((Double) o))
                .collect(Collectors.toList()), "Intensity", one.toString());
    }/*  w  w  w .j av  a 2 s .com*/

    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Global QC " + globalQCList.get(0).toString(),
            "Injection", "Intensity", dataset, true);
    chart.getCategoryPlot().getDomainAxis()
            .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2));
    return chart;
}

From source file:ds.monte.carlo.Application.java

private void createFrequencyGraph(HashMap<Long, Integer> dictionary) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    long checksum = 0;

    for (Long key : dictionary.keySet()) {
        dataset.setValue(dictionary.get(key), "", "" + key);
        checksum += dictionary.get(key);
    }/*from  w w  w  . ja  v a  2 s . c  o  m*/

    JFreeChart chart = ChartFactory.createBarChart("Frequency graph", "", "", dataset, PlotOrientation.VERTICAL,
            false, false, false);
    chart.setBackgroundPaint(Color.WHITE);
    CategoryPlot catPlot = chart.getCategoryPlot();
    catPlot.setRangeGridlinePaint(new Color(92, 184, 92));

    ValueAxis vAxis = catPlot.getRangeAxis();
    CategoryAxis cAxis = catPlot.getDomainAxis();

    cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);

    Font font = new Font("SansSerif", Font.PLAIN, 12);
    Font fontTitle = new Font("SansSerif", Font.PLAIN, 14);
    Font fontc = new Font("SansSerif", Font.PLAIN, 10);
    vAxis.setTickLabelFont(font);
    chart.getTitle().setFont(fontTitle);
    cAxis.setTickLabelFont(fontc);

    BarRenderer renderer = (BarRenderer) catPlot.getRenderer();
    Color bootstrapGreen = new Color(92, 184, 92);
    renderer.setSeriesPaint(0, bootstrapGreen);

    ChartPanel chartPanel = new ChartPanel(chart);
    jPanel5.removeAll();
    jPanel5.add(chartPanel, BorderLayout.CENTER);
    jPanel5.validate();
    //jPanel5.setVisible(true);

    System.out.println("Checksum " + checksum);
    System.out.println("NumberOfReplications " + numberOfReplications);

}