Color Not Changing

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ponic
Posts: 28
Joined: Thu Aug 04, 2005 7:32 pm

Color Not Changing

Post by ponic » Sun Oct 16, 2005 11:21 pm

I am using StackedBar3D fo my JSP, I am using

StackedBarRenderer3D rend = new StackedBarRenderer3D();
rend.setSeriesPaint(0, Color.GREEN);
rend.setSeriesPaint(1, Color.RED);

However my bar color not getting changed, someone could kindly help?

Thanks in advance

dhchou
Posts: 138
Joined: Tue Jul 05, 2005 11:01 pm

Post by dhchou » Mon Oct 17, 2005 2:06 pm

You need to apply setSeriesPaint to the renderer in YOUR chart. Suppose chart is your JFreeChart instance. You should call

StackedBarRenderer3D rend = chart.getPlot().getRenderer();
rend.setSeriesPaint(0, Color.GREEN);
rend.setSeriesPaint(1, Color.RED);

Hope this helps.

Daniel

ponic
Posts: 28
Joined: Thu Aug 04, 2005 7:32 pm

Post by ponic » Tue Oct 18, 2005 7:08 am

I am calling the StackedBarRenderer3D rend nefore JFreeChart chart gets initialized.

I am pasting my code, kindly correct my mistakes.

***** JSP*****

CategoryAxis categoryAxis = new CategoryAxis("Site");
ValueAxis valueAxis = new NumberAxis("Value");
StackedBarRenderer3D rend = new StackedBarRenderer3D();
StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator();
rend.setItemURLGenerator(new StandardCategoryURLGenerator("xy_chart.jsp","series","section"));
rend.setToolTipGenerator(new StandardCategoryToolTipGenerator());
rend.setDrawBarOutline(true);
rend.setItemURLGenerator(new StandardCategoryURLGenerator("xy_chart.jsp","series","section"));
CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, rend);
JFreeChart chart = new JFreeChart("rr", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
rend = chart.getPlot().getRenderer();

dhchou
Posts: 138
Joined: Tue Jul 05, 2005 11:01 pm

Post by dhchou » Tue Oct 18, 2005 2:23 pm

If you create StackedBarRenderer3D rend nefore JFreeChart chart gets initialized, then you need to do replace the last line in your code snippet with:

chart.getPlot().setRenderer(rend);

and then apply the setSeriesPaint method suggested in my previous post.

Daniel

ponic
Posts: 28
Joined: Thu Aug 04, 2005 7:32 pm

Post by ponic » Tue Oct 18, 2005 6:22 pm

I am sorry about the ignorance,now I am getting error, could you kindly correct my code.

method setRenderer(org.jfree.chart.renderer.category.StackedBarRenderer3D) not found in class org.jfree.chart.plot.Plot


**** JSP***
CategoryAxis categoryAxis = new CategoryAxis("Site");
ValueAxis valueAxis = new NumberAxis("Value");
StackedBarRenderer3D rend = new StackedBarRenderer3D();
StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator();
rend.setItemURLGenerator(new StandardCategoryURLGenerator("xy_chart.jsp","series","section"));
rend.setToolTipGenerator(new StandardCategoryToolTipGenerator());
rend.setDrawBarOutline(true);

CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, rend);
JFreeChart chart = new JFreeChart("rr", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
chart.getPlot().setRenderer(rend);

dhchou
Posts: 138
Joined: Tue Jul 05, 2005 11:01 pm

Post by dhchou » Tue Oct 18, 2005 8:47 pm

You need to cast the plot you got from chart to CategoryPlot:

((CategoryPlot) chart.getPlot()).setRenderer(rend);

Daniel

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Tue Oct 18, 2005 9:24 pm

or call getCategoryPlot()

or just use the plot reference from the previous source line

ponic
Posts: 28
Joined: Thu Aug 04, 2005 7:32 pm

Post by ponic » Tue Oct 18, 2005 9:33 pm

It is working perfectly.

Thanks a lot and much and much appreciated.

Regards

Locked