Scenario:
The code below in jsfidle shows an image and a text for some points.
Problem:
The problem is that I didn't find a way to dinamically change the tooltip position and to some points the image appears outside the grid.
$(document).ready(function () {
var url= "http://cameraserraverde.com.br/img/"
var line1 = [['01', 650, ""], ['02', 600, url+"img_fev.jpg"], ['04', 330, url+"imagem_abr.jpg"], ['06', 280, ""], ['08', 230, url+"imagem_ago.jpg"], ['10', 320, url+"imagem_out.jpg"],['11', 600, url+"imagem_nov.jpg"], ['12', 630, ""]];
var plot2 = $.jqplot('test', [line1], {
seriesDefaults: {
rendererOptions: {
smooth: true
}
},
axes: {
xaxis: {
renderer: $.jqplot.DateAxisRenderer,
tickOptions:{formatString: "%b"},
tickInterval: '1 month'
}
},
series: [{ lineWidth: 2,
}],
highlighter: {
show: true,
useAxesFormatters: false,
tooltipContentEditor: tooltipContentEditor,
},
});
function tooltipContentEditor(str, seriesIndex, pointIndex, plot) {
div = "<div>";
if (plot.data[seriesIndex][pointIndex][2] != ""){
div+= "<img src='" + plot.data[seriesIndex][pointIndex][2] + "''/>";
}
div+= "<figcaption style='text-align: center; background:#D0D0D0'>" + plot.data[seriesIndex][pointIndex][1] + "m</figcaption></div>"
return div;
}
});
The question is:
How can I define the tooltipLocation opposite to the point position, for example, if the point is on the grid's quadrant "ne", define the tooltipLocation as "sw"?
Looking for a solution I found this answer that allowed me to find a way. I didn't find a way to change the
tooltipLocation, but by changing the layout of thediv, I have the desired positioning.That answer shows, among other things, how to know the x, y coordinates of the point and this allows you to find out in which part of the grid the point and the tooltip are in.
I included a
cssand changed the tooltipContentEditor function to identify the X and Y coordinates and create anidfor thedivso that the appropriate style is applied. The code looks like this:CSS:
function tooltipContentEditor:
In this jsfidle you can see the before and here the after.