Monday, May 9, 2011

Creating Cartesian Plane

This example show how to create a Cartesian coordinate plane. Extract from Protovis example page : http://vis.stanford.edu/protovis/ex/dot.html.


<script type="text/javascript+protovis"
/* Sizing and scales. */
var w = 400,
    h = 400,
    x = pv.Scale.linear(099).range(0, w),
    y = pv.Scale.linear(01).range(0, h),
    c = pv.Scale.log(1100).range("orange""brown");

/* The root panel. */
var vis = new pv.Panel()
    .width(w)
    .height(h)
    .bottom(20)
    .left(20)
    .right(10)
    .top(5);

/* Y-axis and ticks. */
vis.add(pv.Rule)
    .data(y.ticks())
    .bottom(y)
    .strokeStyle(function(d) d ? "#eee" : "#000")
    .anchor("left").add(pv.Label)
    .visible(function(d) d > 0 && d < 1)
    .text(y.tickFormat);

/* X-axis and ticks. */
vis.add(pv.Rule)
    .data(x.ticks())
    .left(x)
    .strokeStyle(function(d) d ? "#eee" : "#000")
    .anchor("bottom").add(pv.Label)
    .visible(function(d) d > 0 && d < 100)
    .text(x.tickFormat);

vis.render();
</script>

Cartesian Plane


No comments:

Post a Comment