首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >protovis更新数据

protovis更新数据
EN

Stack Overflow用户
提问于 2011-04-05 04:18:17
回答 2查看 857关注 0票数 1

我已经尝试了很多次使用jquery来更新协议,但是什么也没有发生。这是我的代码。

代码语言:javascript
复制
<script type="text/javascript+protovis">
var minnesota =  [{name:"job 1", values:[182904,196530,203944,192492,77393,81243]}]

$(document).ready(function(){
draw();
$("button").click(function(){
minnesota = [{name:"changed job", values:[342,34234,2342,543]}]
draw();
});

});



    function draw(){
    var w = 200,
        h = 30,
        numberFormat = pv.Format.number(),
        dateFormat = pv.Format.date("%B %Y");

    /* Color by maximum number of people employed in that job. */
    var c = pv.Scale.log(minnesota, function(d) pv.max(d.values))
        .range("#ccc", "#1f77b4");

    /* Tile the visualization for each job. */
    var vis = new pv.Panel()
        .data(minnesota)
        .width(w)
        .height(h + 10)
        .top(6)
        .left(6)
        .right(6)
        .bottom(6);

    /* A panel instance to store scales (x, y) and the mouseover index (i). */
    var panel = vis.add(pv.Panel)
        .def("i", -1)
        .def("x", function(d) pv.Scale.linear(d.values, pv.index).range(0, w))
        .def("y", function(d) pv.Scale.linear(0, pv.max(d.values)).range(0, h))
        .bottom(10)
        .events("all")
        .event("mousemove", pv.Behavior.point(Infinity).collapse("y"));

    /* The area. */
    panel.add(pv.Area)
        .data(function(d) d.values)
        .fillStyle(function(d, p) panel.i() < 0 ? c(pv.max(p.values)) : "#2ca02c")
        .left(function() panel.x()(this.index))
        .height(function(d) panel.y()(d))
        .bottom(0)
        .event("point", function() panel.i(this.index))
        .event("unpoint", function() panel.i(-1));

    /* The x-axis. */
    panel.add(pv.Rule)
        .bottom(0);

    /* The mouseover dot. */
    panel.add(pv.Dot)
        .visible(function() panel.i() >= 0)
        .left(function() panel.x()(panel.i()))
        .bottom(function(d) panel.y()(d.values[panel.i()]))
        .fillStyle("#ff7f0e")
        .strokeStyle(null)
        .size(10);

    /* The label: either the job name, or the month and value. */
    panel.add(pv.Label)
        .bottom(-1)
        .textBaseline("top")
        .left(function() panel.i() < 0 ? 0 : null)
        .right(function() panel.i() < 0 ? null : 0)
        .textAlign(function() panel.i() < 0 ? "left" : "right")
        .textStyle(function() panel.i() < 0 ? "#999" : "#000")
        .text(function(d) panel.i() < 0 ? d.name
            : dateFormat(new Date(2000, panel.i() * 3, 1))
            + ": " + numberFormat(d.values[panel.i()]));

    vis.render();
    }
        </script>

当文档准备就绪时,它会创建图表,但当我单击按钮时,它不会重新绘制图表。我已经用firebug检查了新的数据值,这很好,但它不会更新图表的值。我试了很久才找到解决方案,但没能成功。有什么窍门吗?

EN

回答 2

Stack Overflow用户

发布于 2011-04-07 02:48:03

对我来说,您的解决方案绘制了一个额外的图表,而不是使用新数据重新绘制相同的图表。

我在您的代码中移动了一些东西,并使更新生效。您只需更新数据并调用vis.redraw,而不是在每次单击时设置整个可视化。

查看:https://gist.github.com/906247

票数 0
EN

Stack Overflow用户

发布于 2011-04-30 07:13:30

我只是在更改数据的每个函数的末尾使用vis.render();

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5543859

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档