Example usage for org.jfree.chart ChartFactory createBarChart3D

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

Introduction

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

Prototype

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

Source Link

Document

Creates a bar chart with a 3D effect.

Usage

From source file:org.cyberoam.iview.charts.CustomCategoryAxis.java

/**
 * This method generates JFreeChart instance for 3D Bar chart with iView customization.
 * @param reportID specifies that for which report Chart is being prepared.
 * @param rsw specifies data set which would be used for the Chart
 * @param requeest used for Hyperlink generation from uri.
 * @return jfreechart instance with iView Customization.
 *//*  w  w  w.j a  va2 s .  c o m*/
public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    JFreeChart chart = null;
    boolean isPDF = false;
    try {
        if (request == null) {
            isPDF = true;
        }
        /*
         * Create data set based on rsw object.
         */
        ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
        ReportColumnBean reportColumnBeanX, reportColumnBeanY = null;

        GraphBean graphBean = null;
        DataLinkBean dataLinkBean = null;
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean
        reportColumnBeanX = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        if (reportColumnBeanX.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBeanX.getDataLinkId());
        }

        reportColumnBeanY = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        rsw.beforeFirst();
        int i = 0;
        DecimalFormat placeHolder = new DecimalFormat("00");
        String xData = null;
        String graphurl = "";
        HashMap<Integer, String> urlmap = new HashMap<Integer, String>();
        while (rsw.next()) {
            xData = rsw.getString(reportColumnBeanX.getDbColumnName());
            if (dataLinkBean != null && request != null) {
                //datalink id is non -1 in tblcolumnreport table means another report is avaialble so set url 
                // here multiple url possible bec multiple record so take hashmap and store url. 
                // we have dataset but dataset is occupied.
                graphurl = dataLinkBean.generateURLForChart(rsw, request);
                urlmap.put(new Integer(i), graphurl);
            }
            //dataset second arugument use for bar line of graph and third argument give name of graph
            dataset.addValue(new Long(rsw.getLong(reportColumnBeanY.getDbColumnName())), "",
                    placeHolder.format(i) + xData);
            i++;
        }
        // we define object of CustomURLGeneratorForBarChart and if datalinkid is not -1 then it object define for link
        CustomURLGeneratorForBarChart customURLGeneratorForBarChart = null;
        if (dataLinkBean != null && request != null) {
            customURLGeneratorForBarChart = new CustomURLGeneratorForBarChart(
                    dataLinkBean.generateURLForChart(request), reportColumnBeanX.getDbColumnName());
            customURLGeneratorForBarChart.setUrlMap(urlmap);
        }
        /*
         * Create the jfree chart object.
         */
        String title = isPDF ? reportBean.getTitle() : "";
        chart = ChartFactory.createBarChart3D(title, // chart title
                "", // domain axis label
                "", dataset, // data            
                PlotOrientation.HORIZONTAL, // orientation
                false, // include legend
                true, // tooltips?
                false // URLs?
        );

        /*
         *Setting additional customization to the chart. 
         */
        //Set background color
        chart.setBackgroundPaint(Color.white);
        //Get a reference to the plot for further customisation
        CategoryPlot plot = chart.getCategoryPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setDomainGridlinePaint(Color.white);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.DARK_GRAY);
        plot.setForegroundAlpha(0.8f);
        plot.setDomainGridlineStroke(new BasicStroke(2));
        plot.setOutlineVisible(false);
        plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

        //Set the range axis to display integers only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        if (reportColumnBeanY.getColumnFormat() == TabularReportConstants.BYTE_FORMATTING) {
            rangeAxis.setTickUnit(new ByteTickUnit(rangeAxis.getUpperBound() / 4));
        }
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
        rangeAxis.setTickLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        rangeAxis.setTickLabelsVisible(true);
        rangeAxis.setTickMarksVisible(true);
        rangeAxis.setAxisLineVisible(false);
        rangeAxis.setLabel(reportColumnBeanY.getColumnName());
        rangeAxis.setLabelFont(new Font("Arial", Font.CENTER_BASELINE, 12));
        rangeAxis.setLabelPaint(new Color(35, 139, 199));

        CustomCategoryAxis catAxis = new CustomCategoryAxis();
        catAxis.setTickLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        catAxis.setTickMarksVisible(false);
        catAxis.setAxisLineVisible(false);
        catAxis.setLabel(reportColumnBeanX.getColumnName());
        catAxis.setLabelFont(new Font("Arial", Font.CENTER_BASELINE, 12));
        catAxis.setLabelPaint(new Color(35, 139, 199));
        catAxis.setLabelFormat(reportColumnBeanX.getColumnFormat());

        plot.setDomainAxis(catAxis);

        //Set custom color for the chart.         
        CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { new Color(254, 211, 41),
                new Color(243, 149, 80), new Color(199, 85, 82), new Color(181, 105, 152),
                new Color(69, 153, 204), new Color(155, 212, 242), new Color(52, 172, 100),
                new Color(164, 212, 92), new Color(177, 155, 138), new Color(149, 166, 141) });

        plot.setRenderer(renderer);

        BarRenderer renderer2 = (BarRenderer) plot.getRenderer();
        renderer2.setDrawBarOutline(false);
        renderer2.setBaseItemLabelsVisible(true);
        renderer2.setMaximumBarWidth(0.04);

        if (dataLinkBean != null && request != null) {
            renderer.setBaseItemURLGenerator(customURLGeneratorForBarChart);
            //renderer.setBaseItemURLGenerator(new CustomURLGeneratorForBarChart(dataLinkBean.generateURLForChart(request),reportColumnBeanX.getDbColumnName()));
        }
        renderer.setBaseToolTipGenerator(new CustomToolTipGenerator());
        renderer.setBaseToolTipGenerator(new CustomToolTipGenerator());
        renderer.setBaseToolTipGenerator(
                new CustomToolTipGenerator("{2} " + reportColumnBeanY.getColumnName()));
    } catch (Exception e) {
        CyberoamLogger.appLog.debug("Bar3D.e:" + e, e);
    }
    return chart;
}

