Wednesday, May 25, 2011

pv.scale.Ordinal & split function


pv.scale.Ordinal represents an ordinal scale. An ordinal scale represents a pairwise mapping from n discrete values in the input domain to n discrete values in the output range.

pv.Scale.ordinal generate a pair mapping function from input domain to output range
split(min, max) function

Sets the range from the given continuous interval. The interval [min, max] is subdivided into n equispaced points, where n is the number of (unique) values in the domain. The first and last point are offset from the edge of the range by half the distance between points.

This method must be called after the domain is set.

pv.Scale.ordinal("ABCDE".split("")).split(0, 500)


Sample Code :

<html>
<head>
<script type="text/javascript"  src="protovis-r3.2.js"></script>
<title>pv.Scale.ordinal</title>
</head>
<body>
<div id="pesan">
</div>
<script type="text/javascript+protovis"
    var ordinalidx = "ABCDE".split("");
    var x = pv.Scale.ordinal(ordinalidx).split(0500);

    document.getElementById("pesan").innerHTML 
        += "ordinalidx = " + ordinalidx + "<BR />";
    document.getElementById("pesan").innerHTML 
        += "x['A'] = " + x('A') + "<BR />";
    document.getElementById("pesan").innerHTML 
        += "x['B'] = " + x('B') + "<BR />";
    document.getElementById("pesan").innerHTML 
        += "x['C'] = " + x('C') + "<BR />";
    document.getElementById("pesan").innerHTML 
        += "x['D'] = " + x('D') + "<BR />";
    document.getElementById("pesan").innerHTML 
        += "x['E'] = " + x('E') + "<BR />";
</script>
</body>
</html>


Result :

ordinalidx = A,B,C,D,E
x['A'] = 50
x['B'] = 150
x['C'] = 250
x['D'] = 350
x['E'] = 450


No comments:

Post a Comment