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
<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 に答える
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 に答える