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:Interface.ApplicationAdmin.Analytics.java

private void caruserdatajButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_caruserdatajButtonActionPerformed

    int x = Integer.parseInt(MaxcarownerridejLabel.getText());
    int y = Integer.parseInt(MincarownerridejLabel.getText());
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(x, "Max Car ride", "Rides");
    dataset.setValue(y, "Min Car ride", "Rides");

    JFreeChart chart = ChartFactory.createBarChart("User Min - Max ride chart", "Car ride", "Number of rides",
            dataset, PlotOrientation.VERTICAL, false, false, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);
    ChartFrame frame = new ChartFrame("User Ride chart ", chart);
    frame.setVisible(true);/*from  w w w. jav  a2s .c o m*/
    frame.setSize(450, 350);
    frame.setLocation(400, 150);

}

From source file:GUI.pantalla1.java

private void CalcIntActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CalcIntActionPerformed
    // TODO add your handling code here:
    cuadro = new DefaultCategoryDataset();
    try {//from w ww.j  a v  a  2s .  co  m
        graf.ListaDeMetodos(list);
        graf.metodosOrdA(cuadro, rand.generadorArrInt(getCantidadDat()));
        graf.metodosOrdL(cuadro, rand.generadorListInt(getCantidadDat()));
    } catch (IOException ex) {
        Logger.getLogger(pantalla1.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println("error en ordenamiento con listas y arreglos de ints");
    }
    JFreeChart grafica = ChartFactory.createBarChart("Metodos de ordenamiento con Ints", "promedio",
            "Tiempo de duracion", cuadro, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot grfic = grafica.getCategoryPlot();
    ChartPanel barras = new ChartPanel(grafica);
    PanelGrafico.removeAll();
    PanelGrafico.add(barras, BorderLayout.CENTER);
    PanelGrafico.validate();

}

From source file:tdunnick.jphineas.console.queue.Charts.java

/**
 * Creates the bar chart.  Set the X-axis font small enough to accommodate
 * dates and tidy up the bars.//w ww  .java2 s. c  o m
 * @param title for the chart
 * @param dataset for the chart
 * @return the chart
 */
private JFreeChart createBarChart(String title, CategoryDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(title, null, // domain axis label
            "Messages", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );
    CategoryPlot plot = chart.getCategoryPlot();
    plot.getDomainAxis().setTickLabelFont(new Font("Arial", Font.BOLD, 9));
    BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
    renderer.setItemMargin(0.01);
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);
    return chart;
}

From source file:GUI.pantalla1.java

private void CalcStrinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CalcStrinActionPerformed
    // TODO add your handling code here:
    cuadro = new DefaultCategoryDataset();
    try {// ww  w  .  j av  a  2 s  . c o m
        graf.ListaDeMetodos(list);
        graf.metodosOrdA(cuadro, rand.generadorArrString(getCantidadDat()));
        graf.metodosOrdL(cuadro, rand.generadorListString(getCantidadDat()));
    } catch (IOException ex) {
        Logger.getLogger(pantalla1.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println("error en ordenamiento con listas y arreglos de Strings");
    }
    JFreeChart grafica = ChartFactory.createBarChart("Metodos de ordenamiento con Strings", "promedio",
            "Tiempo de duracion", cuadro, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot grfic = grafica.getCategoryPlot();
    ChartPanel barras = new ChartPanel(grafica);
    PanelGrafico.removeAll();
    PanelGrafico.add(barras, BorderLayout.CENTER);
    PanelGrafico.validate();
}

From source file:com.swordlord.gozer.components.fop.graph.GFopStackedBarChart.java

public GFopStackedBarChart(IGozerFrameExtension gfe, GStackedBarChart chart) {
    super(gfe);/*from w  w  w. java2 s. c o  m*/

    DataBindingMember dbMemberRowKey = chart.getDataBindingMemberRowKey();
    DataBindingMember dbMemberColKey = chart.getDataBindingMemberColKey();
    DataBindingMember dbMemberValue = chart.getDataBindingMemberValue();
    DataBindingManager dbManager = chart.getDataBindingManager();

    DefaultCategoryDataset dcd = new DefaultCategoryDataset();

    List<DataRowBase> rowTests = dbManager.getRows(dbMemberValue);
    for (int j = 0; j < rowTests.size(); j++) {
        DataRowBase row = rowTests.get(j);

        String strKey = row.getPropertyAsStringForce(dbMemberRowKey.getRelativePathWithField());

        dcd.setValue(row.getPropertyAsInt(dbMemberValue.getRelativePathWithField()), strKey,
                row.getPropertyAsStringForce(dbMemberColKey.getRelativePathWithField()));
    }

    JFreeChart fc = ChartFactory.createStackedBarChart(chart.getTitle(), chart.getCategoryAxisLabel(),
            chart.getValueAxisLabel(), dcd, chart.getOrientation(), chart.getLegend(), false, false);

    // Do this in a more static way!
    StackedBarRenderer.setDefaultBarPainter(new StandardBarPainter());

    //chart.setBackgroundPaint(Color.white);
    if (chart.getSubTitle() != null) {
        fc.addSubtitle(new TextTitle(chart.getSubTitle()));
    }

    CategoryPlot plot = fc.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDrawingSupplier(chart.getDrawingSupplier());

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(chart.getCategoryAxisVisible());

    ValueAxis valueAxis = plot.getRangeAxis();
    valueAxis.setVisible(chart.getValueAxisVisible());

    /*
    //CategoryItemRenderer renderer = (CategoryItemRenderer) plot.getRenderer();
    for (int j = 0; j < rowKey.length; j++)
    {
       renderer.setSeriesItemLabelGenerator(j, new LabelGenerator(j, rowKey[j]));
       renderer.setSeriesItemLabelsVisible(j, true);
    }
    */
    StackedBarRenderer renderer = new StackedBarRenderer();

    for (int j = 0; j < dcd.getRowCount(); j++) {
        renderer.setSeriesItemLabelGenerator(j, new StandardCategoryItemLabelGenerator());
        renderer.setSeriesItemLabelsVisible(j, true);
    }

    //renderer.setLegendItemLabelGenerator(new LabelGenerator());
    renderer.setShadowVisible(false);

    plot.setRenderer(renderer);

    _image = new ChartImage("chart", fc, chart.getWidth(800), chart.getHeight(800));
}

From source file:edu.ucla.stat.SOCR.chart.SuperBoxAndWhiskerChart.java

protected JFreeChart createLegendChart(JFreeChart origchart) {

    JFreeChart legendChart = new JFreeChart("", null, new HiddenPlot(), false);

    legendChart.setBackgroundPaint(Color.white);
    CategoryPlot plot = origchart.getCategoryPlot();

    LegendTitle legendTitle = new LegendTitle(plot,
            new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 0),
            new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 0));
    legendChart.addLegend(legendTitle);//from   w  w w  .j  a va 2 s  . c o m

    return legendChart;

}

