Jqplot - 荧光笔显示工具提示,其中包含来自多个y轴的数据

Yas*_*ser 0 javascript css jquery graph jqplot

我正在使用JqPlot.

这是我的小提琴,下面是我的截图.我使用两个y轴.在左边的y轴上我有我的收入,在我的右边y轴上我有我的页面浏览量.

现在悬停在线上,我想在工具提示中显示视图和收入,如下例所示,我一次只能从2个轴获取数据.

有什么想法吗 ?

在此输入图像描述

以下是我的代码

$(document).ready(function () {

  $.jqplot.config.enablePlugins = true;

  s1 = [['23-May-08',1, 11],['24-May-08',4, 14],['25-May-08',2, 22],['26-May-08', 6, 26]];
  s2 = [['23-May-08',11, 1],['24-May-08',14, 4],['25-May-08',22, 2],['26-May-08', 26, 6]];

  plot1 = $.jqplot('chart',[s1, s2],{
     title: 'Highlighting, Dragging, Cursor and Trend Line',
     axes: {
         xaxis: {
             renderer: $.jqplot.DateAxisRenderer,
             tickOptions: {
                 formatString: '%#m/%#d/%y'
             },
             numberTicks: 4
         },
         yaxis: {
             tickOptions: {
                 formatString: '$%.2f'
             }
         }
     },
     highlighter: {
         show:true,
     },
     cursor: {
         show: true
     },
      series: [
        {
            lineWidth: 2,
            highlighter: { formatString: "<div style='background-color:white; border:1px #ddd solid; width:220px; height:60px'>%s . Views : %s Revenue : %s </div>" }
        },
        {
            yaxis: 'y2axis',
            highlighter: { formatString: "<div style='background-color:white; border:1px #ddd solid; width:220px; height:60px'>%s . Views : %s Revenue : %s </div>" }
        }]
  });
});?
Run Code Online (Sandbox Code Playgroud)

Yas*_*ser 10

这是我做的,我使用的tooltipContentEditor属性highlighter.在这里查看更新的小提琴.

在此输入图像描述

series: [
{
    lineWidth: 2,
    highlighter: {
        show: true,
        tooltipContentEditor: function (str, seriesIndex, pointIndex, plot) {

            var date = plot.data[seriesIndex][pointIndex][0];
            var revenue = plot.data[seriesIndex][pointIndex][3];
            var views = plot.data[1][pointIndex][4];

            var html = "<div>Date : ";
            html += date;
            html += "  <br>Money : ";
            html += revenue;
            html += "  <br>Views : ";
            html += views;
            html += "  </div>";

            return html;
        }
    }
},
{
    yaxis: 'y2axis',
    highlighter: {
        show: true,
        tooltipContentEditor: function (str, seriesIndex, pointIndex, plot) {

            var date = plot.data[seriesIndex][pointIndex][0];
            var views = plot.data[seriesIndex][pointIndex][5];
            var revenue = plot.data[0][pointIndex][6];

            var html = "<div>Date : ";
            html += date;
            html += "  <br>Money : ";
            html += revenue;
            html += "  <br>Views : ";
            html += views;
            html += "  </div>";

            return html;
        }
    }
}]
Run Code Online (Sandbox Code Playgroud)