javascript - jqplot replot not working - Stack Overflow

I am trying to replot my jqplot chart.$(document).ready(function(){var dataseries = [[[10,20]]];var plo

I am trying to replot my jqplot chart.

$(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:"<%[email protected]%>"},
        xaxis:{min:-100, max:100, tickInterval:10, showTicks:true, label: "<%[email protected]%>"},
        y2axis:{min:-100, max:100, tickInterval:10, showTicks:true, label:"<%[email protected]%>", show:true},
        x2axis:{min:-100, max:100, tickInterval:10, showTicks:true, label:"<%[email protected]%>", 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: "<%[email protected]%>",
          user_id: "1",     
        }
        requestObj["item_id"]=item
        requestObj["x"]=x
        requestObj["y"]=y
            plot.series[0].data = [[50,50]];
            plot.replot();

BLAH BLAH BLAH...

<%=itemNames.html_safe%> typically looks like this: [{label:"Winona Ryder"},{label:"Paris Hilton"},{label:"Margaret Thatcher"},{label:"Snooki"},{label:"Natalie Portman"},]

The chart draws fine when the page loads; when I click on the chart, nothing happens. I know the click is being caught; if I put an alert in there, I see it. Help!

I am trying to replot my jqplot chart.

$(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:"<%[email protected]%>"},
        xaxis:{min:-100, max:100, tickInterval:10, showTicks:true, label: "<%[email protected]%>"},
        y2axis:{min:-100, max:100, tickInterval:10, showTicks:true, label:"<%[email protected]%>", show:true},
        x2axis:{min:-100, max:100, tickInterval:10, showTicks:true, label:"<%[email protected]%>", 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: "<%[email protected]%>",
          user_id: "1",     
        }
        requestObj["item_id"]=item
        requestObj["x"]=x
        requestObj["y"]=y
            plot.series[0].data = [[50,50]];
            plot.replot();

BLAH BLAH BLAH...

<%=itemNames.html_safe%> typically looks like this: [{label:"Winona Ryder"},{label:"Paris Hilton"},{label:"Margaret Thatcher"},{label:"Snooki"},{label:"Natalie Portman"},]

The chart draws fine when the page loads; when I click on the chart, nothing happens. I know the click is being caught; if I put an alert in there, I see it. Help!

Share Improve this question asked Sep 8, 2012 at 1:27 MikeCMikeC 4806 silver badges14 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

I suggest that you put your event handler in $(document).ready() as well -- sort of the corollary to what you posted.

By the main reason I wanted to respond was to note that since we're using jQuery why not "attach" it more directly to the jQuery element. To do this you would use:

$('placeholder').jqplot(data, options);

and now the plot bees:

$('placeholder').data('jqplot');

so you could replot this example with:

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

OK, figured it out. I needed to declare the "plot" variable as a global variable outside of $(document).ready(function()... Now it's working!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744783536a4593484.html

相关推荐

  • javascript - jqplot replot not working - Stack Overflow

    I am trying to replot my jqplot chart.$(document).ready(function(){var dataseries = [[[10,20]]];var plo

    2天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信