2011-02-06 14 views
2

[OK]をクリックすると、デモページの[Clear Selection]ボタンが有効になったことをFlotで確認してから、http://people.iola.dk/olau/flot/examples/selection.htmlと表示されます。それはあなたの誰のために働いていますか?私はIE 7/8とFirefoxで試しました。鉱山のグラフで同じ機能を実装しようと、それは、仕事にのみデモページに動作していない例を見つけるために得ることができなかったとき、私はこれだけに気づいjQuery Flot clear selection

...

はここに私のコードです:それは事実上FLOTの例からコピーおよび過去のですが、何がここに明白な存在であるよう

$.post(applicationPath + "graph/" + action, 
    function (data) 
    { 
     var graphOptions = { 
      xaxis: { 
       mode: 'time', 
       timeformat: "%m/%d/%y" 
      }, 
      yaxis: { 
       tickDecimals: 0 
      }, 
      legend: { 
       show: true, 
       container: $('.legend') 
      }, 
      series: { 
       points: { show: true }, 
       lines: { show: true } 
      }, 
      grid: { 
       hoverable: true, 
       clickable: true 
      }, 
      selection: { 
       mode: "xy" 
      } 
     }; 

     // hard-code color indices to prevent them from shifting as 
     // series are turned on/off 
     var i = 0; 
     $.each(data, function (key, val) 
     { 
      val.color = i; 
      i++; 
     }); 

     var optionsContainer = $('.module.graph .options-menu'); 

     $.each(data, function (key, val) 
     { 
      optionsContainer.append('<li><input type="checkbox" name="' + key + '" checked="checked" id="id' + key + '">' + val.label + '</li>'); 
     }); 

     $('.module.graph .header .options').optionsMenu(
     { 
      sTarget: '.options-menu', 
      fnCheckboxSelected: function (index, name) 
      { 
       $.plot(data, optionsContainer, graphOptions); 
      }, 
      fnCheckboxDeselected: function (index, name) 
      { 
       $.plot(data, optionsContainer, graphOptions); 
      } 
     }); 

     var dataSet = []; 

     optionsContainer.find('input:checked').each(function() 
     { 
      var key = $(this).attr('name'); 

      if (key && data[key]) 
      { 
       dataSet.push(data[key]); 
      } 
     }); 

     var previousPoint = null; 
     var graphContainer = $('.graph #graph-container'); 

     graphContainer.bind('plothover', function (e, pos, item, ranges) 
     { 
      if (item) 
      { 
       if (previousPoint != item.datapoint) 
       { 
        previousPoint = item.datapoint; 

        $('#tooltip').remove(); 

        var xFormatted = new Date(item.datapoint[0]).toDateString(); 
        var x = item.datapoint[0].toFixed(2); 
        var y = item.datapoint[1].toFixed(2); 

        showGraphToolTip(item.pageX, item.pageY, item.series.label + " of " + y + " on " + xFormatted); 
       } 
      } 
      else 
      { 
       $('#tooltip').remove(); 
       previousPoint = null; 
      } 
     }); 

     graphContainer.bind('plotselected', function (event, ranges) 
     { 
      if (ranges.xaxis.to - ranges.xaxis.from < 0.00001) 
      { 
       ranges.xaxis.to = ranges.xaxis.from + 0.00001; 
      } 
      if (ranges.yaxis.to - ranges.yaxis.from < 0.00001) 
      { 
       ranges.yaxis.to = ranges.yaxis.from + 0.00001; 
      } 

      $.plot(graphContainer, dataSet, 

       $.extend(true, {}, graphOptions, 
       { 
        xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to }, 
        yaxis: { min: ranges.yaxis.from, max: ranges.yaxis.to } 
       }) 
      ); 
     }); 

     var graph = $.plot(graphContainer, dataSet, graphOptions); 

     $('#clearSelection').click(function() 
     { 
      graph.clearSelection(); 
     }); 
    }, 
    "json" 
); 

私は本当に私のコードでは何も悪いことを見ることができませんか?

また、Flotにはバグがありますか?明確な選択デモはあなたのために機能しますか?

+0

デモリンクがうまく動作します。 Firebug/Consoleが動作しないときにjsエラーが表示されますか? – Dogbert

+0

私は実際に別のコンピュータにいますが、まだデモでは何も得られません。 Firebugにもエラーはありません。そして、ちょうどFYI、私は選択範囲のチェックボックスを選択しており、ズームはうまく動作します。どのブラウザを使用していますか?私はFirefox 3.6.13とIE 8を使用しています...合計奇妙さ... – Jeff

+0

うわー...私のiPhoneでも試しましたが、ズームすることはできないので「年選択」ボタンをクリックしても。明確な選択はまだ機能しませんでした... – Jeff

答えて

1

flot.googlecode.com

  • setupGrid()
Recalculate and set axis scaling, ticks, legend etc. 

Note that because of the drawing model of the canvas, this 
function will immediately redraw (actually reinsert in the DOM) 
the labels and the legend, but not the actual tick lines because 
they're drawn on the canvas. You need to call draw() to get the 
canvas redrawn. 

から、あなたがリセット機能にこれを追加する場合は、あなたが期待通りに動作させることができるはずです。