StackOverflow 評価グラフに非常によく似たフロート グラフを作成しています。データの鳥瞰的なレベルを示す小さなグラフがあり、範囲を選択してズームして大きなグラフに表示できます。いずれかのグラフをホバーすると、凡例のテキストが更新され、その x 位置の値が反映されます。
私が遭遇している2つの問題があり、コンソールなどにエラーがまったく見つかりません...
1: 「ズーマー」グラフで範囲を選択すると、大きい方の「詳細」グラフは適切に拡大されますが、x 値をホバーしたときに凡例テキストを更新するコードが機能しなくなります。ポイント アイテムのマウス オーバー (ツールチップが表示される) は引き続き機能し、2 つのコード ビットは同じイベント内にあります。変。
2: ズームインすると、日付の形式が乱れます。指定されているにもかかわらず、日付はタイムスタンプに戻さtimeformat
れます (実際には、ズームが行われる前の最初のプロットで機能します)。
実際の問題を示す短いスクリーンキャストを記録しました。
日付/時刻のフォーマットの問題を示す JSFiddle をセットアップしました。何らかの理由で、その環境では、ホバリング イベントが期待どおりに機能していません。
これら2つの問題を引き起こす何かが欠けていますか?
//doPlot is originally called where ranges=null. This plots the entire universe
//of data on both charts. Once a range is selected, this is called again with
//ranges
var plot=null;
var plot2=null;
var updateLegendTimeout = null;
var latestPosition = null;
var datasets=null;
var currRange=null;
function doPlot(ranges){
currRange=ranges;
clearTimeout(updateLegendTimeout);
updateLegendTimeout = null;
var options = { //Options for large graph
lines: { show: true },
points: { show: true },
grid: { hoverable: true, clickable: false, autoHighlight: false, backgroundColor: { colors: ["#fff", "#eee"] }, markings: weekendAreas },
xaxis: {mode: 'time', timeformat: "%m/%d", minTickSize: [1, "day"]},
crosshair: { mode: "x" },
legend: {
show: true,
container: $('#legend'),
noColumns: 2
}
};
var options2 = { //options for small zoomer graph
lines: { show: true },
points: { show: false },
grid: { hoverable: true, clickable: true, autoHighlight: false, backgroundColor: { colors: ["#fff", "#eee"] }, markings: weekendAreas },
xaxis: {mode: 'time', timeformat: "%m/%d", minTickSize: [1, "month"]},
crosshair: { mode: "x" },
selection: { mode: "x" },
legend: { show: false }
};
if (currRange){ //if there is a range specified, extend options to include it.
options = $.extend(options, {
xaxis: {
min: currRange.xaxis.from,
max: currRange.xaxis.to
}
});
}
//Plot Large Graph with (or without) given range
plot = $.plot($("#placeholder"), datasets,options);
//plot the zoomer graph, only if it is null (it is set to null before ajax request for new chart)
if (!plot2) {
plot2 = $.plot($("#zoomer"), datasets, options2);
$("#zoomer").unbind("plotselected").bind("plotselected", function (event, ranges) {
//unbind/re-bind plotselected event to zoom in when a range is selected
doPlot(ranges);
}).unbind("plothover").bind("plothover", function (event, pos, item) {
//unbind/re-bind plothover event to to show tooltips and to change legend values
latestPosition = pos;
if (!updateLegendTimeout)
updateLegendTimeout = setTimeout(function(){
updateLegend(plot2);
}, 50);
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
$("#tooltip").remove();
var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(2);
var text = item.series.label.split(' = ');
showTooltip(item.pageX, item.pageY,
text[0] + ' ('+y+')');
}
}
else {
$("#tooltip").remove();
previousPoint = null;
}
});
}
doBinds();
}
function doBinds(){
$("#placeholder").unbind("plothover").bind("plothover", function (event, pos, item) {
latestPosition = pos;
if (!updateLegendTimeout)
updateLegendTimeout = setTimeout(function(){
updateLegend(plot);
}, 50);
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
$("#tooltip").remove();
var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(2);
var text = item.series.label.split(' = ');
showTooltip(item.pageX, item.pageY,
text[0] + ' ('+y+')');
}
}
else {
$("#tooltip").remove();
previousPoint = null;
}
});
}