jquery.flot.dashes.js 是否支持 plothover 和 plotclick?

2022-01-22 00:00:00 hover jquery javascript flot

通过使用 plothover 事件,我使用正常的图形选项(不使用破折号)设置了一个可行的工具提示系统,但是当我切换到黑白"模式(使用破折号)时,绘图无法悬停.使用破折号时,有什么方法可以使图表保持可悬停和可点击?或者有一种方法可以在没有破折号的情况下以黑白方式制作出体面的情节?

I have a workable tooltip system set-up with my normal graphing options (not using dashes) by using the plothover event, but the plot is not hoverable when I switch to my "black and white" mode (using dashes). Is there any way to keep the graph hoverable and clickable when using dashes? Or a way to make a decent looking plot in black and white without dashes?

示例系列:{data: data, dashes:{show: true, dashLength: 2}, color: "black", label: "Series 1"}

我目前的绘图选项:

options = {
      yaxis: {max: maxValue, min: minValue},
      grid: {hoverable: true, clickable: true},
      legend: {show: false},
      xaxis: {tickFormatter: null}
  };

我使用 plothover 事件作为工具提示,如下所示:

I use plothover event for tooltips like this:

$(this).bind("plotclick", function (event, pos, item){//这里是工具提示代码}

推荐答案

参见 this issue 针对 jQuery.flot.dashes 插件填写.

See this issue filled against the jQuery.flot.dashes plugin.

关于悬停问题,有一个名为findNearbyItem"的函数在 jquery.flot.js 中,仅当绘图显示时才执行搜索线、点或条.如果您只显示破折号",那么它不会执行搜索.

Regarding the hover issue, there's a function called "findNearbyItem" in jquery.flot.js that performs the search only if the plot is showing lines, points or bars. If you only have "dashes" showing, then it won't perform the search.

两种选择:
- 修改 jquery.flot.js 文件中的以下行: if (s.lines.show || s.points.show) 类似if (s.lines.show || s.points.show || s.dashes.show)
- 在您显示破折号的系列中显示半径为 0 的点:(来自评论 #41 中的示例)
{ label: "sin(x)", data: d1, dashes: { show: true, steps:true }, points: {show: true, radius:0 }}

我同意发帖者的观点,即第二种解决方案是一个更好的主意.我也试过 in this fiddle 并且效果很好.

I agree with the poster that the second solution is a better idea. I've also tried it out in this fiddle and is works well.

相关文章