JfreeChart Buffered Image not showing tool tip

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
rahulkoppati
Posts: 1
Joined: Tue May 05, 2015 8:12 pm
antibot: No, of course not.

JfreeChart Buffered Image not showing tool tip

Post by rahulkoppati » Tue May 05, 2015 8:21 pm

Hi I have a requirement where I need to display a line chart, along with table containing information.
I am sending image to the frontend as en encoded string. I am able to display image, but no tooltips are coming. I highlighted part of code for reference. Am I doing it the right way?


@Controller
@RequestMapping("/forecastReports/BodHistogram.do")
public class BodHistogramController {




@Autowired
private BodHistogramService bodHistogramService;

//Initialize Values and render form
@RequestMapping(method=RequestMethod.GET)
public String initBodHistogramHome(ModelMap model){
System.out.println(" Changess ");
BodHistogramBean bodBean = new BodHistogramBean();
bodBean = bodHistogramService.initializeBodHistForm();
bodBean.setFormSubmitFlag(0);
model.addAttribute("bodBean",bodBean);
return "bodHistogram";
}

// Get the input values and send values to the front end
@RequestMapping(method=RequestMethod.POST)
public String submitBodHistogramForm(@ModelAttribute("bodBean") BodHistogramBean bodBean,
ModelMap model,
BindingResult result,
HttpServletRequest request
){
BodHistogramBean bodBeanOne = bodHistogramService.initializeBodHistForm();
bodBeanOne.setStartDate(bodBean.getStartDate());
bodBeanOne.setEndDate(bodBean.getEndDate());
bodBeanOne.setBodNamesSelected(bodBean.getBodNamesSelected());

// Format the dates recieved in MMMM yyyy to yyyy MM
bodBean.setStartDate(this.formatDate(bodBean.getStartDate()));
bodBean.setEndDate(this.formatDate(bodBean.getEndDate()));
System.out.println(" BOD Names received " + bodBean.getBodNamesSelected());

System.out.println(" Bod Unit " + bodBean.getUnitOfMeasureSelected());
bodBeanOne.setMarketSelected(bodBean.getMarketSelected());
bodBeanOne.setTechSelected(bodBean.getTechSelected());
bodBeanOne.setUnitOfMeasureSelected(bodBean.getUnitOfMeasureSelected());
bodBeanOne.setFormSubmitFlag(1);
// Get BOD Names from temporary string and set to BODNames array List
bodBean.setBodNameList(Arrays.asList(bodBean.getBodNamesSelected().split(";")));
bodBeanOne.setDataSetList(bodHistogramService.getBodDataSetList(bodBean));


try{
XYDataset bodXyDataSet = this.getDataSets(bodBeanOne.getDataSetList(), bodBean.getBodNameList());
JFreeChart chart = this.createChart(bodXyDataSet);
//Pseudo Code

//ImageUtility is class that contain code for converting bufferedimage to string
bodBeanOne.setBodImage(ImageUtility.encodeToString( chart.createBufferedImage(1000, 500), "png" ));
} catch(Exception e){
e.printStackTrace();
}
System.out.println(" BOD Bean " + bodBeanOne.getBodImage());
model.addAttribute("bodBean",bodBeanOne);
return "bodHistogram";
}


private XYDataset getDataSets(List<BodDataSetBean> bodDataSetList, List<String> bodList ){
TimeSeriesCollection xyTimeSeriesCollection = new TimeSeriesCollection();
TimeSeries bodSeries1 = new TimeSeries(bodList.get(0));
TimeSeries bodSeries2 = new TimeSeries(bodList.get(1));
TimeSeries bodSeries3 = new TimeSeries(bodList.get(2));

Iterator<BodDataSetBean> bodIterator = bodDataSetList.iterator();
while(bodIterator.hasNext()){
BodDataSetBean bodBean = bodIterator.next();
Month month = this.convertToDate(bodBean.getMonthYear());
System.out.println(" Month " + month);
System.out.println(" Value 1 " + bodBean.getBodOneValue());
bodSeries1.add(month,bodBean.getBodOneValue());
bodSeries2.add(month,bodBean.getBodTwoValue());
bodSeries3.add(month,bodBean.getBodThreeValue());


}


xyTimeSeriesCollection.addSeries(bodSeries1);
xyTimeSeriesCollection.addSeries(bodSeries2);
xyTimeSeriesCollection.addSeries(bodSeries3);
return xyTimeSeriesCollection;
}

@SuppressWarnings("deprecation")
private JFreeChart createChart(final XYDataset dataset) {

// create the chart...
JFreeChart chart = ChartFactory.createTimeSeriesChart("BOD Histogram",
"Data_Month",
"Data Volume",
dataset,
true,
true,
false);


// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
chart.setBackgroundPaint(Color.white);

// final StandardLegend legend = (StandardLegend) chart.getLegend();
// legend.setDisplaySeriesShapes(true);

// get a reference to the plot for further customisation...
final XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.white);
// plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
plot.setDomainGridlinePaint(Color.WHITE);
plot.setRangeGridlinePaint(Color.black);

final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
renderer.setSeriesShapesVisible(0, false);
renderer.setSeriesShapesVisible(1, false);
// renderer.setSeriesShapesVisible(2, false);



// Set Domain or X Axis
DateAxis xAxis = (DateAxis) plot.getDomainAxis();
xAxis.setDateFormatOverride(new SimpleDateFormat("MMM-yy"));
xAxis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1));
plot.getDomainAxis().setVerticalTickLabels(true);
final StandardXYToolTipGenerator g = new StandardXYToolTipGenerator(
StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
new SimpleDateFormat("MMMM yyyy"), NumberFormat.getInstance()
);
renderer.setToolTipGenerator(g);



plot.setRenderer(renderer);

// change the auto tick unit selection to integer units only...
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// OPTIONAL CUSTOMISATION COMPLETED.

return chart;

}

private Month convertToDate(String inputDate){

System.out.println(" input Date " + inputDate);

DateFormat format = new SimpleDateFormat("MMM-yy");
Date date = null;
try {
date = format.parse(inputDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(" Date " + date);
Month month = new Month(date);
return month;
}

private String formatDate(String inputDate){


DateFormat format = new SimpleDateFormat("MMMM yyyy");
SimpleDateFormat newFormat = new SimpleDateFormat("yyyyMM");
Date date = null;
try {
date = format.parse(inputDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(" Date " + date);

return newFormat.format(date);
}

}

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: JfreeChart Buffered Image not showing tool tip

Post by paradoxoff » Tue May 05, 2015 9:44 pm

All I can advice is to look for the key word "ImageMap".

Locked