【问题标题】:Tooltips not working in jfree chart in struts 2工具提示在 struts 2 中的 jfree 图表中不起作用
【发布时间】:2013-03-18 03:36:13
【问题描述】:

我正在使用 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>

【问题讨论】:

    标签: java struts2 jfreechart


    【解决方案1】:

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

    • CategoryItemLabelGenerator,见过here

    • Java Web Start,建议here

    • ImageMapUtilities 用于创建 HTML 图像映射。

    【讨论】:

    • 你能给我一些用于创建 HTML 图像地图的 ImageMapUtilities 的 URL 或示例代码吗?
    • 为了完整起见,我将其包含在内,但我自己没有使用过;我只读过here
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    • 2020-08-09
    • 2016-06-22
    • 2015-07-12
    相关资源
    最近更新 更多