-
Notifications
You must be signed in to change notification settings - Fork 184
How to show a tooltip? #31
Comments
'mouseover': function(event, data) { |
Very nice! |
Can someone please help me I am trying to display a tooltip in my map and no matter how I try it seems to never work. I have the following code: 'mouseover': function(event, data) { $('#map').mousemove(function(e) { var mousex = e.pageX - 10; //Get X coordinates var mousey = e.pageY - 30; //Get Y coordinates $('.tooltip').css({ top: mousey, left: mousex }) }); }, 'mouseout': function(event, data) { $('.tooltip').remove(); }, enableToolTips: true My map div id is "map" and it never goes into the $('#map').mousemove() function |
Tried the above with no avail:
Am I missing something? |
Just to report back, if anyone needs help. It's easier to create a div and then specify its actions. The following works for me and gives a pretty nice styled tooltip on
|
Hi Kj I am trying to add a tooltip. But its not woking. Can you please look at my code and give me an advice. <script> $(document).ready(function() { $('#map').usmap({ useAllLabels: true, stateSpecificStyles: { 'AL': {fill: '#529669'}, 'MS': {fill: '#b4a8bc'} stateSpecificHoverStyles: { 'AL': {fill: 'red'}, 'MS': {fill: 'red'} }, mouseover: function(event, data) { $('#tooltip').text(data.name).show(); $('#map').mousemove(function(e){ var mouseX = e.pageX -10; var mouseY = e.pageY -30; $('#tooltip').css({ top:mouseY, left:mouseX, 'position': 'absolute', 'border':'1px solid black', 'background': '#fff', 'color': '#ffffff', 'font-size': '1.5 em', 'padding': '5px', 'opacity': '0.75', 'border-radius': '2px' }); }); }, // Hide tooltip when not hovering over state mouseout: function(event, data){ $('#tooltip').hide(); }, }); }); </script> |
Can you format your code? It will be easier to troubleshoot. Use the "<>" button in the text editor. |
Thanks for your quick response. |
Hi Kate thanks a lot for your help. So now I have a working code with tooltip. Inside the tooltip I want to have dirrerent text for different states. How I can implement it. Below is my woking code:
<script>
$(document).ready(function() {
$('#map').usmap({
useAllLabels: true,
stateSpecificStyles: {
'ME': {fill: 'red'},
'WI': {fill: 'red'},
'MT': {fill: 'red'}
},
stateSpecificHoverStyles: {
'ME': {fill: 'green'},
'WI': {fill: 'green'},
'MT': {fill: 'green'}
|
The |
Thanks a lot for your quick response. |
So if I want to display the tooltip text like this, how can I code it? What are the changes needed in my code?
<script>
$(document).ready(function() {
$('#map').usmap({
useAllLabels: true,
stateSpecificStyles: {
'ME': {fill: 'red'},
'WI': {fill: 'red'},
'MT': {fill: 'red'}
},
stateSpecificHoverStyles: {
'ME': {fill: 'green'},
'WI': {fill: 'green'},
'MT': {fill: 'green'}
|
Thansk my code is working. I am using a conditional statement. |
How can i show FULL state name (For Eg 'Texas') on tool tip ? @kjrhody ??? |
@bmanu Make an array somewhere and then use the abbreviation to get the value. E.g.:
And then call it in the
|
@kjrhody .. thank you very much... I have done it. But already one array in JS file named 'otherStates' , why we cant use it like 'otherStates[state].full' ? Also is any way to make all state color full ? :), Thanks |
@kjrhody .. can you help me one more .. I want to add different color to each state . I tried like But its working only at end of the code for AZ ... Thanks |
@bmanu You have to put all the states in the same call, not make separate ones for each state:
|
@kjrhody ..Oh lovely .. thank you very much. I tried this. One more . I created an array like you said first 'nameList ' . Can I add these 3 items 'Name of state' ,its 'stateSpecificStyles' & 'stateSpecificHoverStyles' with single key 'State short text' for ex 👍 var stateNamelist = { And then call this an array.. how can we ? Thanks |
@bmanu Good idea! But you're on your own for that one - I haven't implemented anything like that yet. |
Thanks @kjrhody how can we make an array ? How to make an array here for State code (AL, AK, AZ) & its fill values ? Thanks |
@bmanu I suggest reading the documentation, all of that information is in there: |
Is it possible to show a tooltip when the mouse pointer is over a state?
I want to show some infor when the user passes the pointer over a state, each state has a different tooltip content.
I am trying to use something like this plugin:
http://www.opentip.org/
my current code looks like this:
$('#map').usmap({
The text was updated successfully, but these errors were encountered: