Mouse hover applied to jQPLOT X AXIS TICKS

拈花ヽ惹草 提交于 2019-12-24 15:07:38

问题


I am trying to add mouse hover function to my axis ticks. what i want is to show long ticks full text only on hover else it would be showing only few characters . i am adding a hover event to .jqplot-xaxis-tick .But it doesnot even respond to hover.Please suggest !

.jqplot-xaxis-tick {
    top: 0px;
    /* initial position untill tick is drawn in proper place */
    left: 15px;



/*    padding-top: 10px;*/
    vertical-align: top;
     overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;

}
.jqplot-xaxis-tick :hover{
overflow:visible;

    white-space: normal; 
    width: auto;
    position: absolute;
    background-color:yellow;
}

回答1:


The hover is not detecting because of the z-index of the canvas which lies on top of the whole chart. I did the following and now it's shorten the tootip by CSS ellipsis and show the tooltip with full name on hover.

Based on the Gyandeep's answer, the exact JS and CSS I used are,

Javascript:

$('div.jqplot-xaxis-tick').each(function (i, obj) {
    $(this).prop('title', ($(this).text()));
    $(this).css('z-index', 999);  // this is important otherwise mouseover won't trigger.
});

CSS:

.jqplot-xaxis .jqplot-xaxis-tick {
    position: absolute;
    white-space: pre;
    max-width: 92px;  // Change it according to your need
    overflow: hidden;
    text-overflow: ellipsis;
}

The JavaScript part needs to be executed after every rendering of chart. It's better to put them right after plotting the chart and may in the AJAX success handler.




回答2:


I managed to add a tooltip kindof feature to axis ticks.When I hover upon them it shows a separate box with full text else only 3-4 characters are shown. The code is something like this

$($('.jqplot-xaxis-tick')[i]).bind('mouseover', function () {

        //   var m= '-webkit-marquee';


  $($('.jqplot-xaxis-tick')[i]).css('white-space','pre-line');
  $($('.jqplot-xaxis-tick')[i]).css('overflow','visible');  
  $($('.jqplot-xaxis-tick')[i]).css('width','auto'); 

  $($('.jqplot-xaxis-tick')[i]).css('position','absolute');
  $($('.jqplot-xaxis-tick')[i]).css('background-color','#666666');
  $($('.jqplot-xaxis-tick')[i]).css('color','white');
  $($('.jqplot-xaxis-tick')[i]).css('top','-45px');









// $($('.jqplot-xaxis-tick')[i]).css('overflow-x',m);
//  console.log($($('.jqplot-xaxis-tick')[i]).text());



   }).bind('mouseout', function () {
 //var m= '';
//$($('.jqplot-xaxis-tick')[i]).css('overflow-x',m);
 $($('.jqplot-xaxis-tick')[i]).css('white-space','nowrap');
  $($('.jqplot-xaxis-tick')[i]).css('overflow','hidden');  
  $($('.jqplot-xaxis-tick')[i]).css('width','50'); 
 $($('.jqplot-xaxis-tick')[i]).css('background-color','');
  $($('.jqplot-xaxis-tick')[i]).css('color','grey');
$($('.jqplot-xaxis-tick')[i]).css('top','0px');


 });



回答3:


Here's the solution I'm using to display monthly high and low temperatures. Hovering over the x-axis tick will display an alert with the active month name and temps.

// Set up hover function
$('#monthlyTemps .jqplot-xaxis-tick').hover(function () {
    setActiveColumn($(this));
});

// Set active column
function setActiveColumn(sender) {
    // Display values
    var monthName = sender.text();
    var monthIndex = monthNames.indexOf(monthName);
    var monthLowTemp = getMonthLowTemp(monthIndex);
    var monthHighTemp = getMonthlHighTemp(monthIndex);
    alert(monthName + ': ' + monthLowTemp + ' / ' + monthHighTemp);
}

// Get month low temp
function getMonthLowTemp(monthIndex) {
    var value= $("#monthlyTemps .jqplot-point-label.jqplot-series-0.jqplot-point-" + monthIndex).text();
    return value;
}

// Get month high temp
function getMonthlyHighTemp(monthIndex) {
    var value= $("#monthlyTemps .jqplot-point-label.jqplot-series-1.jqplot-point-" + monthIndex).text();
    return value;
}

var monthNames = new Array(12);
monthAbbreviations[0] = "Jan";
monthAbbreviations[1] = "Feb";
monthAbbreviations[2] = "Mar";
monthAbbreviations[3] = "Apr";
monthAbbreviations[4] = "May";
monthAbbreviations[5] = "Jun";
monthAbbreviations[6] = "Jul";
monthAbbreviations[7] = "Aug";
monthAbbreviations[8] = "Sep";
monthAbbreviations[9] = "Oct";
monthAbbreviations[10] = "Nov";
monthAbbreviations[11] = "Dec";


来源:https://stackoverflow.com/questions/17691939/mouse-hover-applied-to-jqplot-x-axis-ticks

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