From source file:Interface.ApplicationAdmin.Analytics.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    int x = Integer.parseInt(MaxCaruserride.getText());
    int y = Integer.parseInt(MinCarUserride.getText());
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(x, "Max Car ride", "Rides");
    dataset.setValue(y, "Min Car ride", "Rides");

    JFreeChart chart = ChartFactory.createBarChart("Car owner Min - Max ride chart", "Car ride",
            "Number of rides", dataset, PlotOrientation.VERTICAL, false, false, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);
    ChartFrame frame = new ChartFrame("Ride chart ", chart);
    frame.setVisible(true);// w  w w.  j av  a2 s.  c  o m
    frame.setSize(450, 350);
    frame.setLocation(400, 150);

}

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

/**
 * Creates a chart./*from w w  w.j  a  v  a 2s .  c  om*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {
    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart", // chart title
            "Category", // domain axis label
            "Score (%)", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, false);

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

    chart.setBackgroundPaint(Color.lightGray);

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

    plot.getRenderer().setSeriesPaint(0, new Color(0, 0, 255));
    plot.getRenderer().setSeriesPaint(1, new Color(75, 75, 255));
    plot.getRenderer().setSeriesPaint(2, new Color(150, 150, 255));

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(0.0, 100.0);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // NumberAxis hna = rangeAxis;
    // MarkerAxisBand band = new MarkerAxisBand(hna, 2.0, 2.0, 2.0, 2.0,
    //     new Font("SansSerif", Font.PLAIN, 9));

    //        IntervalMarker m1 = new IntervalMarker(0.0, 33.0, "Low", Color.gray,
    //            new BasicStroke(0.5f), Color.green, 0.75f);
    //        IntervalMarker m2 = new IntervalMarker(33.0, 66.0, "Medium", Color.gray,
    //            new BasicStroke(0.5f), Color.orange, 0.75f);
    //        IntervalMarker m3 = new IntervalMarker(66.0, 100.0, "High", Color.gray,
    //            new BasicStroke(0.5f), Color.red, 0.75f);
    //        band.addMarker(m1);
    //        band.addMarker(m2);
    //        band.addMarker(m3);
    //        hna.setMarkerBand(band);
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}

From source file:com.MainChart.java

public MainChart(String applicationTitle, String chartTitle) throws IOException {
    super(applicationTitle);
    this.multiHashtable = new Hashtable<>();
    // This will create the dataset 
    // PieDataset dataset = createDataset();
    // based on the dataset we create the chart
    final JFreeChart chart = ChartFactory.createBarChart("GPA Analysis By Country", // chart title
            "Country", // domain axis label
            "GPA", // range axis label
            createDataset(), // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*w ww  . j ava  2s .c  o  m*/

    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setBackgroundPaint(SystemColor.inactiveCaption);//change background color

    //set  bar chart color

    //CategoryItemRenderer renderer = new CustomRenderer(); 
    //plot.setRenderer(renderer);
    // we put the chart into a panel
    ChartPanel chartPanel = new ChartPanel(chart);
    // default size
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    // add it to our application
    setContentPane(chartPanel);

}

From source file:com.google.jenkins.flakyTestHandler.plugin.TestFlakyStatsOverRevision.java

private JFreeChart createChart(CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title
            null, // unused
            "count", // range axis label*/master
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );/* w  ww .j  a va2  s .c o m*/

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    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());

    StackedAreaRenderer ar = new StackedAreaRenderer2() {

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            RevisionLabel label = (RevisionLabel) dataset.getColumnKey(column);
            Number value = dataset.getValue(row, column);
            switch (row) {
            case 0:
                return label.revision + ": " + value + " fails";
            case 1:
                return label.revision + ": " + value + " passes";
            default:
                return label.revision;
            }
        }
    };
    plot.setRenderer(ar);
    ar.setSeriesPaint(0, ColorPalette.RED); // Fails.
    ar.setSeriesPaint(1, ColorPalette.BLUE); // Passes.

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

    return chart;
}