jqPlot显示带有光标的自定义工具提示

jqPlot displaying custom tooltip with cursor

本文关键字:自定义 工具提示 光标 显示 jqPlot      更新时间:2023-09-26

我使用Cursor插件在jqplot图表上显示一条竖线。光标插件的工具提示显示了X和Y值。

我想在plot points中添加一个元数据。

[x,y,1337]其中1337为元数据。

我想修改光标插件的工具提示,以显示这个元数据以及它已经显示的数据。

用例:我有多个系列,所有系列的趋势都缩放到0-100。我需要显示未缩放的值

更新:

我已经得到了它的工作通过破解jqplot.cursor.js,有更好的方法吗?

Line 468: function updateToolTip(gridpos, datapos, plot){
              // ...
              s += $.jqplot.sprintf(c.tooltipFormatString, label, sx, sy, data[2]);

这就是我如何覆盖tooltipContentEditor jqplot函数,它工作得很好。

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;
                    }
               }

基本上你得到系列和点的数据,并与sprintf连接到一个Html字符串,然后返回字符串