Example usage for org.jfree.data.general DefaultPieDataset setValue

List of usage examples for org.jfree.data.general DefaultPieDataset setValue

Introduction

In this page you can find the example usage for org.jfree.data.general DefaultPieDataset setValue.

Prototype

public void setValue(Comparable key, double value) 

Source Link

Document

Sets the data value for a key and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:org.talend.dataprofiler.chart.TOPChartService.java

@Override
public Object createPieDataset(Map<String, Double> valueMap) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    if (valueMap != null) {
        Iterator<String> iterator = valueMap.keySet().iterator();
        while (iterator.hasNext()) {
            String label = iterator.next();
            dataset.setValue(label, valueMap.get(label));
        }/* w  w  w .j a v a2 s .c  o  m*/
    }
    return dataset;
}

From source file:ui.Analyze.java

private Component buatPermintaan(LocalDate l) throws SQLException {
    org.jfree.data.general.DefaultPieDataset data = new org.jfree.data.general.DefaultPieDataset();
    java.sql.PreparedStatement p = d.getPS(
            "select detjual.brg,sum(detjual.jum)as qty from jual inner join detjual where jual.tgl>=? and "
                    + "jual.tgl<? group by detjual.brg");
    p.setDate(1, Date.valueOf(l));
    p.setDate(2, Date.valueOf(l.plusMonths(1)));
    java.sql.ResultSet r = p.executeQuery();
    while (r.next())
        data.setValue(getNamaBrg(r.getString("brg")), r.getDouble("qty"));
    r.close();/*w ww  .  j a v  a 2 s. c om*/
    p.close();
    return new org.jfree.chart.ChartPanel(ChartFactory.createPieChart("PERMINTAAN", data, true, true, false));
}

From source file:ca.myewb.frame.servlet.GraphServlet.java

private JFreeChart getPost2Pie(Session s) {
    JFreeChart chart;/*from   ww w  .j  ava2s  . co  m*/
    DefaultPieDataset ds = new DefaultPieDataset();

    int numPosts = 0;
    int numTypePosts = 0;

    String query = "select count(*) from PostModel as p where p.group.id=1 and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ds.setValue("Org List", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.group.admin=false and p.group.postName not like 'anyone in the%' and "
            + "p.group.public=true and p.group.parent is null and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ds.setValue("General Public Lists", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.group.admin=false and "
            + "p.group.public=false and p.group.parent is null and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ds.setValue("General Private Lists", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.group.admin=true and p.group.visible=true"
            + " and p.group.id != 1 and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ds.setValue("All-exec Lists", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.group.id = 14 and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ds.setValue("Deleted Posts", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.group.postName like 'anyone in the%' and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ds.setValue("Chapter Lists", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.group.parent!=null and "
            + "p.group.shortname='exec' and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ds.setValue("Chapter-exec Lists", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.group.parent!=null and "
            + "p.group.shortname!='exec' and p.group.public=true and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ds.setValue("Chapter Public Lists", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.group.parent!=null and "
            + "p.group.shortname!='exec' and p.group.public=false and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ds.setValue("Chapter Private Lists", numTypePosts);
    numPosts += numTypePosts;

    chart = ChartFactory.createPieChart("Post Group Breakdown (for " + numPosts + " posts)", ds, false, false,
            false);

    PiePlot plot = ((PiePlot) chart.getPlot());
    StandardPieItemLabelGenerator n = new StandardPieItemLabelGenerator("{0} = {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0.0%"));
    plot.setLabelGenerator(n);
    return chart;
}

From source file:UserInterface.CentreForDiseaseControl.AddDiseaseJPanel.java

