[英]Highlight label when clicked on the corresponding plot in a flot graph
I have a float graph as shown in the figure. 我有一个如图所示的浮动图。 I need to highlight a label when a corresponding plot is clicked.
单击相应的图时,我需要突出显示标签。
/*The below is my function where my HTML is defined in JavaScript*/
function insertlabel()
{
placeholder.find("ticklabels").remove();
var html=['<div class="ticklabels" style="font-size:smaller; color:'+options.grid.color+'">'];
function addlabels(axis,labelgenerate){
for(var i=0;i<axis.ticks.length;++i){
var tick=axis.ticks[i];
if(!tick.label||tick.v<axis.min||tick,v>axis.max)
continue;
html.push(labelgenerate(tick,axis));
}
}
}
//This is the addlabel function
addlabels(axes.yaxis,function(tick,axis){
return '<div id="text" style=position: absolute ; some calculation +ticklabel /div>'
}
/*The jquery code is as follows.*/
$(this).click(function() {
$('#text').each(function() {
$(this).css('color','#C4BD97')
});
});
This is the jquery code i tried but its highlighting only the last label whichever plot is clicked. 这是我尝试过的jQuery代码,但无论点击哪个绘图,它都仅突出显示最后一个标签。 I want to highlight only the corresponding label when its series plot is clicked.
单击序列图时,我只想突出显示相应的标签。
Here's an example that'll highlight the y axis label of the y value of the point clicked. 这是一个示例,将突出显示所单击点的y值的y轴标签。 I didn't bother replacing
flot's
axis labels with custom labels, as you seem to be doing (I'm not sure where you are going with all that). 正如您似乎正在做的那样,我没有费心用自定义标签替换
flot's
轴标签(我不确定所有这些都去了哪里)。
$("#placeholder").bind("plotclick", function (event, pos, item) {
if (item){
var yVal = item.datapoint[1];
var yAxis = plot.getAxes().yaxis;
for (var i = 0; i < yAxis.ticks.length; i++){
if (yAxis.ticks[i].v == yVal){
yCor = yAxis.p2c(yVal);
$('#arrow').css({'display':'block','top':yCor});
}
}
}else{
$('#arrow').css({'display':'none','top':yCor});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.