如何使图形上最近的四个点发光

How do I make the closest four points on a graph glow?

本文关键字:四个 图形 何使 最近      更新时间:2023-09-26

当我的光标移动时,如果它还没有在标绘点上,我会抓住两个最近的点。

我希望能够使这两个最接近的点亮起(即将颜色更改为橙色或其他东西),然后在光标离开图形范围后恢复正常。我该如何实现这一点?

placeholder.bind("plothover",  function (event, pos, item) {
    if (item){
        local_x = item.datapoint[0].toFixed(2);
        local_y = item.datapoint[1].toFixed(2);                 
        if (!updateLegendTimeout){
        updateLegendTimeout = setTimeout(updateLegend(local_x,local_y), 1000);
        updateLegendTimeout = null;
        }
    }
    else{
         var closest_points_container = interpolate(plot,pos.x,pos.y);                              
         //Code to make points glow goes here, they are contained in closest_points[0]                   
           and closest_points[1].
    }

Flot 在绘图对象上提供突出显示和取消突出显示的方法,如文档的绘图方法部分所述。 不幸的是,这有一个限制,即一次只能突出显示一个点。 那是内在的;如果不更改源,则无法更改它。

我将使用的解决方法是添加第二个系列,仅显示点,不显示线条,并将点样式设置为显示为突出显示,即半透明。 这个亮点系列一开始是空的;然后,当您想突出显示主系列上的某个点时,可以将其复制到突出显示系列并重新绘制。