0

I am generating a bar graph in my struts 2 application using JFreeChart; but even if I have enabled the tooltips, they don't work in the bar graph generated. I am not able to figure out how to make the tooltips work? This is my code:

public class ChartAction extends ActionSupport {

private static final long serialVersionUID = 1L;
private JFreeChart chart;

    public JFreeChart getChart() {
    return chart;
}

public String createRBar() throws Exception {
    // chart creation logic..
    System.out.println("IN CHART ACTION");
    try
    {
        BarChart barChart=new BarChart();
        {
            chart=barChart.generateRegionBar();

            return SUCCESS;
        }

    }catch(Exception e)
    {
        e.printStackTrace();
    }
    return "error";

}
}
public class BarChart {

    public JFreeChart generateRegionBar(){
        try{
        DefaultCategoryDataset dataset =new DefaultCategoryDataset();
            dataset.setValue(80, "marks1", "student1");
            dataset.setValue(20, "marks2", "student2");
            dataset.setValue(50, "marks3", "student3");
            dataset.setValue(70, "marks4", "student4");
            JFreeChart chart=ChartFactory.createBarChart("student graph","student name", "student marks",dataset,  PlotOrientation.VERTICAL, true, true, true);
            return chart;
        }catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    }

This is my struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd ">
<struts>        
    <package name="jfree" extends="jfreechart-default">
            <action name="generateRPGraph" class="gr3.jfree.controller.ChartAction"
            method="createRBar">
            <result name="success" type="chart">
                <param name="width">550</param>
                <param name="height">300</param>
            </result>
        </action>
    </package>

</struts>
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
user2077648
  • 951
  • 7
  • 27
  • 42

1 Answers1

1

Tooltips are a feature of Swing JComponent; support is available to charts displayed in a ChartPanel, a subclass of JPanel. In a client-server environment, consider these alternatives:

  • CategoryItemLabelGenerator, seen here.

  • Java Web Start, suggested here.

  • ImageMapUtilities for creating an HTML image map.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Could you suggest me some url or sample code for ImageMapUtilities for creating an HTML image map. – user2077648 Mar 19 '13 at 05:11
  • I included it for completeness, but I've not used it myself; I've only read about it [here](http://www.jfree.org/forum/search.php?keywords=%2BImageMapUtilities+%2Bguide). – trashgod Mar 19 '13 at 10:21