From source file:org.eevolution.form.VSCRP.java

private JFreeChart createChart(CategoryDataset dataset, String title, MUOM uom) {
    JFreeChart chart = ChartFactory.createBarChart3D(title, " ", " ", dataset, PlotOrientation.VERTICAL, true,
            true, false);//from ww w .  ja v a 2s .  c o m

    //Hinzugefgt Begin 05.08.2005
    if (uom == null || uom.isHour()) {
        chart = ChartFactory.createBarChart3D(title, Msg.translate(Env.getCtx(), "Days"), // X-Axis label
                Msg.translate(Env.getCtx(), "Hours"), // Y-Axis label
                dataset, // Dataset
                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);

    }
    //Gendert 05.08.2005 Anfang
    else {
        chart = ChartFactory.createBarChart3D(title, Msg.translate(Env.getCtx(), "Days"), // X-Axis label
                Msg.translate(Env.getCtx(), "Kilo"), // Y-Axis label
                dataset, // Dataset
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips?
                false // URLs?
        );

        //chart.setBackgroundPaint(Color.white);    

    }

    //Gendert 05.08.2005 Ende

    /* 
      // get a reference to the plot for further customisation...
      CategoryPlot plot = chart.getCategoryPlot();
      plot.setBackgroundPaint(Color.lightGray);
      plot.setDomainGridlinePaint(Color.white);
      plot.setDomainGridlinesVisible(true);
      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...
      BarRenderer renderer = (BarRenderer) plot.getRenderer();
      renderer.setDrawBarOutline(false);
              
      // set up gradient paints for series...
      GradientPaint gp0 = new GradientPaint(
    0.0f, 0.0f, Color.blue, 
    0.0f, 0.0f, new Color(0, 0, 64)
      );
      GradientPaint gp1 = new GradientPaint(
    0.0f, 0.0f, Color.green, 
    0.0f, 0.0f, new Color(0, 64, 0)
      );
      GradientPaint gp2 = new GradientPaint(
    0.0f, 0.0f, Color.red, 
    0.0f, 0.0f, new Color(64, 0, 0)
      );
      renderer.setSeriesPaint(0, gp0);
      renderer.setSeriesPaint(1, gp1);
      renderer.setSeriesPaint(2, gp2);
            
      CategoryAxis domainAxis = plot.getDomainAxis();
      domainAxis.setCategoryLabelPositions(
    CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
      );*/
    // OPTIONAL CUSTOMISATION COMPLETED.      

    return chart;

}