public void displayPieChart(String diseaseName) {
    String sName = "";
    int winnerState = 0;
    int totalQuantityConsumedInState = 0;
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    for (PHDEnterprise phdEnterprise : enterprise.getPhdList()) {
        String stateName = phdEnterprise.getStateName();
        for (Order order : enterprise.getMasterOrderCatalog().getOrderList()) {
            if (order.getSite().getStateName().equals(stateName)) {
                for (OrderItem orderItem : order.getOrderItemList()) {
                    if (orderItem.getVaccine().getDisease().getDiseaseName().equals(diseaseName)
                            && orderItem.getIsOrderItemApprovedByCdc().equals("Approved")) {
                        totalQuantityConsumedInState = totalQuantityConsumedInState
                                + orderItem.getTotalQuantity();
                        if (totalQuantityConsumedInState > winnerState) {
                            winnerState = totalQuantityConsumedInState;
                            sName = stateName;
                        }//w  w  w.  j a v  a  2s  .  co m
                    }
                }
            }
        }
        pieDataset.setValue(stateName, totalQuantityConsumedInState);
        totalQuantityConsumedInState = 0;
    }

    JFreeChart chart = ChartFactory.createPieChart("Pie Chart", pieDataset, true, true, true);
    PiePlot p = (PiePlot) chart.getPlot();
    ChartFrame frame = new ChartFrame("Disease Summary", chart);
    frame.setVisible(true);
    frame.setSize(450, 500);

    stateNameJTextField.setText(sName);
}

From source file:ca.myewb.frame.servlet.GraphServlet.java

private JFreeChart getPostPie(Session s) {
    JFreeChart chart;/* w  ww . j  a v a 2s . c o  m*/
    DefaultPieDataset ds = new DefaultPieDataset();

    int numPosts = 0;
    int numTypePosts = 0;

    String query;

    query = "select count(*) from PostModel as p where p.poster.gender='m' and p.emailed=true and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ;
    ds.setValue("Emails by Males", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.poster.gender='m' and "
            + "p.parent is null and p.emailed=false and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ;
    ds.setValue("Posts by Males", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.poster.gender='m' and "
            + "p.parent is not null and p.emailed=false and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ;
    ds.setValue("Replies by Males", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.poster.gender!='f' and p.poster.gender!='m' and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ;
    ds.setValue("All Posts by Unknown Gender", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.poster.gender='f' and "
            + "p.parent is not null and p.emailed=false and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ;
    ds.setValue("Replies by Females", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.poster.gender='f' and "
            + "p.parent is null and p.emailed=false and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ;
    ds.setValue("Posts by Females", numTypePosts);
    numPosts += numTypePosts;

    query = "select count(*) from PostModel as p where p.poster.gender='f' and p.emailed=true and p.date>?";
    numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate()).list().get(0))
            .intValue();
    ;
    ds.setValue("Emails by Females", numTypePosts);
    numPosts += numTypePosts;

    chart = ChartFactory.createPieChart("Post Type/Author Gender Breakdown (for " + numPosts + " posts)", ds,
            false, false, false);

    PiePlot plot = ((PiePlot) chart.getPlot());
    StandardPieItemLabelGenerator n = new StandardPieItemLabelGenerator("{0} = {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0.0%"));
    plot.setLabelGenerator(n);
    return chart;
}

From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java

/**
 * onClick button PieChart. <br>/*www . j  av  a 2s .  c  o  m*/
 * 
 * @param event
 * @throws IOException
 */
public void onClick$button_CustomerChart_PieChart(Event event) throws InterruptedException, IOException {
    // logger.debug(event.toString());

    div_chartArea.getChildren().clear();

    // get the customer ID for which we want show a chart
    long kunId = getCustomer().getId();

    // get a list of data
    List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId);

    if (kunAmountList.size() > 0) {

        DefaultPieDataset pieDataset = new DefaultPieDataset();

        for (ChartData chartData : kunAmountList) {

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(chartData.getChartKunInvoiceDate());

            int month = calendar.get(Calendar.MONTH) + 1;
            int year = calendar.get(Calendar.YEAR);
            String key = String.valueOf(month) + "/" + String.valueOf(year);

            BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3);
            String amount = String.valueOf(bd.doubleValue());

            // fill the data
            pieDataset.setValue(key + " " + amount,
                    new Double(chartData.getChartKunInvoiceAmount().doubleValue()));
        }

        String title = "Monthly amount for year 2009";
        JFreeChart chart = ChartFactory.createPieChart(title, pieDataset, true, true, true);
        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setForegroundAlpha(0.5f);
        BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null);
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage chartImage = new AImage("Pie Chart", bytes);

        Image img = new Image();
        img.setContent(chartImage);
        img.setParent(div_chartArea);

    } else {

        div_chartArea.getChildren().clear();

        Label label = new Label();
        label.setValue("This customer have no data for showing in a chart!");

        label.setParent(div_chartArea);

    }
}

