2011-02-06 2 views
2

좋아, 나는 일단 Flot을 사용하여 데모 페이지의 "Clear Selection"버튼이 작동했다면 꽤 확신 할 수 있습니다. http://people.iola.dk/olau/flot/examples/selection.html. 여러분 모두에게 효과가 있습니까? 나는 IE 7/8과 Firefox에서 시도했다. 내 그래프에서 동일한 기능을 구현하기 위해 노력하고, 작업에만 데모 페이지에 작동하지 않는 예제를 찾을 수 없을 때 나는 단지이 발견jQuery Flot clear 선택

...

여기 내 코드입니다 : 그것은 실질적으로 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에도 오류가 없습니다. 그리고 참고로, 선택 항목 확대/축소 확인란을 선택하고 확대/축소가 올바르게 작동합니다. 어떤 브라우저를 사용하고 있습니까? 나는 파이어 폭스 3.6.13과 IE 8을 사용하고있다. 총 기괴함 ... – Jeff

+0

와우 ... 내 아이폰에서도 시도했지만 확대/축소 할 수 없기 때문에 "연도 선택"버튼을 클릭하기조차했다. 명확한 선택은 여전히 ​​작동하지 않았습니다 ... – Jeff

답변

1

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. 

당신은 당신이 예상대로 작동 할 수 있어야합니다.