static class LabelGenerator implements CategoryLabelGenerator
{
public float var;
public LabelGenerator(float var){
this.var = var;
//ETHLogger.log( "var ---->" + var);
}
public String generateLabel(CategoryDataset dataset,int series,int category )
{
String result = null;
final Number value = dataset.getValue(series, category);
return ""+value;
}
}
private JFreeChart createBarChart(HttpServletRequest request,String hval) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
ReportsBean bean = new ReportsBean();
ConnectionFactory conFac = new ConnectionFactory();
Connection con=conFac.getConnection();
Vector vec1=new Vector();
HttpSession session = request.getSession(false);
vec1 = (Vector)session.getAttribute("vec");
String Fdate="";
JFreeChart chart=null;
float var[];
try {
var = new float[vec1.size()];
for(int i=0;i<vec1.size();i++)
{
String VarianceDetail = (String)vec1.get(i);
StringTokenizer st=new StringTokenizer(VarianceDetail,"$");
String prdname=st.nextToken();
String id = st.nextToken();
String uom=st.nextToken();
float plan=Float.parseFloat(st.nextToken());
int plan1 = (int) plan ;
float actual=Float.parseFloat(st.nextToken());
int actual1 = (int) actual ;
if(hval.equals(id)){
String series1 = "Planned ";
String series2 = "Actual";
String category1 = "Planned";
String category2 = "Actual";
String category = "";
dataset.addValue(plan, series1, category);
dataset.addValue(actual, series2, category);
}
if(request.getParameter("fromdate")!=null){
String fromdate = request.getParameter("fromdate");
}
if(request.getParameter("todate")!=null){
String todate = request.getParameter("todate");
}
if(dataset!=null){
if(hval.equals(id)){
chart = ChartFactory.createBarChart3D(
prdname,
"Comparision",
"Quantity in "+ uom ,
dataset,
PlotOrientation.VERTICAL,
true,
true,
false
);
}}}
CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setUpperMargin(0.5);
CategoryItemRenderer renderer = plot.getRenderer();
renderer.setItemLabelPaint(Color.white.brighter());
for(int i =0;i<var.length;i++){
renderer.setLabelGenerator(new LabelGenerator(var[i]));
renderer.setItemLabelFont(new Font("Serif", Font.PLAIN, 20));
renderer.setItemLabelsVisible(null);
renderer.setSeriesItemLabelsVisible(0, false);
renderer.setSeriesItemLabelsVisible(1, true);
}
}catch(Exception e){
System.out.println("Error "+e);
}finally {
try {
if (con != null)
conFac.freeConnection(con);
} catch (Exception e1) {
System.out.println(e1);
}
}
return chart;
}
}
i can't able to display series2 dataset value in chart
Any one explain me how to solve this problem
Need Help Thanks in advance