简体   繁体   中英

Flot: grab nearest point to crosshair

I've been customizing my graphics and I've been trying to get the nearest point to the crosshair. The closest I got was by adding the mouseActiveRadius option, however this does not apply my desired effect. This is what happens:

在此输入图像描述

As can be seen, the wrong point is being highlighted.

My plot code:

    $.plot("#players_chart",
        [{
            label: "Total number of players",
            data: data.data_labels
        }],
        {
            series: {
                lines: {
                    show: true
                }
            },
            xaxis: {
                mode: "time",
                minTickSize: [1, "day"],
                timeformat: "%a"
            },
            yaxis: {
                tickDecimals: 0
            },
            crosshair: {
                mode: "x"
            },
            grid: {
                hoverable: true,
                autoHighlight: true,
                mouseActiveRadius : 1000
            }
        }
    );

Is there any way to add some kind of horizontal radius to the crosshair instead of grid?

Thank you in advance.

The default point highlighting is separated from the crosshair plugin and works only by distance from the cursor. If you want to only work with horizontal distance you can do the highlighting manually.

Set autoHighlight: false and bind a plothover event where you search the nearest point on the x axis and then highlight that point.

Similar code is in the example for the crosshair plugin .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM