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:sentimentanalyzer.ChartController.java

public void createAndPopulatePieChart__TESTER(JPanel pnlPieChart) {

    DefaultPieDataset data = new DefaultPieDataset();

    data.setValue(Pos, 0 /*count for 1 */);
    data.setValue(Neu, 0 /*count for 0 */);
    data.setValue(Neg, 0 /*count for -1 */);

    JFreeChart chart = ChartFactory.createPieChart("Sent. Distr. for Testing", data, false, // legend?
            false, // tooltips?
            false // URLs?
    );// w  ww .  j  a  v a 2s.c  om
    ChartPanel CP = new ChartPanel(chart);

    PiePlot plot = (PiePlot) chart.getPlot();

    plot.setSectionPaint("Pie chart is not available", Color.LIGHT_GRAY);
    plot.setExplodePercent(Pos, 0.025);
    plot.setExplodePercent(Neg, 0.025);
    plot.setExplodePercent(Neu, 0.025);

    //Customize PieChart to show absolute values and percentages;

    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0.00%"));
    plot.setLabelGenerator(gen);

    TextTitle legendText = new TextTitle("The total number of tweets: ");
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);

    pnlPieChart.setLayout(new java.awt.BorderLayout());
    pnlPieChart.add(CP, BorderLayout.CENTER);
}

From source file:probe.com.view.body.quantcompare.PieChart.java

private String initPieChart(int width, int height, String title) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int x = 0; x < labels.length; x++) {
        dataset.setValue(labels[x], values[x]);

    }/*  w ww  .  ja v  a  2s.c om*/
    PiePlot plot = new PiePlot(dataset);
    plot.setNoDataMessage("No data available");
    plot.setCircular(true);

    plot.setLabelGap(0);

    plot.setLabelFont(new Font("Verdana", Font.BOLD, 10));
    plot.setLabelGenerator(new PieSectionLabelGenerator() {

        @Override
        public String generateSectionLabel(PieDataset pd, Comparable cmprbl) {
            return valuesMap.get(cmprbl.toString());
        }

        @Override
        public AttributedString generateAttributedSectionLabel(PieDataset pd, Comparable cmprbl) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    plot.setSimpleLabels(true);

    plot.setLabelBackgroundPaint(null);
    plot.setLabelShadowPaint(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelOutlinePaint(null);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setInteriorGap(0);
    plot.setShadowPaint(Color.WHITE);
    plot.setOutlineVisible(false);
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(1.2f));
    plot.setInteriorGap(0.05);
    for (String label : labels) {
        plot.setSectionPaint(label, defaultKeyColorMap.get(label));
    }

    JFreeChart chart = new JFreeChart(plot);
    //        chart.setTitle(new TextTitle(title, new Font("Verdana", Font.BOLD, 13)));
    chart.setBorderPaint(null);
    chart.setBackgroundPaint(null);
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setItemFont(new Font("Verdana", Font.PLAIN, 10));
    String imgUrl = saveToFile(chart, width, height);

    return imgUrl;

}

From source file:com.pureinfo.srm.reports.impl.PieChartBuilder.java

private DefaultPieDataset getDataset(Iterator _result) {
    DefaultPieDataset ds = new DefaultPieDataset();
    while (_result.hasNext()) {
        DolphinObject obj = (DolphinObject) _result.next();
        String sName = obj.getStrProperty("name");
        double dblValue = obj.getDoubleProperty("value", 0.0);
        ds.setValue(sName, dblValue);
    }//  w  ww .j  a v a 2 s. c om
    return ds;
}

From source file:sentimentanalyzer.ChartController.java

public void createAndPopulatePieChart(JPanel pnlPieChart, double positiveValue, double negativeValue,
        double neutralValue) {

    DefaultPieDataset data = new DefaultPieDataset();

    data.setValue(Pos, positiveValue /*count for 1 */);
    data.setValue(Neu, neutralValue /*count for 0 */);
    data.setValue(Neg, negativeValue /*count for -1 */);

    JFreeChart chart = ChartFactory.createPieChart("Sent. Distr. for Testing", data, false, // legend?
            false, // tooltips?
            false // URLs?
    );//from  ww w.  ja v a 2s . c  o  m
    ChartPanel CP = new ChartPanel(chart);

    PiePlot plot = (PiePlot) chart.getPlot();

    plot.setSectionPaint("Pie chart is not available", Color.LIGHT_GRAY);
    plot.setExplodePercent(Pos, 0.02);
    plot.setExplodePercent(Neg, 0.02);
    plot.setExplodePercent(Neu, 0.02);

    double sum = positiveValue + negativeValue + neutralValue;
    int z = (int) sum;

    //Customize PieChart to show absolute values and percentages;

    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0.00%"));
    plot.setLabelGenerator(gen);

    TextTitle legendText = new TextTitle("The total number of tweets: " + z);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);

    pnlPieChart.removeAll();

    pnlPieChart.setLayout(new java.awt.BorderLayout());
    pnlPieChart.add(CP, BorderLayout.CENTER);

}

From source file:Vista.frm_MasVendidoInforme.java

private void graficarDatos() {
    BL.Funciones_frm_MasVendido fun = new Funciones_frm_MasVendido();
    try {/*  w  w  w.java 2  s  .c  om*/
        DefaultPieDataset data = new DefaultPieDataset();
        for (int i = 0; i < id_producto.length; i++) {
            data.setValue(producto[i], fun.procentajeMasVendido(cantidad[i], sumatoriaCantidades()));
        }
        ChartPanel panel;
        JFreeChart chart = ChartFactory.createPieChart3D("PASTEL", data, true, true, true);
        panel = new ChartPanel(chart);
        panel.setBounds(0, 30, 450, 450);
        pan_derecha.add(panel);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }
}

