5

我正在尝试为折线图获取自定义工具提示,因为我希望工具提示更详细地描述点而不是该点的值。(附上的图片进一步解释了我在做什么)

我已经尝试过如何做到这一点。

下面是我的代码:

<script type="text/javascript">        $('#page3a').live('pageshow', function () {
        var s1 = [1, 2, 3, 4, 5];
        var s2 = ["Message 1", "Message 2", "Message 3", "Message 4", "Message 5"];

        var lineGraph1 = $.jqplot('lineGraph1', [s1,s2], {

            animate: true,
            seriesDefault: {
                showMarker: false,
                pointLabels: { show: true }
            },

            grid: {
                drawBorder: false,
                drawGridlines: false,
                background: '#eafaff',
                shadow: false
            },
            axesDefaults: {
                show: false,

                showTicks: false,
                showTickMarks: false

            },

            highlighter: {
                show: true,
                sizeAdjust: 8,
                tooltipLocation: 'n',
                tooltipAxes: 'piered',
               formatString:'%s',
                fadeTooltip: true,
                tooltipFadeSpeed: "fast",
                useAxesFormatters: false

            }

        });
    });</script>

任何帮助将不胜感激。:)

4

6 回答 6

7

有一个配置选项允许您提供一个自定义回调方法,该方法被调用以检索工具提示内容:

highlighter: {
    tooltipContentEditor: function (str, seriesIndex, pointIndex) {
        return str + "<br/> additional data";
    },

    // other options just for completeness
    show: true,
    showTooltip: true,
    tooltipFade: true,
    sizeAdjust: 10,
    formatString: '%s',
    tooltipLocation: 'n',
    useAxesFormatters: false,
}
于 2013-09-05T08:59:08.110 回答
3

我对 nick_w 的回答做了些微修改。但是我现在有了想要的效果,只是粘贴代码来帮助以后的其他人。

<script type="text/javascript">     

   $('#page3a').live('pageshow', function () {
          var s1 = [1, 2, 3, 4, 5];
          var s2 = ["Message 1", "Message 2", "Message 3", "Message 4", "Message 5"];

          var lineGraph1 = $.jqplot('lineGraph1', [s1, s2], {

              animate: true,
              seriesDefault: {
                  showMarker: false,
                  pointLabels: { show: true }
              },

              grid: {
                  drawBorder: false,
                  drawGridlines: false,
                  background: '#eafaff',
                  shadow: false
              },
              axesDefaults: {
                  show: false,

                  showTicks: false,
                  showTickMarks: false

              }
          });

          $('#lineGraph1').bind('jqplotDataMouseOver', function (ev, seriesIndex, pointIndex, data) {

              var mouseX = ev.mouseX; //these are going to be how jquery knows where to put the div that will be our tooltip
              var mouseY = ev.mouseY;
              $('#chartpseudotooltip').html(s2[pointIndex] );
              var cssObj = {
                  'position': 'absolute',
                  'font-weight': 'bold',
                  'left': mouseX + 'px', //usually needs more offset here
                  'top': mouseY + 'px',
                  'background-color': 'white',
                  'z-index':'1'
              };
              $('#chartpseudotooltip').css(cssObj);

          });

          $('#lineGraph1').bind('jqplotDataUnhighlight', function (ev) {
              $('#chartpseudotooltip').html('');
          });
      });</script>

要调用此脚本,将以下内容添加到我的内容 div 中。

<div id="lineGraph1" style="margin-top: 20px; margin-left: 160px; width: 350px; height: 350px">
        <div id="chartpseudotooltip"></div>
于 2013-02-15T10:24:55.817 回答
2

如果您总是希望在点值之前出现文本“消息”,则只需将其添加到 formatString 中:

highlighter:{
  show: true,
  formatString: 'Message %s',
  //other stuff like sizeAdjust...
}

如果它对应于您要显示的刻度,您也可以使用您的 s2 变量:

axes: {
   yaxis: {
       ticks: s2,
       tickRenderer: ...
   }
}
于 2013-02-13T13:54:36.807 回答
0

像这样的东西怎么样(改编自条形图上的 jqplot 工具提示)?

$('#lineGraph1').bind('jqplotDataMouseOver', function (ev, seriesIndex, pointIndex, data) {

    var mouseX = ev.pageX; //these are going to be how jquery knows where to put the div that will be our tooltip
    var mouseY = ev.pageY;
    $('#chartpseudotooltip').html(s2[pointIndex] + ', (' + data[0] +', ' + data[1] + ')');
    var cssObj = {
        'position' : 'absolute',
        'font-weight' : 'bold',
        'left' : mouseX + 'px', //usually needs more offset here
        'top' : mouseY + 'px',
        'background-color': 'white'
    };
    $('#chartpseudotooltip').css(cssObj);

});

$('#lineGraph1').bind('jqplotDataUnhighlight', function (ev) {
    $('#chartpseudotooltip').html('');
});

Message X, (x_value, y_value)当鼠标经过数据点时,这将绘制表单的小工具提示。然后,您可以进一步设置工具提示的样式以适应。

在此示例中,工具提示如下:

 <div id="chartpseudotooltip"></div>
于 2013-02-15T06:22:21.567 回答
0

你可以在这里得到答案jsfiddle

var line1=[['10/17/2013',21],['1/30/2014',3],['11/1/2013',12],['10/2/2013',3],['11/5/2013',18]];

   var line2=[['10/17/2013',41],['1/30/2014',33],['11/1/2013',12],['10/2/2013',63],['11/5/2013',18]];

var plot1 = $.jqplot('linegraph1', [line1,line2],{
  seriesDefaults: {
    lineWidth: 1,
     markerOptions: {
        show: true,             // wether to show data point markers.
        style: 'filledCircle',  // circle, diamond, square, filledCircle.
        size: 2            // size (diameter, edge length, etc.) of the marker.
    }},
    axes:{
      xaxis:{
        renderer:$.jqplot.DateAxisRenderer,

          tickOptions:{
            formatString:'%b&nbsp;%#d',
        showGridline: false
          }
      },
      yaxis:{min:0,numberTicks:25,
        tickOptions:{

        showGridline: false
          }
      }
    },
    legend :
    {
        "show" : true,
        location: 'se'
    },
    series : [
        {
            label : "line1",highlighter: {formatString: "<div style='text-align:center;'><span>%s </span><br/><span> Blue: %s <br/>custom tooltip<span></div>"}

        },
        {
            label : "line2",highlighter: {formatString: "<div style='text-align:center;'><span>%s </span><br/><span> Orange: %s <br/>custom tooltip<span></div>"},

        }
    ],
   highlighter: {
      show: true,
       sizeAdjust: 25.5,
       tooltipLocation: 's'
    }
  });
于 2014-02-08T10:59:30.273 回答
0
<script type="text/javascript">        $('#page3a').live('pageshow', function () {
        var s1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]];
        var s2 = [["Message 1"], ["Message 2"], ["Message 3"], ["Message 4"], ["Message 5"]];

        var lineGraph1 = $.jqplot('lineGraph1', [s1,s2], {


            seriesDefault: {
                showMarker: false,
                pointLabels: { show: true }
            },

            grid: {
                drawBorder: false,
                drawGridlines: false,
                background: '#eafaff',
                shadow: false
            },
            axes: {

                xaxis: {ticks: s2}


            },

                highlighter: {
                show: true,
                sizeAdjust: 8,
                tooltipLocation: 'n',
                tooltipAxes: 'x',
                formatString: '%s',


            }

        });
    });</script>
于 2013-02-14T13:58:47.010 回答