Tool tip not shown in the graph
Tool tip not shown in the graph
Hi All,
In my graph, I cant see the tooltip when I take the mouse the line series. Can you help me out in this.
The code is below
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
chartTitle, // Chart Title
domainLabel, // X-Axis Label
unit, // Y-Axis Label
dataset, // Dataset
true, // Show Legend
true, // Show Tooltip
false); // URL
chart.setBackgroundPaint(Color.white);
XYPlot plot = (XYPlot) chart.getPlot();
DateAxis dateAxis = (DateAxis)plot.getDomainAxis();
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
XYItemRenderer renderer = plot.getRenderer();
Color[] color = new Color[]{new Color(0,0,153), new Color(255,0,204), new Color(0,102,0), new Color(255,0,0), new Color(0,0,0), new Color(102,0,0), new Color(153,0,51)};
LegendItemCollection chartLegend = new LegendItemCollection();
Shape shape = new Rectangle(10, 10);
int arraySize = fieldsArray.length;
for(int i=0; i<arraySize; i++){
renderer.setSeriesPaint(i, color);
renderer.setSeriesStroke(i, new BasicStroke(1.0f));
chartLegend.add(new LegendItem(fieldsArray, null, null, null, shape, color));
}
plot.setFixedLegendItems(chartLegend);
TickUnitSource tickUnits = createDateTickUnits(TimeZone.getDefault(),type);
dateAxis.setStandardTickUnits(tickUnits);
return chart;
Thanks in advance for any assistance.
Regards,
Narayan
In my graph, I cant see the tooltip when I take the mouse the line series. Can you help me out in this.
The code is below
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
chartTitle, // Chart Title
domainLabel, // X-Axis Label
unit, // Y-Axis Label
dataset, // Dataset
true, // Show Legend
true, // Show Tooltip
false); // URL
chart.setBackgroundPaint(Color.white);
XYPlot plot = (XYPlot) chart.getPlot();
DateAxis dateAxis = (DateAxis)plot.getDomainAxis();
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
XYItemRenderer renderer = plot.getRenderer();
Color[] color = new Color[]{new Color(0,0,153), new Color(255,0,204), new Color(0,102,0), new Color(255,0,0), new Color(0,0,0), new Color(102,0,0), new Color(153,0,51)};
LegendItemCollection chartLegend = new LegendItemCollection();
Shape shape = new Rectangle(10, 10);
int arraySize = fieldsArray.length;
for(int i=0; i<arraySize; i++){
renderer.setSeriesPaint(i, color);
renderer.setSeriesStroke(i, new BasicStroke(1.0f));
chartLegend.add(new LegendItem(fieldsArray, null, null, null, shape, color));
}
plot.setFixedLegendItems(chartLegend);
TickUnitSource tickUnits = createDateTickUnits(TimeZone.getDefault(),type);
dateAxis.setStandardTickUnits(tickUnits);
return chart;
Thanks in advance for any assistance.
Regards,
Narayan
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
I can't see any reason why that won't work. Of course, if you'd posted a small self-contained demo, I could have run it and actually tried it out.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Hi Dave, I appreciate your quick response.
Here is the sample self running code for the timrseries chart. Can you please let me know what can I do to get the tooltip for the graph.
import java.awt.Color;
import java.awt.Dimension;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class SecondLineChart extends ApplicationFrame{
private String chartTitle;
public SecondLineChart(String title){
super(title);
chartTitle = title;
TimeSeriesCollection dataset = null;
dataset = createDailyDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(550, 250));
setContentPane(chartPanel);
}
private TimeSeriesCollection createDailyDataset(){
TimeSeriesCollection dataset = new TimeSeriesCollection();
TimeSeries [] time = new TimeSeries[2];
Regards,
Narayan
time[0] = new TimeSeries("Pers Msg", Day.class);
time[1] = new TimeSeries("Non Pers Msg", Day.class);
Day day1 = null;
Day day2 = null;
Day day3 = null;
Day day4 = null;
Day day5 = null;
Day day6 = null;
try {
day1 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 12, 2006"));
day2 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 13, 2006"));
day3 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 14, 2006"));
day4 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 15, 2006"));
day5 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 16, 2006"));
day6 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 17, 2006"));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
time[0].add(day1, 12);
time[1].add(day1, 25);
time[0].add(day2, 3242);
time[1].add(day2, 2523);
time[0].add(day3, 1243);
time[1].add(day3, 2534);
time[0].add(day4, 162);
time[1].add(day4, 2345);
time[0].add(day5, 1562);
time[1].add(day5, 235);
time[0].add(day6, 162);
time[1].add(day6, 225);
dataset.addSeries(time[0]);
dataset.addSeries(time[1]);
return dataset;
}
private JFreeChart createChart(final TimeSeriesCollection dataset){
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
chartTitle, // Chart Title
"Date", // X-Axis Label
"Message", // Y-Axis Label
dataset, // Dataset
true, // Show Legend
true, // Show Tooltip
false);
chart.setBackgroundPaint(Color.white);
return chart;
}
public static void main(String [] args){
SecondLineChart chartType = new SecondLineChart("First Line Chart Sample");
chartType.pack();
RefineryUtilities.centerFrameOnScreen(chartType);
chartType.setVisible(true);
}
}
Here is the sample self running code for the timrseries chart. Can you please let me know what can I do to get the tooltip for the graph.
import java.awt.Color;
import java.awt.Dimension;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class SecondLineChart extends ApplicationFrame{
private String chartTitle;
public SecondLineChart(String title){
super(title);
chartTitle = title;
TimeSeriesCollection dataset = null;
dataset = createDailyDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(550, 250));
setContentPane(chartPanel);
}
private TimeSeriesCollection createDailyDataset(){
TimeSeriesCollection dataset = new TimeSeriesCollection();
TimeSeries [] time = new TimeSeries[2];
Regards,
Narayan
time[0] = new TimeSeries("Pers Msg", Day.class);
time[1] = new TimeSeries("Non Pers Msg", Day.class);
Day day1 = null;
Day day2 = null;
Day day3 = null;
Day day4 = null;
Day day5 = null;
Day day6 = null;
try {
day1 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 12, 2006"));
day2 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 13, 2006"));
day3 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 14, 2006"));
day4 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 15, 2006"));
day5 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 16, 2006"));
day6 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 17, 2006"));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
time[0].add(day1, 12);
time[1].add(day1, 25);
time[0].add(day2, 3242);
time[1].add(day2, 2523);
time[0].add(day3, 1243);
time[1].add(day3, 2534);
time[0].add(day4, 162);
time[1].add(day4, 2345);
time[0].add(day5, 1562);
time[1].add(day5, 235);
time[0].add(day6, 162);
time[1].add(day6, 225);
dataset.addSeries(time[0]);
dataset.addSeries(time[1]);
return dataset;
}
private JFreeChart createChart(final TimeSeriesCollection dataset){
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
chartTitle, // Chart Title
"Date", // X-Axis Label
"Message", // Y-Axis Label
dataset, // Dataset
true, // Show Legend
true, // Show Tooltip
false);
chart.setBackgroundPaint(Color.white);
return chart;
}
public static void main(String [] args){
SecondLineChart chartType = new SecondLineChart("First Line Chart Sample");
chartType.pack();
RefineryUtilities.centerFrameOnScreen(chartType);
chartType.setVisible(true);
}
}
Hi All,
I am sorry for giving the wrong piece of code. If I use the chartPanel I get the tooltip.
But my requirement is to set the chart in the response and send it. I have given the piece of the which saves it as PNG. When I do this or when I send it in response, I am not gettig the tooltip. Can you please let me know what has to be done so that I get the tooltip when I send it in the response.
I am sorry for giving the wrong piece of code. If I use the chartPanel I get the tooltip.
But my requirement is to set the chart in the response and send it. I have given the piece of the which saves it as PNG. When I do this or when I send it in response, I am not gettig the tooltip. Can you please let me know what has to be done so that I get the tooltip when I send it in the response.
Code: Select all
import java.awt.Color;
import java.awt.Dimension;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class SecondLineChart extends ApplicationFrame{
private String chartTitle;
public SecondLineChart(String title){
super(title);
chartTitle = title;
TimeSeriesCollection dataset = null;
dataset = createDailyDataset();
final JFreeChart chart = createChart(dataset);
File file1 = new File("E:\\first.png");
try {
ChartUtilities.saveChartAsPNG(file1, chart, 500, 200);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private TimeSeriesCollection createDailyDataset(){
TimeSeriesCollection dataset = new TimeSeriesCollection();
TimeSeries [] time = new TimeSeries[2];
time[0] = new TimeSeries("Pers Msg", Day.class);
time[1] = new TimeSeries("Non Pers Msg", Day.class);
Day day1 = null;
Day day2 = null;
Day day3 = null;
Day day4 = null;
Day day5 = null;
Day day6 = null;
try {
day1 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 12, 2006"));
day2 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 13, 2006"));
day3 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 14, 2006"));
day4 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 15, 2006"));
day5 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 16, 2006"));
day6 = new Day(new SimpleDateFormat("MMM dd, yyyy").parse("Jun 17, 2006"));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
time[0].add(day1, 12);
time[1].add(day1, 25);
time[0].add(day2, 3242);
time[1].add(day2, 2523);
time[0].add(day3, 1243);
time[1].add(day3, 2534);
time[0].add(day4, 162);
time[1].add(day4, 2345);
time[0].add(day5, 1562);
time[1].add(day5, 235);
time[0].add(day6, 162);
time[1].add(day6, 225);
dataset.addSeries(time[0]);
dataset.addSeries(time[1]);
return dataset;
}
private JFreeChart createChart(final TimeSeriesCollection dataset){
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
chartTitle, // Chart Title
"Date", // X-Axis Label
"Message", // Y-Axis Label
dataset, // Dataset
true, // Show Legend
true, // Show Tooltip
false);
chart.setBackgroundPaint(Color.white);
return chart;
}
public static void main(String [] args){
SecondLineChart chartType = new SecondLineChart("First Line Chart Sample");
chartType.pack();
RefineryUtilities.centerFrameOnScreen(chartType);
chartType.setVisible(true);
}
}
-
- Posts: 59
- Joined: Fri Feb 23, 2007 7:41 am
You can retrieve the tooltip information by doing the following.
The imageMap String has the tooltip information.
Regards,
Priya
Code: Select all
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
ChartUtilities.saveChartAsPNG(file1, chart, width, height, info);
String imageMap = ImageMapUtilities.getImageMap("imagemap", info);
Regards,
Priya
Thanks Priya. I appreciate your response.
I got that. But I am facing a strange problem.
My requirement is to draw the chart and then put it directly in the jsp without storing it as a PNG file.
I am calling the chart using the following code.
Now in the action class, I am doing the following.
If I storing it as a image then the code will look
The problem comes because I am not having that file with me on the fly and I shouldnt create any temp file. can I give something else instead of the file name in the src ???
Since I am doing both constructing the chart and the imagemap together, I dont know how can I get the above pattern. [/code]
I got that. But I am facing a strange problem.
My requirement is to draw the chart and then put it directly in the jsp without storing it as a PNG file.
I am calling the chart using the following code.
Code: Select all
//in the src call the action class method to get the chart.
<img id="chart" onerror="javascript:errorChart()" src='actionname.action.generateChart.event' border="0" USEMAP="#imageMap"/>
Code: Select all
final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
OutputStream out = response.getOutputStream();
response.setContentType("image/png");
//get the chart
chart = chartHelper.drawChart(statsContext);
//write the chart as PNG
ChartUtilities.writeChartAsPNG(out, chart, 650, 220, info);
//Write the image map and put to same outputstream.
ChartUtilities.writeImageMap(new PrintWriter(out), "imageMap", info, false);
Code: Select all
<map id="imageMap" name="imageMap">
.......
</map>
<img src="chart.png" usemap="#imageMap"/>
Since I am doing both constructing the chart and the imagemap together, I dont know how can I get the above pattern. [/code]
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
A workaround would be to draw the chart twice, once to get the image map and again to stream the image bytes to the client.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Thanks Dave.
I got the answer. I got to fine tune it though.
My jsp will now look like this.
I have 2 hits to the backend.
In the first hit, I am doing the following.
and the second hit will be to the following.
I got the answer. I got to fine tune it though.
My jsp will now look like this.
Code: Select all
<%
//here the call to the chart is made
out.println((String)action.getImageMap(request, response));
%>
//src will make the second hit to chart
<img id="chart" onerror="javascript:errorChart()" src="ActionName.action.generateChart.event" border="0"
USEMAP="#imageMap">
In the first hit, I am doing the following.
Code: Select all
ChartHelper chartHelper = new ChartHelper();
//get the chart
chart = chartHelper.drawChart(statsContext);
//get the rendering info
final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
ByteArrayOutputStream out1 = new ByteArrayOutputStream();
//write the chart.
ChartUtilities.writeChartAsPNG(out1, chart, 650, 220, info);
//get the image map
imageMap = ImageMapUtilities.getImageMap("imageMap", info);
//save the chart as a session attribute
session.setAttribute("chart", chart);
return imageMap;
Code: Select all
//set the response type to png
response.setContentType("image/png");
//get the output stream
OutputStream out = response.getOutputStream();
//get the chart object from the session.
JFreeChart chart = (JFreeChart)session.getAttribute("chart");
//remove chart object from the session
session.removeAttribute("chart");
//get the rendering info
final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
//get the png image
ChartUtilities.writeChartAsPNG(out, chart, 650, 220, info);
return null;
Hi Dave,
I am doing the way you had told me, once getting the imageMap and then getting the chart.
But the problem is that if there are lots of records, the chart is not displayed fully, also in the page, some components of the page like left navigation bar will be missing. Can you please tell me how can I have the smooth rendering
Regards,
Narayan
I am doing the way you had told me, once getting the imageMap and then getting the chart.
But the problem is that if there are lots of records, the chart is not displayed fully, also in the page, some components of the page like left navigation bar will be missing. Can you please tell me how can I have the smooth rendering
Regards,
Narayan
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
No I can't, because I have very little information about what you've done. And if I *did* have that information, I'm guessing there would be a few hours of debugging and analysis to figure out what is going wrong...time that I can't afford to spend solving your problem.Narayan wrote:But the problem is that if there are lots of records, the chart is not displayed fully, also in the page, some components of the page like left navigation bar will be missing. Can you please tell me how can I have the smooth rendering
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