From source file:fuel.gui.stats.MotorStatsPanel.java

private void refreshGraphs(Motorcycle motor) {
    graphContainer.removeAll();//from   w w  w  .j  a  v  a2s .co m
    if (motor != null) {
        DefaultPieDataset usageDataset = new DefaultPieDataset();
        try {
            ResultSet thisMotor = database
                    .Query("SELECT SUM(distance) FROM fuelrecords WHERE motorcycleId = " + motor.getId(), true);
            ResultSet otherMotors = database.Query(
                    "SELECT SUM(distance) FROM fuelrecords WHERE NOT motorcycleId = " + motor.getId(), true);
            thisMotor.next();
            otherMotors.next();

            usageDataset.setValue(motor.toString(), thisMotor.getInt("1"));
            usageDataset.setValue("Andere motoren", otherMotors.getInt("1"));

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
        }
        JFreeChart usagePiechart = ChartFactory.createPieChart3D("", usageDataset, true, true, false);
        PiePlot3D plot3 = (PiePlot3D) usagePiechart.getPlot();
        plot3.setForegroundAlpha(0.6f);
        //plot3.setCircular(true);

        JPanel usagePiechartPanel = new ChartPanel(usagePiechart);
        usagePiechartPanel
                .setBorder(BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Motorgebruik")));
        usagePiechartPanel.setPreferredSize(new java.awt.Dimension(240, 240));
        usagePiechartPanel.setLayout(new BorderLayout());

        DefaultPieDataset stationDataset = new DefaultPieDataset();
        try {
            for (Station station : database.getStations()) {
                ResultSet numberStations = database.Query(
                        "SELECT DISTINCT stationId FROM fuelrecords WHERE stationId = " + station.getId(),
                        true);
                if (numberStations.next()) {
                    ResultSet otherMotors = database.Query("SELECT COUNT(*) FROM fuelrecords WHERE stationId = "
                            + station.getId() + " AND motorcycleId = " + motor.getId(), true);
                    otherMotors.next();
                    if (otherMotors.getInt("1") > 0) {
                        stationDataset.setValue(station.toString(), otherMotors.getInt("1"));
                    }
                }
            }

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
        }
        JFreeChart stationPiechart = ChartFactory.createPieChart3D("", stationDataset, true, true, false);
        PiePlot3D plot2 = (PiePlot3D) stationPiechart.getPlot();
        plot2.setForegroundAlpha(0.6f);
        //plot3.setCircular(true);

        JPanel stationPiechartPanel = new ChartPanel(stationPiechart);
        stationPiechartPanel.setBorder(
                BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Tankstation verhouding")));
        stationPiechartPanel.setPreferredSize(new java.awt.Dimension(240, 240));
        stationPiechartPanel.setLayout(new BorderLayout());

        DefaultPieDataset fuelDataset = new DefaultPieDataset();
        try {
            ResultSet numberResults = database.Query("SELECT DISTINCT typeOfGas FROM fuelrecords", true);
            while (numberResults.next()) {
                ResultSet thisStation = database.Query(
                        "SELECT SUM(liter) FROM fuelrecords WHERE typeOfGas = '"
                                + numberResults.getString("typeOfGas") + "'AND motorcycleId = " + motor.getId(),
                        true);
                thisStation.next();
                if (thisStation.getDouble("1") > 0) {
                    fuelDataset.setValue(numberResults.getString("TYPEOFGAS"), thisStation.getDouble("1"));
                }
            }

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
        }
        JFreeChart fuelPieChart = ChartFactory.createPieChart3D("", fuelDataset, true, true, false);
        PiePlot3D plot1 = (PiePlot3D) fuelPieChart.getPlot();
        plot1.setForegroundAlpha(0.6f);
        //plot3.setCircular(true);

        JPanel fuelPieChartPanel = new ChartPanel(fuelPieChart);
        fuelPieChartPanel.setBorder(
                BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Brandstof verhouding")));
        fuelPieChartPanel.setPreferredSize(new java.awt.Dimension(240, 240));

        DefaultCategoryDataset barDataset = new DefaultCategoryDataset();
        try {
            ResultSet motorThing = database
                    .Query("SELECT distance/liter,date FROM fuelrecords WHERE motorcycleId = " + motor.getId()
                            + " ORDER BY date ASC", true);
            while (motorThing.next()) {
                barDataset.addValue(motorThing.getDouble("1"), motorThing.getString("DATE"), "Verbruik");
            }

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
        }

        JFreeChart barChart = ChartFactory.createBarChart3D("", // chart title
                "", // domain axis label
                "Aantal", // range axis label
                barDataset, // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips?
                false // URLs?
        );
        CategoryPlot plot = barChart.getCategoryPlot();
        BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
        renderer.setDrawBarOutline(false);

        ChartPanel barChartPanel = new ChartPanel(barChart);
        barChartPanel.getChartRenderingInfo().setEntityCollection(null);
        barChartPanel.setBorder(BorderFactory.createTitledBorder("Verbruik"));
        barChartPanel.setPreferredSize(new java.awt.Dimension(320, 240));
        barChartPanel.setLayout(new BorderLayout());

        JPanel piePanel = new JPanel(new GridLayout(0, 3));
        piePanel.add(usagePiechartPanel);
        piePanel.add(stationPiechartPanel);
        piePanel.add(fuelPieChartPanel);

        //uitgaven
        DefaultPieDataset expensesDataset = new DefaultPieDataset();
        try {
            Map<String, ResultSet> allCosts = new HashMap<String, ResultSet>();
            ResultSet fuelCosts = database
                    .Query("SELECT SUM(cost) FROM fuelrecords WHERE motorcycleId = " + motor.getId(), true);
            allCosts.put("Brandstof", fuelCosts);
            ResultSet expenses = database.Query("SELECT DISTINCT categoryid FROM expenses", true);
            while (expenses.next()) {
                ResultSet set = database.Query("SELECT SUM(costs) FROM expenses WHERE categoryid = "
                        + expenses.getInt("categoryid") + " AND motorcycleid = " + motor.getId(), true);
                ResultSet set2 = database
                        .Query("SELECT name FROM categories WHERE id = " + expenses.getInt("categoryid"), true);
                set2.next();
                allCosts.put(set2.getString("name"), set);
            }

            for (Map.Entry<String, ResultSet> element : allCosts.entrySet()) {
                element.getValue().next();
                if (element.getValue().getInt("1") > 0) {
                    expensesDataset.setValue(element.getKey(), element.getValue().getInt("1"));
                }
            }

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
        }
        JFreeChart expensesPiechart = ChartFactory.createPieChart3D("", expensesDataset, true, true, false);
        PiePlot3D plot4 = (PiePlot3D) expensesPiechart.getPlot();
        plot4.setForegroundAlpha(0.6f);

        JPanel expensesPiePanel = new ChartPanel(expensesPiechart);
        expensesPiePanel
                .setBorder(BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Uitgaven")));
        expensesPiePanel.setPreferredSize(new java.awt.Dimension(240, 240));
        expensesPiePanel.setLayout(new BorderLayout());

        graphContainer.add(piePanel);
        graphContainer.add(barChartPanel);
        graphContainer.add(expensesPiePanel);
    }
    revalidate();
    repaint();
}

From source file:org.eevolution.form.VCRP.java

private JFreeChart createChart(CategoryDataset dataset, String title, MUOM uom) {
    JFreeChart chart = ChartFactory.createBarChart3D(title, " ", " ", dataset, PlotOrientation.VERTICAL, true,
            true, false);/*  w w w. ja  v a 2s  .  c  o  m*/

    //Hinzugefgt Begin 05.08.2005
    if (uom == null || uom.isHour()) {
        chart = ChartFactory.createBarChart3D(title, Msg.translate(Env.getCtx(), "Days"), // X-Axis label
                Msg.translate(Env.getCtx(), "Hours"), // Y-Axis label
                dataset, // Dataset
                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);

    }
    //Gendert 05.08.2005 Anfang
    else {
        chart = ChartFactory.createBarChart3D(title, Msg.translate(Env.getCtx(), "Days"), // X-Axis label
                Msg.translate(Env.getCtx(), "Kilo"), // Y-Axis label
                dataset, // Dataset
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips?
                false // URLs?
        );

        //chart.setBackgroundPaint(Color.white);

    }

    //Gendert 05.08.2005 Ende

    /*
      // get a reference to the plot for further customisation...
      CategoryPlot plot = chart.getCategoryPlot();
      plot.setBackgroundPaint(Color.lightGray);
      plot.setDomainGridlinePaint(Color.white);
      plot.setDomainGridlinesVisible(true);
      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...
      BarRenderer renderer = (BarRenderer) plot.getRenderer();
      renderer.setDrawBarOutline(false);
            
      // set up gradient paints for series...
      GradientPaint gp0 = new GradientPaint(
    0.0f, 0.0f, Color.blue,
    0.0f, 0.0f, new Color(0, 0, 64)
      );
      GradientPaint gp1 = new GradientPaint(
    0.0f, 0.0f, Color.green,
    0.0f, 0.0f, new Color(0, 64, 0)
      );
      GradientPaint gp2 = new GradientPaint(
    0.0f, 0.0f, Color.red,
    0.0f, 0.0f, new Color(64, 0, 0)
      );
      renderer.setSeriesPaint(0, gp0);
      renderer.setSeriesPaint(1, gp1);
      renderer.setSeriesPaint(2, gp2);
            
      CategoryAxis domainAxis = plot.getDomainAxis();
      domainAxis.setCategoryLabelPositions(
    CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
      );*/
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:org.karndo.graphs.CustomChartFactory.java

/**
 * Creates a chart of the selected PiracyEvent data graphed by month from
 * the available months in the data. Presently uses a very basic method of 
 * graphing this data by      * using the static CreateBarChart3D method 
 * available in class org.jfree.chart.ChartFactory.
 * // w ww  .j  a  v a 2s .  c  o m
 * @param data the selected PiracyEvent data to graph.
 * @return A JFreeChart object representing a graph of the selected 
 * PiracyEvent data against months from the available data.
 */
public JFreeChart createHistogramMonthlyAvailableData(LinkedList<PiracyEvent> data) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    Integer[] freqs = new Integer[MONTHS.length];
    Calendar cal = Calendar.getInstance();

    //set up the frequencies array
    for (int i = 0; i < freqs.length; i++) {
        freqs[i] = 0;
    }

    for (PiracyEvent ev : data) {
        cal.setTime(ev.getDate());
        freqs[cal.get(Calendar.MONTH)]++;
    }

    //add the frequencies to a dataset for plotting
    for (int i = 0; i < freqs.length; i++) {
        if (freqs[i] != 0) {
            dataset.addValue(freqs[i], "Piracy Incidents", MONTHS[i]);
        }
    }

    JFreeChart chart = ChartFactory.createBarChart3D("Piracy Incidents " + "by month", "Month", "Frequency",
            dataset, PlotOrientation.VERTICAL, false, true, false);
    return chart;
}

From source file:com.netflix.ice.basic.BasicWeeklyCostEmailService.java

private File createImage(ApplicationGroup appgroup) throws IOException {

    Map<String, Double> costs = Maps.newHashMap();
    DateTime end = new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0);
    Interval interval = new Interval(end.minusWeeks(numWeeks), end);

    for (Product product : products) {
        List<ResourceGroup> resourceGroups = getResourceGroups(appgroup, product);
        if (resourceGroups.size() == 0) {
            continue;
        }//from   w  ww .  j av a2s  .  c  o  m
        DataManager dataManager = config.managers.getCostManager(product, ConsolidateType.weekly);
        if (dataManager == null) {
            continue;
        }
        TagLists tagLists = new TagLists(accounts, regions, null, Lists.newArrayList(product), null, null,
                resourceGroups);
        Map<Tag, double[]> data = dataManager.getData(interval, tagLists, TagType.Product, AggregateType.none,
                false);
        for (Tag tag : data.keySet()) {
            for (int week = 0; week < numWeeks; week++) {
                String key = tag + "|" + week;
                if (costs.containsKey(key))
                    costs.put(key, data.get(tag)[week] + costs.get(key));
                else
                    costs.put(key, data.get(tag)[week]);
            }
        }
    }

    boolean hasData = false;
    for (Map.Entry<String, Double> entry : costs.entrySet()) {
        if (!entry.getKey().contains("monitor") && entry.getValue() != null && entry.getValue() >= 0.1) {
            hasData = true;
            break;
        }
    }
    if (!hasData)
        return null;

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Product product : products) {
        for (int week = 0; week < numWeeks; week++) {
            String weekStr = String.format("%s - %s week",
                    formatter.print(end.minusWeeks(numWeeks - week)).substring(5),
                    formatter.print(end.minusWeeks(numWeeks - week - 1)).substring(5));
            dataset.addValue(costs.get(product + "|" + week), product.name, weekStr);
        }
    }

    JFreeChart chart = ChartFactory.createBarChart3D(appgroup.getDisplayName() + " Weekly AWS Costs", "",
            "Costs", dataset, PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    BarRenderer3D renderer = (BarRenderer3D) categoryplot.getRenderer();
    renderer.setItemLabelAnchorOffset(10.0);
    TextTitle title = chart.getTitle();
    title.setFont(title.getFont().deriveFont((title.getFont().getSize() - 3)));

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() {
        public java.lang.String generateLabel(org.jfree.data.category.CategoryDataset dataset, int row,
                int column) {
            return costFormatter.format(dataset.getValue(row, column));
        }
    });
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setNumberFormatOverride(costFormatter);

    BufferedImage image = chart.createBufferedImage(1200, 400);
    File outputfile = File.createTempFile("awscost", "png");
    ImageIO.write(image, "png", outputfile);

    return outputfile;
}

From source file:Gui.admin.GererlesSratistique.java

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

    int size = evaluationTable.getRowCount();
    System.out.println(size);//  w ww .  jav a2s . co m
    List<Double> notes = new ArrayList<Double>();
    List<Integer> ids = new ArrayList<Integer>();

    for (int i = 0; i < size; i++) {

        notes.add((new Double(evaluationTable.getValueAt(i, 3).toString())));

        ids.add((int) evaluationTable.getValueAt(i, 1));

    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < size; i++) {

        dataset.setValue(new Double(notes.get(i)), "notes", new Double(ids.get(i)));

    }

    //dataset.setValue(evaluationTable);

    JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Id Adhrents", "Notes", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);
    ChartFrame frame = new ChartFrame(" les notes des adhrents", chart);
    frame.setVisible(true);
    frame.setSize(450, 350);

    try {

    }

    catch (Exception e) {
    }

    /*
    String note =noteTxt.getText();
    String idAdherent=idAdherentEvaluText.getText();
            
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(new Double(note), "notes", new Double(idAdherent));
    //dataset.setValue(evaluationTable);
            
    JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Id Adhrents", "Notes", dataset, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot p= chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);
    ChartFrame frame = new ChartFrame(" les notes des adhrents", chart);
    frame.setVisible(true);
    frame.setSize(450,350);
    */
    try {

        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("statistiques.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

    }

    catch (Exception e) {
    }

}

From source file:GUI.Control.java

public void boton2ActionPerformed(java.awt.event.ActionEvent evt) {
    ArrayList<String> Paises = new ArrayList();
    ArrayList<String> PaisesDB = new ArrayList();
    JOptionPane.showMessageDialog(null, "Grfica No. 2 - Pases con ms Clientes");
    ArrayList dataPais = dbman.executeQuery(
            "select con.name from client c join country con on (c.country_id = con.id) join tipo t on (t.id = c.tipo_id);");
    ArrayList PaisTabla = dbman.executeQuery("select name from country order by id;");
    ArrayList dataUser = dbman.executeQuery(
            "select t.name from client c join country con on (c.country_id = con.id) join tipo t on (t.id = c.tipo_id);");
    for (int i = 0; i < dataPais.size(); i++) {
        ArrayList temp = (ArrayList) dataPais.get(i);
        Paises.add((String) temp.get(0));
    }//from   ww w. j  a va 2s . c  om

    for (int i = 0; i < PaisTabla.size(); i++) {
        ArrayList temp = (ArrayList) PaisTabla.get(i);
        PaisesDB.add((String) temp.get(0));
    }

    ArrayList<String> y = new ArrayList();
    int cont = 0;
    for (int i = 0; i < PaisesDB.size(); i++) {
        for (int j = 0; j < Paises.size(); j++) {
            if (Paises.get(j).equals(PaisesDB.get(i))) {
                cont = cont + 1;
            }
        }
        y.add(String.valueOf(cont));
        cont = 0;
    }
    for (int i = 0; i < y.size(); i++) {
        if (y.size() == PaisesDB.size()) {
            Datos2.addValue(Integer.parseInt(y.get(i)), "Cantidad de Clientes", PaisesDB.get(i));
        }
    }
    Grafica2 = ChartFactory.createBarChart3D("Pases con ms clientes", "Paises", "Clientes", Datos2,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel Panel = new ChartPanel(Grafica2);
    JFrame Ventana = new JFrame("Grfica 2");
    Ventana.getContentPane().add(Panel);
    Ventana.pack();
    Ventana.setVisible(true);
}

From source file:graph.plotter.BarMenu.java

/**
 * This is the main working button for this class... It creates bar chart analyZing whole data set
 * /* w  ww .ja v a  2  s .com*/
 * @param evt 
 */
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    try {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        int i;
        i = 0;
        String genre = " ";
        if (Button == 1)
            while (i < count) {
                double amount = Double.parseDouble(Table.getModel().getValueAt(i, 1).toString());
                String name = Table.getModel().getValueAt(i, 0).toString();
                dataset.setValue(new Double(amount), genre, name);
                i++;
                genre += " ";

            }
        else {
            try {
                BufferedReader br = new BufferedReader(new FileReader(jTextField3.getText()));
                String Line;
                while ((Line = br.readLine()) != null) {
                    String[] value = Line.split(",");
                    double val = Double.parseDouble(value[1]);

                    dataset.setValue(new Double(val), genre, value[0]);
                    genre += " ";
                    System.out.println(value[0]);
                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(BarMenu.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(BarMenu.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

        JFreeChart chart = ChartFactory.createBarChart3D("Amount", "Name", "Amount", dataset,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.white);
        p.setBackgroundPaint(Color.black);
        ChartFrame frame = new ChartFrame("Bar Chart", chart);
        saveButton = new JButton("Save image in Project Folder");

        frame.setLayout(new BorderLayout());

        JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());

        GridBagConstraints gc = new GridBagConstraints();
        gc.gridx = 1;
        gc.gridy = 0;

        panel.add(saveButton, gc);

        frame.add(panel, BorderLayout.SOUTH);

        saveButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                try {
                    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
                    final File file1 = new File("Bar_Chart.png");
                    ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
                } catch (Exception ex) {

                }

            }
        });
        frame.setVisible(true);

        frame.setSize(858, 513);
    } catch (Exception e) {

    }
}

From source file:UserInterface.DoctorRole.ViewPatientReport.java

public void Graph() {
    dataset = new DefaultCategoryDataset();
    if (!(patient.getTestDir().getTestdir().isEmpty())) {

        for (Test vs : patient.getTestDir().getTestdir()) {

            dataset.addValue(Float.parseFloat(vs.getBloodPressure()), "Blood Pressure", vs.getTimestamp());
            dataset.addValue(Float.parseFloat(vs.getBloodPlatlets()), "Blood Platelets", vs.getTimestamp());
            dataset.addValue(Float.parseFloat(vs.getHemoglobinLevel()), "Hemoglobin Level", vs.getTimestamp());
            //dataset.addValue(vs.getWeight(), "Weight", vs.getTimestamp());

        }//  w w w .  j  a  v a  2s. co m

        JFreeChart chartFactory = ChartFactory.createBarChart3D("VitalSign", "Time", "VitalSign", dataset,
                PlotOrientation.VERTICAL, true, true, false);

        BarRenderer renderer = null;
        CategoryPlot plot = chartFactory.getCategoryPlot();
        renderer = new BarRenderer();
        ChartFrame frame = new ChartFrame("Bar Chart for VitalSign", chartFactory);
        frame.setVisible(true);
        frame.setSize(700, 320);
    } else {
        JOptionPane.showMessageDialog(this, "No Vital Signs To Display On Graph!!!");
    }
}