0

I am developed dynamic pie chart using Jfreechart successfully.Here my concern is when i over the mouse particular area i want see how munch percentage occupy in that area.This is my code.

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

My output is :

enter image description here

This is my database Table.

enter image description here

madhu
  • 1,083
  • 3
  • 12
  • 31
  • You might want to take a look at the lines that say `dataset.executeQuery("Select country,employes From CompanyDetails order by cid "); JFreeChart chart = ChartFactory.createPieChart("Employes Chart", dataset, true, true, false);` – frasnian Jan 21 '15 at 13:26
  • thanks for your comment.I looked but i cont find any solution. – madhu Jan 21 '15 at 13:29
  • 1
    Tooltips won't work in a static image. Can you use labels, as shown [here](http://stackoverflow.com/q/3547244/230513)? – trashgod Jan 21 '15 at 19:58

0 Answers0