<%@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;
}
%>
<%!
void createChart(HttpServletRequest request, String img)
{
    //The data for the chart
    double[] data = {85, 156, 179.5, 211, 123};
    String[] labels = {"Mon", "Tue", "Wed", "Thu", "Fri"};

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

    //Set the plot area at (40, 32) and of size 200 x 200 pixels
    PlotArea plotarea = c.setPlotArea(40, 32, 200, 200);

    //Set the background style based on the input parameter
    if (img.equals("0")) {
        //Has wallpaper image
        c.setWallpaper(MapPath(request, "tile.gif"));
    } else if (img.equals("1")) {
        //Use a background image as the plot area background
        plotarea.setBackground2(MapPath(request, "bg.png"));
    } else if (img.equals("2")) {
        //Use white (0xffffff) and grey (0xe0e0e0) as two alternate plotarea
        //background colors
        plotarea.setBackground(0xffffff, 0xe0e0e0);
    } else {
        //Use a dark background palette
        c.setColors(Chart.whiteOnBlackPalette);
    }

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

    //Add a color bar layer using the given data. Use a 1 pixel 3D border for
    //the bars.
    c.addBarLayer3(data).setBorderColor(-1, 1);

    //output the chart
    request.getSession().setAttribute("chart" + img, c.makeChart2(Chart.PNG));
}
%>
<%
createChart(request, "0");
createChart(request, "1");
createChart(request, "2");
createChart(request, "3");
%>
<html>
<body topmargin=0 leftmargin=5 rightmargin=0 marginwidth=5 marginheight=0>
<div style="font-size:18pt; font-family:verdana; font-weight:bold">
    Background and Wallpaper
</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="chart0.chart?no_cache=<%=Chart.getUniqueId()%>">
<img src="chart1.chart?no_cache=<%=Chart.getUniqueId()%>">
<img src="chart2.chart?no_cache=<%=Chart.getUniqueId()%>">
<img src="chart3.chart?no_cache=<%=Chart.getUniqueId()%>">
</body>
</html>