工具提示不在struts 2中的jfree图表中工作

时间:2013-03-18 03:36:13

标签: java struts2 jfreechart

我使用JFreeChart在我的struts 2应用程序中生成条形图;但即使我启用了工具提示,它们也无法在生成的条形图中工作。我无法弄清楚如何使工具提示工作?这是我的代码:

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;
        }
    }
    }

这是我的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>

1 个答案:

答案 0 :(得分:1)

工具提示是Swing JComponent的一项功能;支持可用于显示在ChartPanel中的图表,JPanelCategoryItemLabelGenerator的子类。在客户端 - 服务器环境中,请考虑以下备选方案: