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:com.babynamesUI.java

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

    String name = nameentered.getText();
    String y = yearentered.getText();
    String sex = null;//from w  w w . j  a va  2s  .  c o  m
    if (male2.isSelected())
        sex = "male";
    else if (female2.isSelected())
        sex = "female";
    int[] Lvalue = new int[100];
    int[] Lyear = new int[100];
    int j = 0;
    try {
        int year = Integer.parseInt(y);
        int i = year;

        while (i <= 2013) {
            String filename = sex + "_cy" + i + "_top.csv";
            InputStream is = babynamesUI.class.getResourceAsStream("/resourse/" + filename);
            BufferedReader br = null;
            String line = "";
            String cvsSplitBy = ",";
            br = new BufferedReader(new InputStreamReader(is));
            line = br.readLine();
            while ((line = br.readLine()) != null) {

                int val;
                // use comma as separator

                String[] names = line.split(cvsSplitBy);
                String s1 = names[1].trim();
                String s2 = names[0].trim();
                //System.out.println("name:-"+s1);
                if (s1.charAt(0) == '"') {
                    val = Integer.parseInt(s1.substring(1, s1.length() - 1));
                } else {
                    val = Integer.parseInt(s1);
                }
                if (s2.charAt(0) == '"') {
                    s2 = s2.substring(1, s2.length() - 1);
                }
                //System.out.println("name:-"+s2);
                if (s2.equalsIgnoreCase(name)) {
                    Lvalue[j] = val;
                    Lyear[j] = i;
                    j++;
                }

            }
            i++;
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "invalid entry");
        e.printStackTrace();
    }
    //graph grp =new graph(this,Lvalue,Lyear,j);
    //grp.setVisible(true);
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    String val = "";
    //textArea1.setText("Year     |     Number of Birth");
    for (int p = 0; p < j; p++) {
        val = Integer.toString(Lyear[p]);
        dataset.addValue(Lvalue[p], val, val);
        // textArea1.setText( textArea1.getText()+" \n"+year[i] +"     |     "+ value[i]);                       
    }
    JFreeChart chart = ChartFactory.createAreaChart("Name Trend", "year", "Number of Birth", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.BLACK);
    ChartFrame frame = new ChartFrame("Chart for Name Trend", chart);
    frame.setVisible(true);
    frame.setSize(1200, 700);
    frame.setLocationRelativeTo(null);
    setVisible(false);
    dispose();
}

From source file:Client.Gui.BarChart.java

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

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Distribution of Trainging", // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // 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);

    // 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);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.magenta, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(3, gp3);
    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    return chart;

}

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

/**
 * Creates a sample chart./* w ww. j a v a  2  s .  c  o m*/
 * 
 * @param dataset  a dataset.
 * 
 * @return A sample chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createBarChart(chartTitle, // title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // dataset
            PlotOrientation.HORIZONTAL, // orientation
            !legendPanelOn, // include legend
            true, // tooltips
            false // URLs
    );

    chart.setBackgroundPaint(new Color(0xFF, 0xFF, 0xCC));

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10.0f);
    plot.setRangeAxis(new DateAxis("Date"));
    CategoryToolTipGenerator toolTipGenerator = new StandardCategoryToolTipGenerator("",
            DateFormat.getDateInstance());
    LineAndShapeRenderer renderer = new LineAndShapeRenderer(false, true);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    plot.setRenderer(renderer);

    // setCategorySummary(dataset); time
    return chart;
}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates a bar chart./* w ww  .  j av  a2s . c  o m*/
 * 
 * @param title
 * @param categoryAxisLabel
 *            (X-Axis label)
 * @param valueAxisLabel
 *            (Y-Axis label)
 * @param dataset
 * @return JfreeChart instance.
 */
public JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(title, categoryAxisLabel, valueAxisLabel, dataset,
            this.orientation, this.drawLegend, false, false);
    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);
    CategoryPlot plot = chart.getCategoryPlot();
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.01);
    domainAxis.setUpperMargin(0.01);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesPaint(2, Color.green);
    renderer.setSeriesPaint(3, Color.darkGray);
    renderer.setSeriesPaint(4, Color.yellow);
    return chart;
}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates an area chart.//w w  w .j a va2s.c o  m
 * 
 * @param title
 * @param categoryAxisLabel
 *            (X-Axis label)
 * @param valueAxisLabel
 *            (Y-Axis label)
 * @param dataset
 * @return JfreeChart instance.
 */
public JFreeChart createAreaChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createAreaChart(title, categoryAxisLabel, valueAxisLabel, dataset,
            this.orientation, this.drawLegend, false, false);
    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);
    CategoryPlot plot = chart.getCategoryPlot();
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0);
    domainAxis.setUpperMargin(0);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    AreaRenderer renderer = (AreaRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesPaint(2, Color.green);
    renderer.setSeriesPaint(3, Color.darkGray);
    renderer.setSeriesPaint(4, Color.yellow);
    return chart;
}

