jqplot highlighter a line when mouse is over it

妖精的绣舞 提交于 2019-12-13 00:39:06

问题


I am using jqplot to generate several line plots, and would like to add the highlight feature to it. In detail, once your mouse is over this line, it will highlight itself (change color). I have see this feature in bar plot (example). Is there a way to introduce this to line plot?

Here is the demo of my code.


回答1:


This feature, at least to my knowledge, is not provided out of the box by the jqPlot. For this reason the 'easiest' is to add it yourself. I did something of this sort a while back. My approach was to use the jqplotMouseMove event and add the appropriate functionality there.

The idea of my approach is simple:

  1. Get the distance of the mouse point from a line segment.
  2. Then if it is smaller than the line's width - you found your line.
  3. Draw the line in different colour on the highlighter's canvas (.jqplot-highlight-canvas), thus creating the highlight effect - for this canvas we need the highlighter plugin.

The working sample of the aforementioned idea is here.

PS: Thanks to Jonas Raoni Soares Silva, for the point to line distance function which saved lots of my time, and works great.



来源:https://stackoverflow.com/questions/11460421/jqplot-highlighter-a-line-when-mouse-is-over-it

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