While protovis has the convenience support for evaluating
javascript+protovis scripts inline (using the braceless 1.8 javascript
syntax), you can call protovis functions normally if you avoid the 1.8
syntax. Here's an example (this is extracted from a web page, so it
may need some tweaking to work):
// Using jQuery's dom:ready but should work with any framework
$(function(){
// Data defined statically but could be pulled in via AJAX
var data = [
{value:10, label:'New'},
{value:20, label:'Existing'}
];
// Draw the chart into targetElem
var w = 200,
h = 200,
r = w / 2,
max = pv.sum(data, function(d){ return d.value; }),
a = pv.Scale.linear(0, max).range(0, 2 * Math.PI);
var vis = new pv.Panel()
.canvas('targetElem')
.width(w)
.height(h);
vis.add(pv.Wedge)
.data(data)
.outerRadius(r)
.angle(function(d) { return a(d.value); })
.title(function(d) { return d.value; })
.add(pv.Wedge) // invisible wedge to offset label
.visible(function(d) { return d.value > 0.15; })
.innerRadius(0.25 * r)
.outerRadius(0.75 * r)
.fillStyle(null)
.anchor("center").add(pv.Label)
.textAngle(0)
.text(function(d) { return d.label; });
vis.render();
})
At minimum for refresh, you should be able to redraw the entire chart,
although I suspect there's a more efficient way to do it.
Hope that helps,
Chris Hunter
> --
> You received this message because you are subscribed to the Google Groups "protovis" group.
> To post to this group, send email to prot...@googlegroups.com.
> To unsubscribe from this group, send email to protovis+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/protovis?hl=en.
>
>
It's not exactly passing it to the constructor but you can use a call
to the 'canvas'
method to specify a DOM element as the container. From my example:
var vis = new pv.Panel()
.canvas('targetElem')
'targetElem' is the id of a div nested in my page's DOM.
> I'm looking at using protovis for a dashboard and it's a major hack to
> workaround how the charts are positioned right now. I don't want to
> write out a script for every chart -- I want to have a chart making
> template, and feed it data as the charts arrive and have the charts
> end up in the right position. I can work around that by overriding
> the $dom before rendering the chart and creating a phony child element
> (instead of a script tag) inside of the my desired target container...
> but, this isn't really a clean way of doing things. :)
You shouldn't have to be doing this. I'm using code very much like that
from my original response, wrapped in a utility function that takes a
data argument,
element, width and height. Then you just make multiple calls to that
function on page load
(or whenever your data is ready).
Does that make more sense?
--Chris