PARETO.jsp 2.66 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
<%@page import="ChartDirector.*" %>
<%
//The data for the chart
double[] data = {40, 15, 7, 5, 2};

//The labels for the chart
String[] labels = {"Hard Disk", "PCB", "Printer", "CDROM", "Keyboard"};

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

//Set the background color of the chart to gold (goldGradient). Use a 2 pixel 3D
//border.
c.setBackground(c.gradientColor(Chart.goldGradient), -1, 2);

//Add a title box using 11 point Arial Bold font. Set the background color to
//blue metallic (blueMetalGradient). Use a 1 pixel 3D border.
c.addTitle("Hardware Defects", "arialbd.ttf", 11).setBackground(c.gradientColor(
    Chart.blueMetalGradient), -1, 1);

//Set the plotarea at (50, 40) and of 300 x 150 pixels in size. Use 0x80ccccff
//as the background color.
c.setPlotArea(50, 40, 300, 150, 0x80ccccff);

//Add a line layer for the pareto line
LineLayer layer = c.addLineLayer();

//Compute the pareto line by accumulating the data
ArrayMath lineData = new ArrayMath(data);
lineData.acc();

//Set a scaling factor such as the maximum point of the line is scaled to 100
double scaleFactor = 100 / lineData.max();

//Add the pareto line using the scaled data. Use deep blue (0x80) as the line
//color, with light blue (0x9999ff) diamond symbols
layer.addDataSet(lineData.mul2(scaleFactor).result(), 0x80).setDataSymbol(
    Chart.DiamondSymbol, 9, 0x9999ff);

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

//Add a multi-color bar layer using the given data. Bind the layer to the
//secondary (right) y-axis.
c.addBarLayer3(data).setUseYAxis2();

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

//Set the primary y-axis scale as 0 - 100 with a tick every 20 units
c.yAxis().setLinearScale(0, 100, 20);

//Set the label format of the y-axis label to include a percentage sign
c.yAxis().setLabelFormat("{value}%");

//Add a title to the secondary y-axis
c.yAxis2().setTitle("Frequency");

//Set the secondary y-axis label foramt to show no decimal point
c.yAxis2().setLabelFormat("{value|0}");

//Set the relationship between the two y-axes, which only differ by a scaling
//factor
c.syncYAxis(1 / scaleFactor);

//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">
    Pareto 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>