Javascript jqplot replot不工作

Javascript jqplot replot不工作,javascript,jquery,jqplot,Javascript,Jquery,Jqplot,我正在尝试回复我的jqplot图表 $(document).ready(function(){ var dataseries = [[[10,20]]]; var plot = $.jqplot('placeholder', dataseries , { title:'<%= @question.text%>', axes:{ yaxis:{min:-100, max:100, tickInterval:10, showTic

我正在尝试回复我的jqplot图表

$(document).ready(function(){

var dataseries = [[[10,20]]];

 var plot = $.jqplot('placeholder', dataseries ,
        { title:'<%= @question.text%>',
          axes:{
        yaxis:{min:-100, max:100, tickInterval:10, showTicks:true, label:"<%=@question.ylabel1%>"},
        xaxis:{min:-100, max:100, tickInterval:10, showTicks:true, label: "<%=@question.xlabel1%>"},
        y2axis:{min:-100, max:100, tickInterval:10, showTicks:true, label:"<%=@question.ylabel2%>", show:true},
        x2axis:{min:-100, max:100, tickInterval:10, showTicks:true, label:"<%=@question.xlabel2%>", show:true}},

          seriesDefaults:{showLine:false},
          series:<%=itemNames.html_safe%>,
          highlighter:{
        show:true,
        tooltipContentEditor:tooltipContentEditor}

        });
});

function tooltipContentEditor(str, seriesIndex, pointIndex, plot) {
    return plot.series[seriesIndex]["label"];
}


$("#placeholder").bind("jqplotClick", function(ev, gridpos, datapos, neighbor) {

    var x = Math.round(datapos.xaxis);
        var y = Math.round(datapos.yaxis);
      var item = $('li.item_button_selected').attr('id');
      if (item > 0){
        var requestObj = {
          question_id: "<%=@question.id%>",
          user_id: "1",     
        }
        requestObj["item_id"]=item
        requestObj["x"]=x
        requestObj["y"]=y
            plot.series[0].data = [[50,50]];
            plot.replot();

BLAH BLAH BLAH...
$(文档).ready(函数(){
var数据系列=[[10,20]];
变量绘图=$.jqplot('占位符',数据系列,
{标题:'',
轴线:{
yaxis:{min:-100,max:100,滴答声间隔:10,showTicks:true,标签:'},
xaxis:{min:-100,max:100,滴答声间隔:10,showTicks:true,标签:'},
y2axis:{min:-100,max:100,滴答声间隔:10,显示滴答声:真,标签:,,显示:真},
X2轴:{min:-100,max:100,滴答声间隔:10,显示滴答声:真,标签:,,显示:真},
序列默认值:{showLine:false},
系列:,
荧光灯:{
秀:没错,
tooltipContentEditor:tooltipContentEditor}
});
});
函数tooltipContentEditor(str、seriesIndex、pointIndex、plot){
返回绘图系列[系列索引][“标签”];
}
$(“#占位符”).bind(“jqplotClick”,函数(ev、gridpos、datapos、neighbor){
var x=数学圆(datapos.xaxis);
变量y=数学圆(数据位置yaxis);
var item=$('li.item_按钮_选定').attr('id');
如果(项目>0){
var requestObj={
问题:",,
用户id:“1”,
}
requestObj[“item_id”]=item
requestObj[“x”]=x
requestObj[“y”]=y
plot.series[0]。数据=[[50,50]];
plot.replot();
废话废话。。。
通常是这样的:[{标签:“威诺娜·莱德”},{标签:“帕里斯·希尔顿”},{标签:“玛格丽特·撒切尔”},{标签:“斯努基”},{标签:“娜塔莉·波特曼”},]


当页面加载时,图表绘制得很好;当我单击图表时,什么也没有发生。我知道单击被捕获;如果我在其中放置了警报,我会看到它。帮助!

好的,解决了。我需要将“plot”变量声明为$(文档)之外的全局变量。就绪(函数()…现在它工作了!

好的,算出了。我需要将“plot”变量声明为$(document).ready(function()…现在它工作了!

我建议您将事件处理程序放入
$(document).ready()
中,这是您发布内容的必然结果

我想回答的主要原因是要注意,既然我们正在使用jQuery,为什么不将其“附加”到jQuery元素

$('placeholder').jqplot(data, options);
现在情节变成:

$('placeholder').data('jqplot');
因此,您可以用以下内容来回答此示例:

$('placeholder').data('jqplot').series[0].data = [[50,50]];    
$('placeholder').data('jqplot').replot();

我建议您将事件处理程序也放在
$(document).ready()
中——这是您发布内容的必然结果

我想回答的主要原因是要注意,既然我们正在使用jQuery,为什么不将其“附加”到jQuery元素

$('placeholder').jqplot(data, options);
现在情节变成:

$('placeholder').data('jqplot');
因此,您可以用以下内容来回答此示例:

$('placeholder').data('jqplot').series[0].data = [[50,50]];    
$('placeholder').data('jqplot').replot();