Example usage for org.jfree.chart ChartFactory createPieChart

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

Introduction

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

Prototype

public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips,
        boolean urls) 

Source Link

Document

Creates a pie chart with default settings.

Usage

From source file:com.sun.portal.os.portlets.PortletChartUtilities.java

private static JFreeChart createChart(ResourceRequest request) {
    JFreeChart chart = null;/*  w ww  . ja  v  a  2  s .  c  o  m*/
    try {
        PortletPreferences prefs = request.getPreferences();

        if (prefs == null)
            throw new NoPreferredDbSetException("Preferences not passed in from portlet");

        String type = prefs.getValue(Constants.PREF_CHART_TYPE, PIE_CHART);

        debugMessage("Chart type :" + type);

        if (type.equals(PIE_CHART)) {
            String sql = prefs.getValue(Constants.PREF_PIE_CHART_SQL, DEFAULT_PIE_CHART_SQL);
            PieDataset data = (PieDataset) generatePieDataSet(getDatabaseConnection(request), sql);
            chart = ChartFactory.createPieChart("Pie Chart", data, true, true, false);
        } else if (type.equals(BAR_CHART)) {
            String sql = prefs.getValue(Constants.PREF_BAR_CHART_SQL, DEFAULT_BAR_CHART_SQL);
            JDBCCategoryDataset data = (JDBCCategoryDataset) generateBarChartDataSet(
                    getDatabaseConnection(request), sql);
            chart = ChartFactory.createBarChart3D("Bar Chart", "Category", "Value", data,
                    PlotOrientation.VERTICAL, true, true, false);
        } else if (type.equals(TIME_CHART)) {
            String sql = prefs.getValue(Constants.PREF_TIME_SERIES_SQL, DEFAULT_TIME_SERIES_SQL);
            JDBCXYDataset data = (JDBCXYDataset) generateXYDataSet(getDatabaseConnection(request), sql);
            chart = ChartFactory.createTimeSeriesChart("Time Series Chart", "Date", "Rate", data, true, true,
                    false);
        }

    } catch (NoPreferredDbSetException npdbs) {
        npdbs.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return chart;
}

From source file:org.loklak.api.vis.PieChartServlet.java

public JFreeChart getChart(JSONObject jsonData, boolean legendBit, boolean tooltipBit) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    Iterator iter = jsonData.keys();

    while (iter.hasNext()) {
        String keyData = (String) iter.next();
        Float value = Float.parseFloat(jsonData.getString(keyData));
        dataset.setValue(keyData, value);
    }/*w w w  .j a  v a2 s  .  c  o  m*/

    boolean legend = legendBit;
    boolean tooltips = tooltipBit;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createPieChart("Loklak Visualizes - PieChart", dataset, legend, tooltips,
            urls);

    chart.setBorderPaint(Color.BLACK);
    chart.setBorderStroke(new BasicStroke(5.0f));
    chart.setBorderVisible(true);

    return chart;
}

From source file:ai.susi.server.api.vis.PieChartServlet.java

public JFreeChart getChart(JSONObject jsonData, boolean legendBit, boolean tooltipBit) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    Iterator<String> iter = jsonData.keys();

    while (iter.hasNext()) {
        String keyData = iter.next();
        Float value = Float.parseFloat(jsonData.getString(keyData));
        dataset.setValue(keyData, value);
    }/*from w ww . j av a 2s. c o m*/

    boolean legend = legendBit;
    boolean tooltips = tooltipBit;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createPieChart("Loklak Visualizes - PieChart", dataset, legend, tooltips,
            urls);

    chart.setBorderPaint(Color.BLACK);
    chart.setBorderStroke(new BasicStroke(5.0f));
    chart.setBorderVisible(true);

    return chart;
}

From source file:application.logik.Logik.java

public void stats() {
    //http://www.math.hu-berlin.de/~ccafm/lehre_BZQ_Numerik/allg/JAVA_Pakete/JFreeChart/Codes/PieChart_code.html
    //JFreeChart Library (GNU License deshalb benutzen wir die MIT-Lizenz)
    long[] arr = new long[3];
    arr[0] = trT;//from  w  w  w .  ja v  a  2  s .  c  o m
    arr[2] = trR;
    arr[1] = trC;
    arr[step] += trackStop();
    String[] timeText = new String[3];
    for (int i = 0; i < timeText.length; i++) {
        arr[i] = arr[i] / 1000;
        long sek = arr[i] % 60;
        long min = arr[i] / 60;
        if (sek < 10) {
            timeText[i] = min + " : 0" + sek;
        } else {
            timeText[i] = min + " : " + sek;
        }
    }
    long ges = (trT + trR + trC) / 100;
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    pieDataset.setValue("Red: " + timeText[0] + "min", ges * arr[0]);
    pieDataset.setValue("Refactor: " + timeText[2] + "min", ges * arr[2]);
    pieDataset.setValue("Green: " + timeText[1] + "min", ges * arr[1]);

    JFreeChart chart = ChartFactory.createPieChart("Time", pieDataset, true, false, false);
    ChartFrame frame = new ChartFrame("Chart", chart);
    frame.pack();
    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setVisible(true);
}

