![](/img/trans.png)
[英]%p for percent in stacked graph with jquery.flot.tooltip is not working
[英]jQuery flot graph plot tooltip
我有一個顯示如下的圖形:
我希望工具提示顯示“ 31/07的銷售額為1500英鎊”,而不是4。
我的x軸是這樣生成的:
xaxis: {
tickColor: 'transparent',
tickDecimals: 0,
ticks: [[1,'27/07'],[2,'28/07'],[3,'29/07'],[4,'30/07'],[5,'31/07'],[6,'01/08'],[7,'02/08']]
},
生成工具提示的代碼是:
function showTooltip(x, y, contents) {
jQuery('<div id="tooltip">' + contents + '</div>').css({
top: y - 16,
left: x + 20
}).appendTo('body').fadeIn();
}
var previousPoint = null;
jQuery('#graph-lines, #graph-bars').bind('plothover', function (event, pos, item) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
jQuery('#tooltip').remove();
var x = item.datapoint[0],
y = item.datapoint[1];
showTooltip(item.pageX, item.pageY, '£' + y + ' sales on ' + x);
}
} else {
jQuery('#tooltip').remove();
previousPoint = null;
}
});
重要的一行是:
var x = item.datapoint[0]
我怎樣才能讀取刻度線而不是值?
謝謝
我已經弄清楚了,我意識到我需要在數據點中保存x軸標簽:
var graphData = [{
// Shop
data: [ [1, 1300, '27/07'], [2, 1600, '28/07'], [3, 1700, '29/07'], [4, 1500, '30/07'], [5, 1500, '31/07'], [6, 1200, '01/08'], [7, 1000, '02/08'] ],
color: '#71c73e'
}, {
// Net
data: [ [1, 900, '27/07'], [2, 1100, '28/07'], [3, 1550, '29/07'], [4, 1600, '30/07'], [5, 1800, '31/07'], [6, 1400, '01/08'], [7, 1300, '02/08'] ],
color: '#77b7c5',
points: { radius: 4, fillColor: '#77b7c5' }
}
];
然后替換為:
var x = item.datapoint[0]
有了這個:
var x = item.series.data[item.dataIndex][2]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.