2016-02-17 38 views
0

使用Highcharts中的工具提示我可以看到,並非所有類型的系列都包含在同一個工具提示中。在我Highcharts的定義對象的工具提示的屬性看起來像:在所有系列類型之間共享工具提示

tooltip: { 
    positioner : function (boxWidth, boxHeight, point) { 
     return { 
      x : point.plotX - 100, 
      y : point.plotY 
     }; 
    }, 
    shared : true 
} 

怎麼我設置tooltip屬性爲每個系列:閱讀提示的文件

public getDefaultTooltip() { 
    return { 
     pointFormat : '<span style="font-weight: bold; color: {series.color}">{series.name}</span>: <b>{point.y} </b><br/>' 
    }; 
} 

後,我可以看到該共享屬性對於'scatter'類型的系列是無效的,那些不適合我的系列類型究竟是什麼。那麼,是否有一些解決方法可以在同一個共享工具提示中提供所有數據?

在下面的示例中,我想在同一個工具提示中顯示所有系列數據,但散佈系列使用不同的彈出式窗口。 http://jsfiddle.net/rolandomartinezg/a6c4c4tv/1/

+0

我想你指的 「功能」,而不是 「公共」。 JavaScript沒有可見性修飾符,除非這是一些僞Java代碼? –

+0

對不起,使用打字稿也:) – Rolando

+0

@Rolando:你可以請你在jsfiddle上分享你的代碼,以更好地評估你的問題? :) –

回答

2

ScatterSeries在highcharts中定義,noSharedTooltip = true。我認爲這是因爲scatter系列在其工具提示中顯示x和y。

var ScatterSeries = extendClass(Series, { 
    type: 'scatter', 
    sorted: false, 
    requireSorting: false, 
    noSharedTooltip: true, 
    trackerGroups: ['group', 'markerGroup', 'dataLabelsGroup'], 
    takeOrdinalPosition: false, // #2342 
    kdDimensions: 2, 
    kdComparer: 'distR', 
    drawGraph: function() { 
     if (this.options.lineWidth) { 
      Series.prototype.drawGraph.call(this); 
     } 
    } 
}); 

要解決這個問題,你可以使用一個線系列,而不是與線寬= 0您還需要關閉懸停狀態的系列,以避免廣告顯示在懸停了線分散系列。

, { 
     type: 'line', 
     name: 'Average', 
     lineWidth: 0, 
     states: { 
      hover: { 
      enabled: false 
      } 
     }, 
     data: [3, 2.67, 3, 6.33, 3.33], 
     marker: { 
      lineWidth: 2, 
      lineColor: Highcharts.getOptions().colors[3], 
      fillColor: 'white' 
     } 
    } 

http://jsfiddle.net/a6c4c4tv/2/

+0

你的回答非常明確。並且你也給出了答案,以避免懸停狀態。 – Rolando