Add or highlight a single points on a jQuery flot graph?

不打扰是莪最后的温柔 提交于 2019-12-08 04:30:41

问题


I've already drawn a flot graph using some data:

    var plot = $.plot($("#placeholder"),
    [{
        data: data,
    }], {
        series: {
            points: {
                show: true
            }
        },
        grid: {
            hoverable: true,
        }
    });

Now I'd like to highlight a single point on the graph, when a user hovers over an item elsewhere on the page.

I found this question, which explains how to totally redraw the series from scratch, but is there a way to highlight a single point?

Or add a new point in a different colour, which would have the effect of a highlight?

NB: when the user hovers over the relevant item elsewhere on the page, I will have the x and y coordinates of the related point, but not the pixel coordinates on the graph.


回答1:


The API provides the following methods:

The Plot object returned from the plot function has some methods you can call:

  • highlight(series, datapoint)

    Highlight a specific datapoint in the data series. You can either specify the actual objects, e.g. if you got them from a "plotclick" event, or you can specify the indices, e.g. highlight(1, 3) to highlight the fourth point in the second series (remember, zero-based indexing).

  • unhighlight(series, datapoint) or unhighlight()

    Remove the highlighting of the point, same parameters as highlight.

    If you call unhighlight with no parameters, e.g. as plot.unhighlight(), all current highlights are removed.



来源:https://stackoverflow.com/questions/7716631/add-or-highlight-a-single-points-on-a-jquery-flot-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!