2016-12-20 4 views
2

Я сделал несколько графиков с возможностью размещения метки внутри, но я не понимаю, как сделать метку нависшей с величиной оси y.диаграмма флоат-диаграмма нависшая маркировка

$.plot($("#[email protected]"), [email protected], { 
     series: { 
      lines: { 
       lineWidth: 2, 
       fill: @((Model.Series.Count() == 1).ToString().ToLower()), 
      }, 
      bars: { 
       barWidth: 0.6, 
       align: "center" 
      }, 
      points: { 
       fill: @((Model.Series.Count() == 1).ToString().ToLower()), 
      } 
     }, 
     xaxis: { 
      ticks: [email protected], 
      tickDecimals: 0 
     }, 
     colors: @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.Series.Select(o => o.Color).ToArray())), 
     grid: { 
      color: "#999999", 
      hoverable: true, 
      clickable: true, 
      borderWidth: 0, 
      @if (Model.LimitLine != null) 
      { 
       <text> 
        markings: [ 
         { color: '#000', lineWidth: 1, yaxis: { from: @Model.LimitLine, to: @Model.LimitLine }}, 
        ] 
       </text> 
      } 
      }, 
     legend: { 
      show: true 
     }, 
     tooltip: true, 
     tooltipOpts: { 
      content: function(label, xval, yval) { 
       var content = [email protected](ControlID)(xval) + ": " + yval; 
       return content; 
      }, 
     } 
    }); 

Как я могу показать всплывающую подсказку со значением?
Graph пример:

enter image description here

ответ

1

Вы не можете сделать это с помощью всплывающих подсказок плагина, но это возможно, когда делать всплывающие подсказки самостоятельно. Что-то вроде этого:

$("#placeholder").bind("plothover", function (event, pos, item) { 
    if (item) { // hovering over a datapoint 
     var x = item.datapoint[0].toFixed(2), 
      y = item.datapoint[1].toFixed(2); 

     $("#tooltip").html(item.series.label + " of " + x + " = " + y) 
      .css({top: item.pageY+5, left: item.pageX+5}).fadeIn(200); 
    } else { 
     var hideTooltip = true; 

     // you need to save the Flot object for this (here as "plot") 
     $.each(plot.getOptions().grid.markings, function(idx, marking) { 
      if (Math.abs(pos.y - marking.yaxis.to) < 10) { 
       $("#tooltip").html("Limit: " + marking.yaxis.to) 
        .css({top: pos.pageY + 5, left: pos.pageX + 5}).fadeIn(200); 
       hideTooltip = false; 
       return false; 
      } 
     }); 

     if (hideTooltip) { 
      $("#tooltip").hide(); 
     } 
    }  
}); 

Основано на этом example.

+0

Если '' 'item''' является null, false или undefined, как вы, супруг, имеете доступ к свойствам' '' pageY''' и '' 'pageX'''? – adripanico

+0

На самом деле решение практически отсутствует. Вместо '' 'item.pageX''' и' '' item.pageY''', вы должны получить доступ к '' 'pos.pageX''' и' '' pos.pageY'''. Кроме того, вам может понадобиться играть с порогом (жестко закодированным «10») в зависимости от масштаба оси x. – adripanico

+0

@adripanico Вы правы, спасибо за подсказку. – Raidri

Смежные вопросы