Example usage for org.jfree.chart ChartFactory createBarChart

List of usage examples for org.jfree.chart ChartFactory createBarChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createBarChart.

Prototype

public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a bar chart.

Usage

From source file:com.spotlightppm.BarChart.java

public void createBarChart() {

    dataset.setValue(mouseData.size(), "Number of Presses", "Mouse");
    dataset.setValue(keyData.size(), "Number of Presses", "Key");
    String title = "Number of Mouse and Key Presses between " + start.toString() + " - " + end.toString();
    JFreeChart chart = ChartFactory.createBarChart(title, "Mouse/Key", "Number of Presses", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    try {/*from  w w  w . j ava  2  s  . c  om*/
        ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300);
    } catch (IOException ex) {
        Logger.getLogger(BarChart.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.googlecode.tawus.jfreechart.pages.JPEGChartDemo.java

public JFreeChart getChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(5, "Sales", "2007");
    dataset.setValue(6, "Sales", "2008");

    JFreeChart chart = ChartFactory.createBarChart("BarChart", "Year", "Sales", dataset,
            PlotOrientation.VERTICAL, false, true, true);

    return chart;
}

From source file:com.main.controller.ChartDIG.java

public File generateBarChart() throws Exception {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (String string : arrayList) {
        dataset.addValue(Integer.parseInt(string), string, string);
    }/*from  w w w.ja va  2 s . c  o m*/

    JFreeChart barChart = ChartFactory.createBarChart(chartTitle, xTitle, yTitle, dataset,
            PlotOrientation.VERTICAL, true, true, false);

    //        int width = 640;
    //        /* Width of the image */
    //        int height = 480;
    /* Height of the image */
    File BarChart = new File("chart/" + chartTitle + ".jpeg");
    ChartUtilities.saveChartAsJPEG(BarChart, barChart, width, height);
    return BarChart;
}

From source file:jmbench.plots.MemoryRelativeBarPlot.java

public MemoryRelativeBarPlot(String title) {
    chart = ChartFactory.createBarChart(title, // chart title
            "Operation", // domain axis label
            "Relative Memory", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from w  w w . java2 s  .c  om*/
    chart.addSubtitle(new TextTitle("(Smaller is Better)", new Font("SansSerif", Font.ITALIC, 12)));

    plot();
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Bar Chart Demo", "Category", "Value", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
    GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    barrenderer.setSeriesPaint(0, gradientpaint);
    barrenderer.setSeriesPaint(1, gradientpaint1);
    barrenderer.setSeriesPaint(2, gradientpaint2);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(0.52359877559829882D));
    return jfreechart;
}

From source file:Graphing.barGraph.java

public JPanel getBarGraph() {
    CategoryDataset dataSet = getDataSet();
    JFreeChart chart = ChartFactory.createBarChart(this.name, this.X, this.Y, dataSet, this.p, this.Legend,
            this.toolTip, false);

    return new ChartPanel(chart);
}

From source file:de.tuberlin.dima.flinkhandson.utils.SingleSeriesBarChart.java

public SingleSeriesBarChart(String title, String xLabel, String yLabel, Color barColor,
        Map<String, Double> result) {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (Map.Entry<String, Double> e : result.entrySet()) {
        dataset.addValue(e.getValue(), "", e.getKey());
    }/*w  w  w. j av a2 s.  c  o  m*/

    JFreeChart chart = ChartFactory.createBarChart(title, xLabel, yLabel, dataset, PlotOrientation.VERTICAL,
            false, true, false);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    CategoryAxis xAxis = plot.getDomainAxis();

    xAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.BLACK);
    plot.setBackgroundPaint(Color.WHITE);

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setBarPainter(new StandardBarPainter());

    renderer.setSeriesPaint(0, barColor);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(1024, 768));
    getContentPane().add(chartPanel);

    pack();
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:gui.MainForm.java

private static JFreeChart create_AMS_DATA_Chart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("AMS??", "", "??", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setRangeCrosshairVisible(true);
    categoryplot.setRangeCrosshairPaint(Color.blue);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
    GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    barrenderer.setSeriesPaint(0, gradientpaint);
    barrenderer.setSeriesPaint(1, gradientpaint1);
    barrenderer.setSeriesPaint(2, gradientpaint2);
    barrenderer.setLegendItemToolTipGenerator(new StandardCategorySeriesLabelGenerator("Tooltip: {0}"));
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(0.52359877559829882D));
    return jfreechart;
}

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

private static JFreeChart createChart(String s, CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart(s, "Category", "Value", categorydataset,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setDomainGridlinesVisible(true);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
    GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    barrenderer.setSeriesPaint(0, gradientpaint);
    barrenderer.setSeriesPaint(1, gradientpaint1);
    barrenderer.setSeriesPaint(2, gradientpaint2);
    return jfreechart;
}

From source file:com.bdb.weather.display.summary.RainHourChart.java

public RainHourChart() {
    for (int i = 0; i < 24; i++)
        hourRainDataset.addValue(0.0, CATEGORY_NAME, Integer.toString(i));

    JFreeChart rainChart = ChartFactory.createBarChart(null, "Hour", "", hourRainDataset,
            PlotOrientation.VERTICAL, false, true, false);
    ChartViewer rainChartViewer = new ChartViewer(rainChart);
    rainChartViewer.setMaxHeight(10000);
    rainChartViewer.setMaxWidth(10000);/*w  w w  .  ja v a 2  s . co  m*/
    rainChartViewer.setPrefSize(800, 200);
    plot = (CategoryPlot) rainChart.getPlot();
    plot.setRangeAxis(RainRangeAxis.create());
    this.getChildren().add(rainChartViewer);
}