From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java

/**
 * onClick button PieChart 3D. <br>
 * /*from   w  w w  .ja  v a 2  s  . c o m*/
 * @param event
 * @throws IOException
 */
public void onClick$button_CustomerChart_PieChart3D(Event event) throws InterruptedException, IOException {
    // logger.debug(event.toString());

    div_chartArea.getChildren().clear();

    // get the customer ID for which we want show a chart
    long kunId = getCustomer().getId();

    // get a list of data
    List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId);

    if (kunAmountList.size() > 0) {

        DefaultPieDataset pieDataset = new DefaultPieDataset();

        for (ChartData chartData : kunAmountList) {

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(chartData.getChartKunInvoiceDate());

            int month = calendar.get(Calendar.MONTH) + 1;
            int year = calendar.get(Calendar.YEAR);
            String key = String.valueOf(month) + "/" + String.valueOf(year);

            BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3);
            String amount = String.valueOf(bd.doubleValue());

            // fill the data
            pieDataset.setValue(key + " " + amount,
                    new Double(chartData.getChartKunInvoiceAmount().doubleValue()));
        }

        String title = "Monthly amount for year 2009";
        JFreeChart chart = ChartFactory.createPieChart3D(title, pieDataset, true, true, true);
        PiePlot3D plot = (PiePlot3D) chart.getPlot();
        plot.setForegroundAlpha(0.5f);
        BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null);
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage chartImage = new AImage("Pie Chart", bytes);

        Image img = new Image();
        img.setContent(chartImage);
        img.setParent(this.div_chartArea);

    } else {

        div_chartArea.getChildren().clear();

        Label label = new Label();
        label.setValue("This customer have no data for showing in a chart!");

        label.setParent(div_chartArea);

    }
}

From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java

/**
 * onClick button Ring Chart. <br>
 * /*from   w  w  w .  j  av  a 2  s.co  m*/
 * @param event
 * @throws IOException
 */
public void onClick$button_CustomerChart_RingChart(Event event) throws InterruptedException, IOException {
    // logger.debug(event.toString());

    div_chartArea.getChildren().clear();

    // get the customer ID for which we want show a chart
    long kunId = getCustomer().getId();

    // get a list of data
    List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId);

    if (kunAmountList.size() > 0) {

        DefaultPieDataset pieDataset = new DefaultPieDataset();

        for (ChartData chartData : kunAmountList) {

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(chartData.getChartKunInvoiceDate());

            int month = calendar.get(Calendar.MONTH) + 1;
            int year = calendar.get(Calendar.YEAR);
            String key = String.valueOf(month) + "/" + String.valueOf(year);

            BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3);
            String amount = String.valueOf(bd.doubleValue());

            // fill the data
            pieDataset.setValue(key + " " + amount,
                    new Double(chartData.getChartKunInvoiceAmount().doubleValue()));
        }

        String title = "Monthly amount for year 2009";
        JFreeChart chart = ChartFactory.createRingChart(title, pieDataset, true, true, true);
        RingPlot plot = (RingPlot) chart.getPlot();
        plot.setForegroundAlpha(0.5f);
        BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null);
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage chartImage = new AImage("Ring Chart", bytes);

        Image img = new Image();
        img.setContent(chartImage);
        img.setParent(this.div_chartArea);

    } else {

        div_chartArea.getChildren().clear();

        final Label label = new Label();
        label.setValue("This customer have no data for showing in a chart!");

        label.setParent(div_chartArea);

    }
}

From source file:org.lsug.quota.portlet.SitesQuotaPortlet.java