From source file:UserInterface.PublisherRole.ViewUserHabitsJPanel.java

private PieDataset createDataset(UserPotential userPotential) {
    DefaultPieDataset dataset = new DefaultPieDataset();

    for (Tag tag : userPotential.getTagList().getTagList()) {
        dataset.setValue(tag.getTagName(), tag.getNumberOfVisits());
    }//from  www . j ava2 s.c  om

    return dataset;
}

From source file:GUILayer.CustomerStatsByGroup.java

protected PieDataset createProductDataset() {
    DefaultPieDataset result = new DefaultPieDataset();
    ProductCtrl prdCtrl = new ProductCtrl();
    for (Product prd : prdCtrl.getProducts()) {
        System.out.println(prd.getSoldProducts());
        if (prd.getSoldProducts() > 0) {
            result.setValue(prd.getCategory(), prd.getSoldProducts());
        }// ww w  .  j  a  va2  s.  c om
    }
    return result;
}

From source file:views.Student_Home.java

private void populateTasks() {
    ArrayList taskList = studentActions.fetchTasks();

    while (taskModel.getRowCount() != 0) {
        taskModel.removeRow(taskModel.getRowCount() - 1);
    }// w  w  w.  ja va 2  s.c  o m

    Task task = new Task();
    Date currDate = new Date();
    int totalTime = 0;
    int timePassed = 0;
    for (int i = 0; i < taskList.size(); i++) {
        task = (Task) taskList.get(i);
        this.taskLinkedList.add(task.getTaskId());
        if (currDate.before(task.getStartDate())) {
            String[] str = { task.getTaskId(), task.getTaskDescription(), task.getProjectId(), "Up coming" };
            taskModel.insertRow(taskModel.getRowCount(), str);
        } else {
            String[] str = { task.getTaskId(), task.getTaskDescription(), task.getProjectId(), "In progress" };
            taskModel.insertRow(taskModel.getRowCount(), str);
            timePassed = timePassed + (currDate.getDate() - task.getStartDate().getDate());
        }
        totalTime = totalTime + (task.getEndDate().getDate() - task.getStartDate().getDate());

    }
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Task completed", timePassed);
    dataset.setValue("Pending Tasks", totalTime - timePassed);
    JFreeChart taskStatusChart = ChartFactory.createPieChart("Tasks completion status", dataset, true, true,
            true);
    PiePlot piePlot = (PiePlot) taskStatusChart.getPlot();
    ChartPanel chartPanel = new ChartPanel(taskStatusChart);
    chartPanel.setSize(323, 303);
    chartPanel.setVisible(true);
    //chartPanel.setLocation(500, 200);
    taskPieChart.removeAll();
    taskPieChart.add(chartPanel);
    taskPieChart.updateUI();
    taskPieChart.repaint();
}

From source file:bzstats.chart.KillRatioChart.java

/**
 * @see bzstats.chart.ChartFactory#getChart()
 *//*from  w ww. java2  s.co m*/
protected JFreeChart getChart() {

    DefaultPieDataset dataset = new DefaultPieDataset();

    Iterator playeriter = stats.getPlayerStats().values().iterator();

    PlayerStats player;
    int playercount = 0;
    while (playeriter.hasNext() && (playercount++ < MAXPLAYERS)) {
        player = (PlayerStats) playeriter.next();
        dataset.setValue(player.getName(), player.getKillRatio());
    }

    //       create chart and plot
    JFreeChart chart = ChartFactory.createPieChart3D("Killratio", // chart title
            dataset, // data
            false, // include legend
            true, false);

    chart.addSubtitle(new TextTitle("kills/deaths"));

    final PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(290);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    plot.setBackgroundAlpha(0);
    plot.setNoDataMessage("No data to display");
    plot.setDepthFactor(.1f);

    return chart;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.UserDiskSpace.java

/** Builds and lays out the GUI. */
void buildGUI() {
    data.removeAll();/* ww w  . jav  a 2 s.c  om*/
    DiskQuota quota = view.isDiskSpaceLoaded();
    if (quota != null) {
        DefaultPieDataset dataset = new DefaultPieDataset();
        long free = quota.getAvailableSpace();
        long used = quota.getUsedSpace();
        if (free < 0 || used < 0) {
            buildChartNotAvailable();
            return;
        }
        dataset.setValue("Free " + UIUtilities.formatFileSize(free), free);
        dataset.setValue("Used " + UIUtilities.formatFileSize(used), used);
        try {
            JFreeChart chart = ChartFactory.createPieChart3D("", dataset, false, true, false);
            PiePlot3D plot = (PiePlot3D) chart.getPlot();
            plot.setDirection(Rotation.CLOCKWISE);
            plot.setForegroundAlpha(0.55f);
            data.add(new ChartPanel(chart), BorderLayout.CENTER);
        } catch (Exception e) {
            buildChartNotAvailable();
        }

    } else {
        JXBusyLabel busyLabel = new JXBusyLabel();
        busyLabel.setBackground(UIUtilities.BACKGROUND_COLOR);
        busyLabel.setEnabled(true);
        busyLabel.setBusy(true);
        JPanel p = UIUtilities.buildComponentPanelCenter(busyLabel);
        p.setBackground(UIUtilities.BACKGROUND_COLOR);
        data.add(p, BorderLayout.CENTER);
    }
    revalidate();
    repaint();
}