<%@page import="ChartDirector.*" %> <% //Get the selected year and month int selectedYear = Integer.parseInt(request.getParameter("year")); int selectedMonth = Integer.parseInt(request.getParameter("x")) + 1; //Get the monthly revenue double monthlyRevenue = Double.parseDouble(request.getParameter("value")); // // In this demo, we just split the total revenue into 3 parts using random // numbers. In real life, the data probably can come from a database. // java.util.Random rand = new java.util.Random(selectedMonth * 2000 + selectedYear ); double[] data = new double[3]; data[0] = (rand.nextDouble() * 0.1 + 0.5) * monthlyRevenue; data[1] = (rand.nextDouble() * 0.1 + 0.2) * monthlyRevenue; data[2] = monthlyRevenue - data[0] - data[1]; //The labels for the pie chart String[] labels = {"Services", "Hardware", "Software"}; //Create a PieChart object of size 360 x 260 pixels PieChart c = new PieChart(360, 260); //Set the center of the pie at (180, 140) and the radius to 100 pixels c.setPieSize(180, 130, 100); //Add a title to the pie chart using 13 pts Times Bold Italic font c.addTitle("Revenue Breakdown for " + selectedMonth + "/" + selectedYear, "timesbi.ttf", 13); //Draw the pie in 3D c.set3D(); //Set the pie data and the pie labels c.setData(data, labels); //Create the image and save it in a temporary location request.getSession().setAttribute("chart1", c.makeChart2(Chart.PNG)); //Create an image map for the chart String imageMap = c.getHTMLImageMap("PIESTUB.jsp", "", "title='{label}:USD {value|0}K'"); %> <html> <body> <h1>Simple Clickable Pie Chart</h1> <p><a href="VIEWSOURCE.jsp?file=<%=request.getServletPath()%>"> View Source Code </a></p> <img src="chart1.chart?no_cache=<%=Chart.getUniqueId()%>" border="0" usemap="#map1"> <map name="map1"> <%=imageMap%> </map> </body> </html>