Capturing click event in a PieChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Divya

Capturing click event in a PieChart

Post by Divya » Tue Oct 29, 2002 6:13 pm

Hello,

I'm new to JFreeChart and Java.I'm a oracle developer.i created charts in java using oracle libraries with thier examples.we are trying to change to JFreeChart as they have more utilities.

My problem is, i created a pie chart with the demo provided the jfreechart -_0.9.4.jar and i'm successful.i wanted to capture the mouse click on the slice and display another chart.(a drill down).i looked at in the API provided there are Mouse click,pressed,release events in chart panel.

as i'm new i don't know how to implement that and i can't find any example for click events in the demo directory provided.

Can anybody help or can u give me some sample code.

import com.jrefinery.data.DefaultPieDataset;
import com.jrefinery.chart.tooltips.StandardPieToolTipGenerator;
import com.jrefinery.chart.*;
import com.jrefinery.ui.ApplicationFrame;
import com.jrefinery.ui.RefineryUtilities;
import oracle.ewt.lwAWT.*;

public class PieChart
extends LWContainer

{
// Chart values
Vector v1 = new Vector();
Vector v2 = new Vector();

// Chart default width and height
int Width = 300;
int Height = 350;

// Needed for pie
DefaultPieDataset data = new DefaultPieDataset();
private String Category[];
private Double Value[];


public PieChart()
{
super(null);
}

public void addData(String sName, String sValue)
{
v1.addElement(sName);
v2.addElement(sValue);
}

public void drawPieChart(String sTitle)
{
Category = new String[v1.size()];
Value = new Double[v2.size()];

for (int j=0; j<v1.size(); j++)
{
Category[j] = new String((String)v1.get(j));
Value[j] = new Double((String)v2.get(j));
data.setValue(Category[j],Value[j]);
}
drawPie(sTitle,Height,Width);
setVisible(true);
Clear();
}

public void Clear()
{
v1 = new Vector();
v2 = new Vector();
}

public void drawPie(String sTitle,int iHeight,int iWidth)
{
setLayout(new GridLayout(1,1));

JFreeChart chart = ChartFactory.createPieChart(sTitle,data,true);
chart.setBackgroundPaint(new Color(191,191,191));

PiePlot plot = (PiePlot) chart.getPlot();
plot.setBackgroundPaint(new Color(191,191,191));
plot.setOutlinePaint(new Color(191,191,191));
plot.setSectionLabelType(PiePlot.PERCENT_LABELS);
plot.setNoDataMessage("No data available");
plot.setToolTipGenerator(new StandardPieToolTipGenerator());

ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(iHeight,iWidth));
add(chartPanel);
chartPanel.addchartMouseListener(this);
setVisible(true);

}

}



Thank you,
Divya

Dave Gilbert

Re: Capturing click event in a PieChart

Post by Dave Gilbert » Wed Oct 30, 2002 9:13 am

Hi Divya,

There is a demo (MouseListenerDemo1.java) included in the "extra" samples download available to developers that have purchased the JFreeChart documentation. It displays a pie chart and writes information about the components of the chart (to standard output) as the user points or clicks with the mouse. That's probably what you are looking for.

Regards,

DG

Divya

Re: Capturing click event in a PieChart

Post by Divya » Wed Oct 30, 2002 5:35 pm

Thanks Dave.

Locked