Label and VerticalBarChart

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

Label and VerticalBarChart

Post by Mats » Thu Nov 14, 2002 1:05 pm

Hi!

Trying to set labels in VerticalBarChart (to explain the meaning of the two bars in this code). But I fail. Do anyone knows how to do it?


String[] ss = {new String("aa"), new String("bb")};
Number[][] nn = {{new Double(4.23)}, {new Double(5.14)}};
DefaultCategoryDataSource def = new DefaultCategoryDataSource(ss, nn);

DataSource dataSource = def;
JFreeChart chart = JFreeChart.createVerticalBarChart(dataSource);

chart.setLegend(null);
chart.setTitle(new StandardTitle("my title ...", fontTitle));
chart.setAntiAlias(true);
chart.setSeriesPaint(paints);
chart.setChartBackgroundPaint(bgColor);

Plot bPlot = chart.getPlot();
BufferedImage image = new BufferedImage(325, 186, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();

g.setRenderingHint (RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(bgColor);
g.fillRect(0, 0, 180, 400);

chart.draw(g, new Rectangle(5, 3, 325, 186));


Thanks.

//Mats

Vanaja

Re: Label and VerticalBarChart

Post by Vanaja » Thu Nov 14, 2002 8:19 pm

Hi Mats,

I hope this would help :
Try using CategoryPlot instead of Plot ...

*****************************************************
CategoryPlot objCategoryPlot = chart.getCategoryPlot();
...
...
...
// Set the data labels display property to true
objCategoryPlot .setValueLabelsVisible(true);
*****************************************************

This would display the values of the Vertical Bars on top of the bars.

Regards,
Vanaja

Locked