• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

how to write dataset value in chart using CategoryItemRenderer

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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




 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Siva, could you please go back and edit your post with code tags? e.g. UseCodeTags It makes it easier for us to help you
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!