I'm using the Cursor plugin to display a vertical line on a jqplot chart. The tooltip for the Cursor plugin is showing the X and Y values.
I want to add a piece of meta data to the plot points.
[x,y,1337] where 1337 is the meta deta.
I want to modify the Cursor plugin tooltip to show this metadeta as well as the data it already displays.
Use case: I have multiple series that have been scaled to 0-100 across all series for trending. I need to display the unscaled value.
Update:
i've got it working by hacking up jqplot.cursor.js, is there a better way?
Line 468: function updateToolTip(gridpos, datapos, plot){
// ...
s += $.jqplot.sprintf(c.tooltipFormatString, label, sx, sy, data[2]);
This is how I override the tooltipContentEditor jqplot function, it works great.
highlighter: {
show: true,
showMarker:true,
showTooltip:true,
sizeAdjust: 10,
tooltipLocation: 'se',
tooltipAxes: 'xy',
yvalues: 1,
formatString:'<table class="jqplot-highlighter"><tr><td>date:</td><td>%s</td></tr><tr><td>PiecesPerHour:</td><td align="right">%s</td></tr></table>',
useAxesFormatters: true,
tooltipContentEditor: function(str, seriesIndex, pointIndex, plot){
var data = plot.series[seriesIndex].data[pointIndex];
var label = plot.legend.labels[seriesIndex].indexOf('Target')
var format = [];
//A little formatting to the data before I join it to the Html string
if (that.model.get('groupBy')==='month')
format[0] = new Date(data[0] + 1000*60*60*24).format('mmmm yyyy');
else
format[0] = new Date(data[0] ).format('mmmm dd, yyyy');
format[1] = new Number(data[1]).toFixed(1)
//join the data to the Html string:
str = $.jqplot.sprintf.apply($.jqplot.sprintf, [str].concat(format));
return str;
}
}
Basically you get the Series and Point data and join it to an Html string with sprintf and then return the string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With