0

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

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>
4

1 回答 1

1

工具提示是 Swing 的一个特性JComponent;支持可用于显示在 a 中的图表ChartPanel,a 的子类JPanel。在客户端-服务器环境中,请考虑以下替代方案:

于 2013-03-18T11:57:14.683 回答