Highcharts:向每个 xAxis gridLine 添加可点击图像

发布于 2024-12-26 05:05:03 字数 488 浏览 0 评论 0原文

我正在构建一些自定义功能,用户可以单击折线图中的数据点来添加该日期的注释。这有点误导,因为注释实际上并未附加到指标本身,而是附加到其发布的日期。换句话说,如果我在一个折线图上有 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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无法回应 2025-01-02 05:05:03

基于 Mark 的建议,使用 redraw 事件来定位图像并使用 load 事件来创建图像。在load 上添加它们对于使它们在导出期间可用是必要的,并且您也不希望在每次redraw 上创建新图像。

使用这些图表事件:

events: {
    load: drawImages,
    redraw: alignImages
}

drawImages 函数中,我使用 xAxis 的逆转换来将图像定位在图表上:

x = chart.plotLeft + chart.xAxis[0].translate(i, false) - imageWidth / 2,
y = chart.plotTop - imageWidth / 2;

然后添加它们并设置单击处理程序、zIndex、指针光标:

chart.renderer.image('http://highcharts.com/demo/gfx/sun.png', x, y, imageWidth, imageWidth)
    .on('click', function() {
        location.href = 'http://example.com'
    })
    .attr({
        zIndex: 100
    })
    .css({
        cursor: 'pointer'
    })
   .add(); 

alignImages中,attr函数用于为图像设置新的x和y值,其计算方式与drawImages中相同。

jsfiddle 上的完整示例

屏幕截图:

Building on Mark's suggestion using redraw event to position the images and using load event to create them. Adding them on load is necessary to make them available during export and you would not want to create new images on each redraw either.

These chart events are used:

events: {
    load: drawImages,
    redraw: alignImages
}

In the drawImages function I'm using the inverse translation for the xAxis to position the images on the chart:

x = chart.plotLeft + chart.xAxis[0].translate(i, false) - imageWidth / 2,
y = chart.plotTop - imageWidth / 2;

and then adding them and setting a click handler, zIndex, pointer cursor:

chart.renderer.image('http://highcharts.com/demo/gfx/sun.png', x, y, imageWidth, imageWidth)
    .on('click', function() {
        location.href = 'http://example.com'
    })
    .attr({
        zIndex: 100
    })
    .css({
        cursor: 'pointer'
    })
   .add(); 

In alignImages the attr function is used to set new x and y values for the images which are calculated the in the same way as in drawImages.

Full example on jsfiddle

Screenshot:

screenshot

も让我眼熟你 2025-01-02 05:05:03

几个想法。首先,我将使用图表 redraw 事件来了解图表何时正在重新绘制(例如缩放)。其次,明确地将图像放置在感兴趣的轴位置。直接从 DOM 中获取这些查询。

使用 jQuery:

$('.highcharts-axis') //return an array of the two axis.

它们将具有 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:

$('.highcharts-axis') //return an array of the two axis.

They will have svg "text element" children with (x, y) positions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文