@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    StringBundler sb = new StringBundler(5);

    String type = ParamUtil.getString(resourceRequest, "type", "sites");

    JFreeChart jFreeChart = null;/*from w  w w .  j a  va2s. co m*/

    DefaultPieDataset pieDataset = new DefaultPieDataset();

    try {
        long[] classNameIds = null;

        if ("sites".equals(type)) {
            classNameIds = new long[] { PortalUtil.getClassNameId(Group.class.getName()),
                    PortalUtil.getClassNameId(Organization.class.getName()) };
        } else {
            classNameIds = new long[] { PortalUtil.getClassNameId(User.class.getName()) };
        }

        // OrderByComparator

        String orderByCol = "quotaUsed";
        String orderByType = "desc";
        OrderByComparator orderByComparator = QuotaUtil.getQuotaOrderByComparator(orderByCol, orderByType);

        List<Quota> siteQuotas = QuotaLocalServiceUtil.getQuotaByCompanyIdClassNameIds(
                themeDisplay.getCompanyId(), classNameIds, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                orderByComparator);

        for (Quota siteQuota : siteQuotas) {
            if (siteQuota.isEnabled()) {
                Group group = GroupLocalServiceUtil.getGroup(siteQuota.getClassPK());
                pieDataset.setValue(group.getDescriptiveName(themeDisplay.getLocale()),
                        siteQuota.getQuotaUsed());
            }
        }

        sb.append(QuotaUtil.getResource(resourceRequest, "sites-quota-enabled-sites-used-diagram-title"));

        jFreeChart = getCurrentSizeJFreeChart(sb.toString(), pieDataset);

        resourceResponse.setContentType(ContentTypes.IMAGE_PNG);

        OutputStream outputStream = null;

        try {
            outputStream = resourceResponse.getPortletOutputStream();
            ChartUtilities.writeChartAsPNG(outputStream, jFreeChart, 400, 200);
        } finally {
            if (outputStream != null) {
                outputStream.close();
            }
        }

    } catch (Exception e) {
        LOGGER.error(e);
        throw new PortletException(e);
    }
}

From source file:org.lsug.quota.web.internal.portlet.SitesQuotaWebPortlet.java

@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    StringBundler sb = new StringBundler(5);

    String type = ParamUtil.getString(resourceRequest, "type", "sites");

    JFreeChart jFreeChart = null;//  w  w  w.  j a va2s  . c  om

    DefaultPieDataset pieDataset = new DefaultPieDataset();

    try {
        long[] classNameIds = null;

        if ("sites".equals(type)) {
            classNameIds = new long[] { PortalUtil.getClassNameId(Group.class.getName()),
                    PortalUtil.getClassNameId(Organization.class.getName()) };
        } else {
            classNameIds = new long[] { PortalUtil.getClassNameId(User.class.getName()) };
        }

        // OrderByComparator

        String orderByCol = "quotaUsed";
        String orderByType = "desc";
        OrderByComparator<Quota> orderByComparator = QuotaUtil.getQuotaOrderByComparator(orderByCol,
                orderByType);

        List<Quota> siteQuotas = _quotaLocalService.getQuotaByCompanyIdClassNameIds(themeDisplay.getCompanyId(),
                classNameIds, QueryUtil.ALL_POS, QueryUtil.ALL_POS, orderByComparator);

        for (Quota siteQuota : siteQuotas) {
            if (siteQuota.isEnabled()) {
                Group group = _groupLocalService.getGroup(siteQuota.getClassPK());
                pieDataset.setValue(group.getDescriptiveName(themeDisplay.getLocale()),
                        siteQuota.getQuotaUsed());
            }
        }

        ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language",
                resourceRequest.getLocale(), getClass());

        sb.append(LanguageUtil.get(resourceBundle, "sites-quota-enabled-sites-used-diagram-title"));

        jFreeChart = getCurrentSizeJFreeChart(sb.toString(), pieDataset);

        resourceResponse.setContentType(ContentTypes.IMAGE_PNG);

        OutputStream outputStream = null;

        try {
            outputStream = resourceResponse.getPortletOutputStream();
            ChartUtilities.writeChartAsPNG(outputStream, jFreeChart, 400, 200);
        } finally {
            if (outputStream != null) {
                outputStream.close();
            }
        }

    } catch (Exception e) {
        LOGGER.error(e);
        throw new PortletException(e);
    }
}