PDA

View Full Version : Getting label in FilledBarChart



borisperezg
27 Jul 2010, 1:13 PM
Hi everyone.

I write to us because I have a problem. Im painting a FilledBarChart and I need to know what bar was clicked. In a pie chart I use a listener and inside it a use this:


private ChartListener listener = new ChartListener() {
public void chartClick(ChartEvent ce) {
PieChart.Slice pie = (PieChart.Slice) ce.getDataType();
String label = pie.getLabel();
}
};

But... In a FilledBarChart or AreaChart how am I going to do that ?

Thanks for all the help.

borisperezg
27 Jul 2010, 1:26 PM
Hey, I found a way. Since FilledBarChart save its values in a List of Numbers so I did this within my listener' chartClick method:


Number number = (Number)(ce.getDataType().getValue());

But, the other problem is still there. How am I going to get the X-Axis's label for that value ? There are important to note that a FilledBarChart can have several x-axis labels with the same value.

I need your help. Thanks.

borisperezg
27 Jul 2010, 1:45 PM
To be more clear...
http://www.imageno.com/thumbs/20100727/3iudu7uxe8og.jpg (http://www.imageno.com/3iudu7uxe8ogpic.html)

Thanks a lot.

sven
27 Jul 2010, 2:01 PM
ChartListener listener = new ChartListener() {
public void chartClick(ChartEvent ce) {
ChartModel c = ce.getChartModel();
Collection<?> co = c.getXAxis().getLabels().getLabels();
if (co instanceof List<?>) {
System.out.println(((List<?>) co).get(ce.getChartConfig().getValues().indexOf(ce.getDataType())));
}

}
};

borisperezg
27 Jul 2010, 2:24 PM
I really dont understand what you did but it works and its perfect for me. Thanks a lot.

See you.

sven
28 Jul 2010, 3:53 AM
I really dont understand what you did but it works and its perfect for me. Thanks a lot.

See you.


You better try to understand that code. If you just copy & paste code you dont understand, it wont be good for your application.

borisperezg
28 Jul 2010, 6:17 AM
I will.

Before you gave me that code I did some trick. I created a List of Bars, and set this:

b.set("label", "Oficina de Sistemas");

Then, in my listener, I got Bar and label with this:

Bar b = (Bar)ce.getDataType();
b.get("label")

And it worked too, but of course, yours is better and more right form to do it.

Thanks.