How to display series aswell as category values in BAR grapn

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
MasterJ
Posts: 19
Joined: Fri Jun 23, 2006 8:12 am

How to display series aswell as category values in BAR grapn

Post by MasterJ » Wed Jul 19, 2006 11:58 am

Dear David ,

The legend for Bar graph displays only the field names that we draw graph for, but not their values as it does in the case of Pie graph.

In Pie graph,
the legend looks like this:

Boys=100
for a field of boys with a value 100

But for Bar graph it shows only the field name, i.e.

BOYS

Is there any workaround for this?
wwhat I did is the following code :


LegendItemCollection legendItemCollection=new LegendItemCollection();

LegendItemCollection licollection= renderer.getLegendItems();
Iterator iter= licollection.iterator();
int item=-1;
do{
++item;
if(item==licollection.getItemCount())
break;

LegendItem li =licollection.get( item);
java.lang.Number datavalue=dataset.getValue(dataset.getRowKey(item),dataset.getColumnKey(0));
if(datavalue==null)
datavalue=0;
String label=li.getLabel()+"="+datavalue;

LegendItem legendItem=new LegendItem(label,li.getDescription(),li.getToolTipText(),li.getURLText(),li.getShape(),li.getFillPaint());
legendItemCollection.add(legendItem);

}while(iter.hasNext());


LegendSource legendSource=new LegendSource(legendItemCollection);
LegendTitle legendTitle=new LegendTitle(legendSource);

legendTitle.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
legendTitle.setBorder(new BlockBorder());
legendTitle.setBackgroundPaint(new Color(200,150,100));
legendTitle.setPosition(RectangleEdge.BOTTOM);
legendTitle.setItemFont(new Font("Centuary Gothic", Font.ITALIC, 11));

chart.addLegend(legendTitle);

OfCource this works for dataset having only one row(i.e. only one series),and that is where we need to display the values in addition to field names.

For multiple series , the default legend is fine..

Is this the only way or is there any short procedure to do this?


And also, for single series(single row dataset) there is no need to display field/series name as the item label we can altogether eliminate it as there is only one series. For this I had to extend the JDBCCategoryDataset to get that effect.
Is this the way or is there any other way?
Thanking you in advance,
MJ
Master Java

Locked