Highcharts:向每个 xAxis gridLine 添加可点击图像
我正在构建一些自定义功能,用户可以单击折线图中的数据点来添加该日期的注释。这有点误导,因为注释实际上并未附加到指标本身,而是附加到其发布的日期。换句话说,如果我在一个折线图上有 6 个系列,跨越日期 01/01/12 - 01/08/12,则 01/05/12 上的单个注释将适用于所有 6 个系列。因此,您可以想象,单击 6 个系列之一或日期 01/05/12 上的数据点会误导用户,使其相信此注释将应用于该数据点,而不是整个日期和任何系列在那一天着陆。
因此,为了解决这个可用性问题,我决定最好的视觉提示是这样的:
每个 xAxis gridLine 的顶部都有一个可单击的图标,需要随 xAxis gridLine 缩放(就像用户选择要放大的区域一样)。
关于实现这一目标的最佳方法的建议?我只需要关于如何最好地将图标添加到每一行的建议...我已经构建了所有点击后功能。
I'm building in some custom functionality where users can click on data points in a line chart to add notes to that date. This is a bit misleading as the notes aren't actually attached to the metrics themselves but rather the date it lands on. In other words, if I have 6 series on one line chart that spans the dates 01/01/12 - 01/08/12, a single note on 01/05/12 will apply to all 6 series. So, as you can imagine clicking on a data point on one of the 6 series or the date 01/05/12 would mislead the user to believe that this note would be applied to that data point, not the entire date and any series that lands on that date.
So, to remedy this usability issue I've decided that the best visual cue would be something like this:
There would be a clickable icon at the top of each xAxis gridLine that would need to scale with the xAxis gridLine (like if a user selects an area to zoom in on).
Suggestions on best way to pull this off? I only need a suggestion for how best to add the icon to every line... I have all post-click functionality already built.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于 Mark 的建议,使用
redraw
事件来定位图像并使用load
事件来创建图像。在load
上添加它们对于使它们在导出期间可用是必要的,并且您也不希望在每次redraw
上创建新图像。使用这些图表事件:
在
drawImages
函数中,我使用 xAxis 的逆转换来将图像定位在图表上:然后添加它们并设置单击处理程序、zIndex、指针光标:
在
alignImages
中,attr
函数用于为图像设置新的x和y值,其计算方式与drawImages
中相同。jsfiddle 上的完整示例
屏幕截图:
Building on Mark's suggestion using
redraw
event to position the images and usingload
event to create them. Adding them onload
is necessary to make them available during export and you would not want to create new images on eachredraw
either.These chart events are used:
In the
drawImages
function I'm using the inverse translation for the xAxis to position the images on the chart:and then adding them and setting a click handler, zIndex, pointer cursor:
In
alignImages
theattr
function is used to set new x and y values for the images which are calculated the in the same way as indrawImages
.Full example on jsfiddle
Screenshot:
几个想法。首先,我将使用图表 redraw 事件来了解图表何时正在重新绘制(例如缩放)。其次,明确地将图像放置在感兴趣的轴位置。直接从 DOM 中获取这些查询。
使用 jQuery:
它们将具有 svg“文本元素”子元素,其位置为 (x, y)。
Couple of ideas. First, I would use the chart redraw event to know when the chart is being redrawn (say on a zoom). Then second, explicitly place your images at the axis locations of interest. To get those query directly out of the DOM.
Using jQuery:
They will have svg "text element" children with (x, y) positions.