2013-04-03 77 views
2

使用Highchart.jshighcharts add plotline label with images

是否可以将图像添加到情节标签?东西如下图所示

enter image description here

我想用一个工具提示一起加入这个(我)的图像,但似乎(从here),其可用于该元素的组有限的HTML不支持图像,申报单或标题。

我已经想到,将图像和工具提示添加到独立的div(从图表)中,找到标签的位置并使用绝对定位添加此图层会更容易。但是我不能给这个元素添加任何id或者什么,所以我找不到它的位置。

有人有类似的问题?

我的解决方案:

CSS

.infoMedia { 
    position: absolute; 
    z-index : 10000; 
    width: 30px; 
    height: 30px; 
    background: url('../img/information.png') center no-repeat; 
} 

HTML

<div class='infoMedia' style='left:0px;top:0px;'></div> 

的JavaScript

function processHintPosition() // every resize, call this function 
{ 
    $('.infoMediaENEM').css('top', 0); 
     $('.infoMedia').css('left', 0); 

     var this_container = $('#container_line_graph'); 

     var this_container_width = $(this_container).width(); 
     var this_container_height = $(this_container).height(); 

     var this_margin_y = 60; 
     var this_margin_x = 15; 


     $('.infoMedia').css('top', $(this_container).offset().top + $(this_container).height() - this_margin_y); 

     // POSITION X 
     var x_val = $(this_container).offset().left + this_container_width - this_margin_x; 
     $('.infoMedia').css('left', x_val) 

     // POSITION Y 
     var this_media = parseFloat(lineGraph.linechart_data.prcMedia); 
     var this_max = 100; 

     var this_val_posy = Math.ceil((this_media * (this_container_height - this_margin_y))/this_max); 

     var y_val = (($('.infoMedia').offset().top) - this_val_posy) - ($('.infoMedia').height()/2); 
     $('.infoMedia').css('top', y_val); 
} 
+0

你能可能告诉我你如何添加一个标签,你的情节主线?谢谢! – AustinT

+0

当用户滚动或更新位置时,我最终将独立于图形的图标与绝对定位一起放置在逻辑上。 – jose

+0

你是如何计算图像位置的?你能在这里发布你的最终解决方案吗? – Guian

回答

1

看起来好像有一个useHTML选项的yAxislabels配置,允许使用图像。

http://api.highcharts.com/highcharts#yAxis.labels.useHTML

+0

是的,有。不幸的是,它可用于yAxis标签,不适用于yAxis-> plotLines->标签:( – jose

+2

@jose我意识到,发布我的答案后,您指的是'yAxis.plotLines.labels'而不是'yAxis.labels '。所有的歉意,它看起来'plotLines.labels'的唯一选项是基本的CSS规则(不包括'background-image'属性)。 – Joe

1

如果你想在该元素和进一步修改,您可以:

chart.yAxis[0].plotLinesAndBands[0]; 

2)或者:

1)通过图表对象得到它,通过文本本身在DOM中找到它:

$('#container text:contains("Plot line")') // where container is the ID of the div container and "Plot line" is the text of the plot line