How to associate CustomRenderer class with the chart?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
gauravjlj
Posts: 13
Joined: Mon Aug 17, 2009 10:51 am
antibot: No, of course not.

How to associate CustomRenderer class with the chart?

Post by gauravjlj » Wed Aug 19, 2009 2:19 pm

I'm using JSP with that code.
Every thing is fine but unable to do the bars of chart with different colors.

I have been try other solutions on forum but not getting properly.

The main problem, when creating the object of CustomRenderer class extending the BarRenderer.
how can I associate this object with my chart?

Please tell me this as using JSP.

<%
String app_path = application.getRealPath("/");
String query="SELECT * from chart";
JDBCCategoryDataset dataset=new JDBCCategoryDataset("jdbc:mysql://localhost:3306/license_server",
"com.mysql.jdbc.Driver","root","");

dataset.executeQuery( query);
JFreeChart chart = ChartFactory.createBarChart3D(
"Test",
"Id",
"Score",
dataset,
PlotOrientation.VERTICAL, true, true, false);

CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer();

renderer.setSeriesPaint(0, Color.red);
renderer.setSeriesPaint(1, Color.darkGray);

try
{
ChartUtilities.saveChartAsJPEG(new File(app_path + "chart_images/chart.jpg"), chart, 600, 500);
}
catch (IOException e)
{
System.out.println("Problem in creating chart.");
}
%>

<img src="chart_images/chart.jpg" ></img>

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: How to associate CustomRenderer class with the chart?

Post by RichardWest » Wed Aug 19, 2009 7:14 pm

Stop posting the same question multiple times; I have already answered this question for you in Need the different colors of bars.

I would like to echo David's sentiments.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

Locked