From source file:org.usip.osp.graphs.GraphServer.java

public static Chart getChartByNameAndRound(String chart_id, String game_round, String sim_id,
        String values_table) {//from   w w w.j a  va2s  .co m

    Chart cci = new Chart();

    String selectChartInfo = "SELECT * FROM `charts` where sf_id = '" //$NON-NLS-1$
            + chart_id + "'"; //$NON-NLS-1$

    try {
        Connection connection = MultiSchemaHibernateUtil.getConnection();
        Statement stmt = connection.createStatement();
        ResultSet rst = stmt.executeQuery(selectChartInfo);

        if (rst.next()) {
            String chart_type = rst.getString("type"); //$NON-NLS-1$
            String chart_title = rst.getString("title"); //$NON-NLS-1$
            String x_axis_title = rst.getString("x_axis_title"); //$NON-NLS-1$
            String y_axis_title = rst.getString("y_axis_title"); //$NON-NLS-1$

            //cci.height = rst.getInt("height");
            //cci.width = rst.getInt("width");

            String howToGetData = rst.getString("first_data_source"); //$NON-NLS-1$

            howToGetData = howToGetData.replace("[simulation_id]", sim_id); //$NON-NLS-1$
            howToGetData = howToGetData.replace("[sim_value_table_name]", values_table); //$NON-NLS-1$

            Statement stmt2 = connection.createStatement();
            ResultSet rst2 = stmt.executeQuery(howToGetData);

            JFreeChart chart = null;

            if (chart_type.equalsIgnoreCase("LineChart")) { //$NON-NLS-1$

                DefaultCategoryDataset cd = DataGatherer.getChartData(chart_type, game_round, howToGetData);

                chart = ChartFactory.createLineChart(chart_title, // chart
                        // title
                        x_axis_title, // domain axis label
                        y_axis_title, // range axis label
                        cd, // data
                        PlotOrientation.VERTICAL, // orientation
                        false, // include legend
                        true, // tooltips
                        false // urls
                );

            } else if (chart_type.equalsIgnoreCase("BarChart")) { //$NON-NLS-1$

                DefaultPieDataset dataset = DataGatherer.getPieData(chart_id, game_round, howToGetData);

                chart = ChartFactory.createPieChart(chart_title, dataset, true, // legend?
                        true, // tooltips?
                        false // URLs?
                );
            }

            cci.setThis_chart(chart);

        } // End of loop if found chart info

        connection.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

    return cci;
}

From source file:org.openmrs.module.vcttrac.web.view.chart.VCTCreatePieChartView.java

private JFreeChart createGenderPieChartView() {
    DefaultPieDataset pieDataset = new DefaultPieDataset();

    VCTModuleService service = Context.getService(VCTModuleService.class);

    try {/*from  ww w  .  j av  a  2  s  .co m*/
        Date reportingDate = new Date();
        int numberOffemale = service.getVCTClientsBasedOnGender("f", reportingDate).size();
        int numberOfMale = service.getVCTClientsBasedOnGender("m", reportingDate).size();

        int all = numberOffemale + numberOfMale;

        Float percentageFemale = new Float(100 * numberOffemale / all);
        pieDataset.setValue(VCTTracUtil.getMessage("vcttrac.person.female", null) + " (" + numberOffemale
                + " , " + percentageFemale + "%)", percentageFemale);

        Float percentageMale = new Float(100 * numberOfMale / all);
        pieDataset.setValue(VCTTracUtil.getMessage("vcttrac.person.male", null) + " (" + numberOfMale + " , "
                + percentageMale + "%)", percentageMale);

        JFreeChart chart = ChartFactory.createPieChart(VCTTracUtil.getMessage("vcttrac.person.gender", null),
                pieDataset, true, true, false);

        return chart;
    } catch (Exception e) {
        log.error(">>GENDER>>PIE>>CHART>> " + e.getMessage());
        e.printStackTrace();
        return ChartFactory.createPieChart(VCTTracUtil.getMessage("vcttrac.person.gender", null), null, true,
                true, false);
    }
}

From source file:userInterface.MonitoringTeamRole.AnalysisJPanel.java

private static JFreeChart createChart(PieDataset dataset) {
    JFreeChart chart = ChartFactory.createPieChart("Suspicious Events: Network based & User-profiling based", // chart title 
            dataset, // data    
            true, // include legend   
            true, false);//  w  w w.  jav a  2  s .  c o  m

    return chart;
}

From source file:utilities.itext.Turnover.java

private static Image createPieChart(HashMap<String, BigDecimal> map, String title) throws Exception {
    DefaultPieDataset data = new DefaultPieDataset();

    for (String key : map.keySet()) {
        data.setValue(key, map.get(key).doubleValue());
    }/*from  w  w w  .  j a v a  2s .  co m*/

    JFreeChart pieChart = ChartFactory.createPieChart(title, data, true, false, Locale.GERMAN);
    //        PiePlot plot = (PiePlot) pieChart.getPlot();
    //        plot.setLabelGenerator(null);

    BufferedImage pie = pieChart.createBufferedImage(500, 500);
    File tempPie = File.createTempFile("png", null);
    ImageIO.write(pie, "png", tempPie);
    Image img = Image.getInstance(tempPie.getPath());

    return img;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.PieChartExpression.java

protected JFreeChart computeChart(final Dataset dataset) {

    PieDataset pieDataset = null;//from  w  w w  .  j  av  a 2  s  .com
    if (dataset instanceof PieDataset) {
        pieDataset = (PieDataset) dataset;
    }

    if (isThreeD()) {
        return ChartFactory.createPieChart3D(computeTitle(), pieDataset, isShowLegend(), false, false);
    } else {
        return ChartFactory.createPieChart(computeTitle(), pieDataset, isShowLegend(), false, false);
    }
}

From source file:de.laures.cewolf.taglib.CewolfChartFactory.java

public static JFreeChart getChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel,
        Dataset data) throws ChartValidationException {
    // first check the dynamically registered chart types
    CewolfChartFactory factory = (CewolfChartFactory) factories.get(chartType);
    if (factory != null) {
        // custom factory found, use it
        return factory.getChartInstance(title, xAxisLabel, yAxisLabel, data);
    }/*  w w  w  . ja v a 2s. c o  m*/

    switch (getChartTypeConstant(chartType)) {
    case XY:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, (XYDataset) data,
                PlotOrientation.VERTICAL, true, true, true);
    case PIE:
        check(data, PieDataset.class, chartType);
        return ChartFactory.createPieChart(title, (PieDataset) data, true, true, true);
    case AREA_XY:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createXYAreaChart(title, xAxisLabel, yAxisLabel, (XYDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case SCATTER:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, (XYDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case AREA:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case HORIZONTAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.HORIZONTAL, true, false, false);
    case HORIZONTAL_BAR_3D:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.HORIZONTAL, true, false, false);
    case LINE:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case STACKED_HORIZONTAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.HORIZONTAL, true, false, false);
    case STACKED_VERTICAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case STACKED_VERTICAL_BAR_3D:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case VERTICAL_BAR:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case VERTICAL_BAR_3D:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case TIME_SERIES:
        check(data, XYDataset.class, chartType);
        return ChartFactory.createTimeSeriesChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, true, false,
                false);
    case CANDLE_STICK:
        check(data, OHLCDataset.class, chartType);
        return ChartFactory.createCandlestickChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true);
    case HIGH_LOW:
        check(data, OHLCDataset.class, chartType);
        return ChartFactory.createHighLowChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true);
    case GANTT:
        check(data, IntervalCategoryDataset.class, chartType);
        return ChartFactory.createGanttChart(title, xAxisLabel, yAxisLabel, (IntervalCategoryDataset) data,
                true, false, false);
    case WIND:
        check(data, WindDataset.class, chartType);
        return ChartFactory.createWindPlot(title, xAxisLabel, yAxisLabel, (WindDataset) data, true, false,
                false);
    //case SIGNAL :
    //  check(data, SignalsDataset.class, chartType);
    //  return ChartFactory.createSignalChart(title, xAxisLabel, yAxisLabel, (SignalsDataset) data, true);
    case VERRTICAL_XY_BAR:
        check(data, IntervalXYDataset.class, chartType);
        return ChartFactory.createXYBarChart(title, xAxisLabel, true, yAxisLabel, (IntervalXYDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case PIE_3D:
        check(data, PieDataset.class, chartType);
        return ChartFactory.createPieChart3D(title, (PieDataset) data, true, false, false);
    case METER:
        check(data, ValueDataset.class, chartType);
        MeterPlot plot = new MeterPlot((ValueDataset) data);
        JFreeChart chart = new JFreeChart(title, plot);
        return chart;
    case STACKED_AREA:
        check(data, CategoryDataset.class, chartType);
        return ChartFactory.createStackedAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data,
                PlotOrientation.VERTICAL, true, false, false);
    case BUBBLE:
        check(data, XYZDataset.class, chartType);
        return ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, (XYZDataset) data,
                PlotOrientation.VERTICAL, true, false, false);

    case AUSTER_CICLOS:
        check(data, IntervalCategoryDataset.class, chartType);
        return ChartFactory.createAusterCiclosChart((IntervalCategoryDataset) data);

    default:
        throw new UnsupportedChartTypeException(chartType + " is not supported.");
    }
}