2014-04-16 219 views
2

所以我在單個頁面上有多個高圖。其中一些圖(行)在一張圖上包含多個系列。我遇到的問題是能夠爲一個或兩個系列選擇多個點。Highcharts - 多個Y軸

這裏是什麼,我試圖做一些示例代碼,但它給了我的問題......

function hc_json(series, hc_id) { 
    $('#' + hc_id).highcharts('StockChart', { 
     chart: { 
      events: {   //Sets an event listener for the chart 
       /* 
       * If an event is registered it checks if the external zoom/selects are checked. 
       * If select is checked it gets the data points that were within the range at sets 
       * them as selected. 
       */ 
       selection: function(event) { 
        var mode = $('input[name=mode]:checked', '#' + hc_id + '_control').val(); 
        if (mode != hc_id + '_zoom') { 

         for (var i = 0; i < this.series.length; i++) 
         { 
          console.log("Series: ", this.series); 
          console.log("Series length: ", this.series.length); 
          var points = this.series[i].points; // visible points 
          var xs = event.xAxis[0]; //There seems to be no min/max forxAxis[1] 
          $.each(points, function (i,p) { 
           if (p.x >= xs.min && p.x <= xs.max) { 
            console.log("Point:", p.x, "is selected"); 
            p.select(true, true); 
           } 
          }); 
          //return false; 
         } 
         return false; 
        } 
       }, 
      }, 

因此,舉例來說,我希望能夠在圖表上選擇點一但我希望能夠區分我想要選擇的系列。我閱讀了一些「可見」系列文章,但還沒有弄清楚如何讓一個系列可見或不可見。

回答

1

請大家看一下這個解決方案:

chart: { 
     events: { 
      selection: function(event) { 
       var chart = this, 
        min = event.xAxis[0].min, 
        max = event.xAxis[0].max, 
        txt = ''; 
       if (event.xAxis) { 

        $.each(chart.series,function(i,serie){ 
         $.each(serie.data,function(j,point){ 
          if(point.x >=min && point.x <=max) { 
           txt += '<br>serie: ' + serie.name + ' point: '+ point.y; 
           point.select(true,true); 
          } 
         }); 
        }); 

        $report.html(txt); 
       } 
      } 
     }, 
     zoomType: 'x' 
    }, 

http://jsfiddle.net/cNRx5/2/

+0

太謝謝你了!這正是我所期待的! – cmircovich