CLICKBAR.jsp 1.46 KB
Newer Older
Thitichaipun Wutthisak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
<%@page import="ChartDirector.*" %>
<%
//
//For demo purpose, we use hard coded data. In real life, the following data
//could come from a database.
//
double[] revenue = {4500, 5600, 6300, 8000, 12000, 14000, 16000, 20000, 24000,
    28000};
String[] labels = {"1992", "1993", "1994", "1995", "1996", "1997", "1998",
    "1999", "2000", "2001"};

//Create a XYChart object of size 450 x 200 pixels
XYChart c = new XYChart(450, 200);

//Add a title to the chart using Times Bold Italic font
c.addTitle("Annual Revenue for Star Tech", "timesbi.ttf");

//Set the plotarea at (60, 25) and of size 350 x 150 pixels
c.setPlotArea(60, 25, 350, 150);

//Add a blue (0x3333cc) bar chart layer using the given data. Set the bar border
//to 1 pixel 3D style.
c.addBarLayer(revenue, 0x3333cc, "Revenue").setBorderColor(-1, 1);

//Set x axis labels using the given labels
c.xAxis().setLabels(labels);

//Add a title to the y axis
c.yAxis().setTitle("USD (K)");

//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("CLICKLINE.jsp", "",
    "title='{xLabel}: USD {value|0}K'");
%>

<html>
<body>
<h1>Simple Clickable Bar 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>