<%@page import="ChartDirector.*" %>
<%!
//Utility function to get the real path given a relative URL
String MapPath(HttpServletRequest request, String path)
{
    String realPath = request.getRealPath(request.getServletPath());
    if (realPath == null)
        //some web servers have bugs and real path must be obtained as follows
        realPath = request.getRealPath(request.getRequestURI());
    return new java.io.File(realPath).getParent() + "/" + path;
}
%>
<%
//The data for the area chart
double[] data = {3.0, 2.8, 4.0, 5.5, 7.5, 6.8, 5.4, 6.0, 5.0, 6.2, 7.5, 6.5,
    7.5, 8.1, 6.0, 5.5, 5.3, 3.5, 5.0, 6.6, 5.6, 4.8, 5.2, 6.5, 6.2};

//The labels for the area chart
String[] labels = {"0", "", "", "3", "", "", "6", "", "", "9", "", "", "12", "",
    "", "15", "", "", "18", "", "", "21", "", "", "24"};

//Create a XYChart object of size 300 x 180 pixels. Set the background to pale
//yellow (0xffffa0) with a black border (0x0)
XYChart c = new XYChart(300, 180, 0xffffa0, 0x0);

//Set the plotarea at (45, 35) and of size 240 x 120 pixels. Set the background
//to white (0xffffff). Set both horizontal and vertical grid lines to black
//(&H0&) dotted lines (pattern code 0x0103)
c.setPlotArea(45, 35, 240, 120, 0xffffff, -1, -1, c.dashLineColor(0x0, 0x103),
    c.dashLineColor(0x0, 0x103));

//Add a title to the chart using 10 pts Arial Bold font. Use a 1 x 2 bitmap
//pattern as the background. Set the border to black (0x0).
c.addTitle("Snow Percipitation (Dec 12)", "arialbd.ttf", 10).setBackground(
    c.patternColor(new int[]{0xb0b0f0, 0xe0e0ff}, 2), 0x0);

//Add a title to the y axis
c.yAxis().setTitle("mm per hour");

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

//Add an area layer to the chart
AreaLayer layer = c.addAreaLayer();

//Load a snow pattern from an external file "snow.png".
int snowPattern = c.patternColor(MapPath(request, "snow.png"));

//Add a data set to the area layer using the snow pattern as the fill color. Use
//deep blue (0x0000ff) as the area border line color (&H0000ff&)
layer.addDataSet(data).setDataColor(snowPattern, 0xff);

//Set the line width to 2 pixels to highlight the line
layer.setLineWidth(2);

//output the chart
request.getSession().setAttribute("chart1", c.makeChart2(Chart.PNG));
%>
<html>
<body topmargin=0 leftmargin=5 rightmargin=0 marginwidth=5 marginheight=0>
<div style="font-size:18pt; font-family:verdana; font-weight:bold">
    Pattern Area Chart
</div>
<hr color="#000080">
<div style="font-size:10pt; font-family:verdana">
    <a href="VIEWSOURCE.jsp?file=<%=request.getServletPath()%>">
        View Chart Source Code
    </a>
</div>
<br>
<img src="chart1.chart?no_cache=<%=Chart.getUniqueId()%>">
</body>
</html>