How to change dataset values?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
sayali chavan
Posts: 2
Joined: Fri Mar 30, 2012 2:54 pm
antibot: No, of course not.

How to change dataset values?

Post by sayali chavan » Fri Mar 30, 2012 5:43 pm

I want change dataset values of pie chart. Code as following:

package org.jfree.chart.demo;

import java.awt.Font;

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
* A simple demonstration application showing how to create a pie chart using
* data from a {@link DefaultPieDataset}.
*/
public class PieChartDemo1 extends ApplicationFrame {

/**
* Default constructor.
*
* @param title the frame title.
*/
public PieChartDemo1(String title) {
super(title);
setContentPane(createDemoPanel());
}

/**
* Creates a sample dataset.
*
* @return A sample dataset.
*/
private static PieDataset createDataset() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("One", new Double(43.2));
dataset.setValue("Two", new Double(10.0));
dataset.setValue("Three", new Double(27.5));
dataset.setValue("Four", new Double(17.5));
dataset.setValue("Five", new Double(11.0));
dataset.setValue("Six", new Double(19.4));
return dataset;
}

/**
* Creates a chart.
*
* @param dataset the dataset.
*
* @return A chart.
*/
private static JFreeChart createChart(PieDataset dataset) {

JFreeChart chart = ChartFactory.createPieChart(
"Pie Chart Demo 1", // chart title
dataset, // data
true, // include legend
true,
false
);

PiePlot plot = (PiePlot) chart.getPlot();
plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
plot.setNoDataMessage("No data available");
plot.setCircular(false);
plot.setLabelGap(0.02);
return chart;

}

/**
* Creates a panel for the demo (used by SuperDemo.java).
*
* @return A panel.
*/
public static JPanel createDemoPanel() {
JFreeChart chart = createChart(createDataset());
return new ChartPanel(chart);
}

/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) {

PieChartDemo1 demo = new PieChartDemo1("Pie Chart Demo 1");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);

}

}


plz help me..

conwaypm
Posts: 11
Joined: Wed Dec 21, 2011 2:49 pm
antibot: No, of course not.

Re: How to change dataset values?

Post by conwaypm » Tue Apr 10, 2012 3:37 pm

Could you expand a little on what you mean? You could quite easily change the values specified in the 'createDataset' method. Do you mean changing the values after the chart has been created?

remiohead
Posts: 201
Joined: Fri Oct 02, 2009 3:53 pm
antibot: No, of course not.

Re: How to change dataset values?

Post by remiohead » Wed Apr 11, 2012 5:06 pm

DefaultPieDataset has the following

Code: Select all

public void setValue(Comparable key, Number value)
public void setValue(Comparable key, double value)
public void insertValue(int position, Comparable key, double value)
public void insertValue(int position, Comparable key, double value)
All these methods fire a DatasetChangeEvent which will result in the chart view updating with the new/changed data.

Locked