当鼠标悬停在图表上时,使用Jfreechart的动态饼图未显示特定区域百分比

时间:2015-01-21 13:24:29

标签: java jfreechart

我使用Jfreechart成功开发了动态饼图。我关注的是,当我超过鼠标特定区域时,我想看看该区域中munch百分比的占用情况。这是我的代码。

    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartRenderingInfo;
    import org.jfree.chart.ChartUtilities;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.entity.StandardEntityCollection;
    import org.jfree.data.jdbc.JDBCPieDataset;

    public class PieChartDemo extends HttpServlet {

        private static final long serialVersionUID = 1L;

        protected void doGet(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
            String connectionUrl = "jdbc:sqlserver://localhost:1433;"
                    + "databaseName=mydb;user=madhu;password=*****";
            Connection connection = null;
            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
                        .newInstance();
                try {
                    connection = DriverManager.getConnection(connectionUrl);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            JDBCPieDataset dataset = new JDBCPieDataset(connection);
            try {
                dataset.executeQuery("Select country,employes From CompanyDetails order by cid ");
                JFreeChart chart = ChartFactory.createPieChart("Employes Chart", dataset, true, true, false);
                chart.setBorderPaint(Color.black);

                chart.setBorderStroke(new BasicStroke(10.0f));
                chart.setBorderVisible(true);


                if (chart != null) {
                    int width = 500;
                    int height = 350;
                    final ChartRenderingInfo info = new ChartRenderingInfo(
                            new StandardEntityCollection());
                    response.setContentType("image/png");
                    OutputStream out = response.getOutputStream();
                    ChartUtilities.writeChartAsPNG(out, chart, width, height, info);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        protected void doPost(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
        }
    }

我的输出是:

enter image description here

这是我的数据库表。

enter image description here

0 个答案:

没有答案