From source file:userinterface.PatientRole.PatientWorkAreaJPanel.java

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

    if (patient.vitalSignHistory.getVitalSignHistory().size() > 0) {

        String legend = null;//from   ww w.  ja  va 2s.  c o  m
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        for (VitalSign vs : patient.vitalSignHistory.getVitalSignHistory()) {

            /*if(vs.getState().equalsIgnoreCase("ABNORMAL"))
            legend=vs.getTimestamp().concat(" (" +vs.getState()+")");
            else*/
            legend = vs.getTimestamp();

            dataset.addValue(vs.getRespiratoryRate(), legend, "Respiratory Rate");
            dataset.addValue(vs.getHeartRate(), legend, "Heart Rate");
            dataset.addValue(vs.getSystolicBloodPressure(), legend, "Blood Pressure");
            dataset.addValue(vs.getWeight(), legend, "Weight");

        }

        JFreeChart chart = ChartFactory.createBarChart3D("Vital Signs", "Vital Signs", "Values", dataset,
                PlotOrientation.VERTICAL, true, true, true);
        CategoryPlot P = chart.getCategoryPlot();
        P.setRangeGridlinePaint(Color.BLACK);

        ChartFrame frame = new ChartFrame("Bar Charts", chart);
        frame.setVisible(true);
        frame.setSize(650, 550);

    } else {
        JOptionPane.showMessageDialog(null, "There's no Vital Sign reported for this patient");
        return;
    }

}

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

private void createGrowthGraph(double[] growthMap) {
    DefaultCategoryDataset growthDataset = new DefaultCategoryDataset();
    double min = 1000000;
    double max = 0;
    int l_100 = growthMap.length;
    int l_40 = (int) Math.round(l_100 * 0.4);
    System.out.print(growthMap.length);
    for (int i = l_40; i < growthMap.length; i++) {
        growthDataset.setValue(growthMap[i], "", "" + i);
        if (growthMap[i] < min) {
            min = growthMap[i];/*  w ww  .ja v a 2s. c  o m*/
        }
        if (growthMap[i] > max) {
            max = growthMap[i];
        }
    }

    JFreeChart growChart = ChartFactory.createLineChart("Simulated annealing", "", "", growthDataset,
            PlotOrientation.VERTICAL, false, false, false);
    growChart.setBackgroundPaint(Color.WHITE);

    CategoryPlot catPlot = growChart.getCategoryPlot();
    catPlot.setRangeGridlinePaint(new Color(92, 184, 92));

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

    cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    vAxis.setRange(min, max);

    cAxis.setTickLabelsVisible(false);

    Font font = new Font("SansSerif", Font.PLAIN, 12);
    Font fontTitle = new Font("SansSerif", Font.PLAIN, 14);
    vAxis.setTickLabelFont(font);
    growChart.getTitle().setFont(fontTitle);

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

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

From source file:org.owasp.jbrofuzz.graph.canvas.ResponseTimeChart.java

public ChartPanel getPlotCanvas() {

    final JFreeChart chart = ChartFactory.createBarChart("JBroFuzz Response Time Bar Chart", // chart title
            "File Name", // domain axis label
            "Response Time (ms)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            true // URLs?
    );/*  w  ww .jav  a2 s  .c o  m*/

    final Plot plot = chart.getPlot();
    plot.setBackgroundImage(ImageCreator.IMG_OWASP_MED.getImage());
    plot.setBackgroundImageAlignment(Align.TOP_RIGHT);

    final CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer();
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

    return new ChartPanel(chart);

}

From source file:fitmon.Chart.java

/**
 * Creates a sample chart./*from   ww w.j a va 2 s. co 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, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

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

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // 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);

    // 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);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates a line chart./*from ww  w. ja v a2s  .c  o  m*/
 * 
 * @param title
 * @param categoryAxisLabel
 *            (X-Axis label)
 * @param valueAxisLabel
 *            (Y-Axis label)
 * @param dataset
 * @param includeZero
 *            True when zero shall be included to the axis range.
 * @return JfreeChart instance.
 */
public JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, boolean includeZero, boolean drawShapes) {
    JFreeChart chart = ChartFactory.createLineChart(title, categoryAxisLabel, valueAxisLabel, dataset,
            this.orientation, this.drawLegend, false, false);
    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);
    CategoryPlot plot = chart.getCategoryPlot();
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.025);
    domainAxis.setUpperMargin(0.025);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(includeZero);
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesPaint(2, Color.green);
    renderer.setSeriesPaint(3, Color.darkGray);
    renderer.setSeriesPaint(4, Color.yellow);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseShapesVisible(drawShapes);
    renderer.setBaseShapesFilled(true);
    return chart;
}