flot chart plothover事件触发,但条形图中的项始终为空
flot chart plothover event fires but item is always null in bar chart
我使用flot图表在shoppimon.com上显示随时间推移的问题发生数据。当使用折线图时,我的flothover函数工作得很好,但一旦切换到条形图,工具提示就会停止显示。调试时,我在flothover回调内部中断,这意味着事件正在激发,但"item"参数始终为null。
如有任何建议,不胜感激。
这是我的代码:
renderChart : function(containerId) {
setTimeout(function(){
var data = chartServer.getData(containerId);
var container = $('#' + containerId);
if (window.localStorage && window.localStorage['cbMode'] == 'true') {
data.options.colors = chartClient.cbColors;
} else {
data.options.colors = chartClient.chartColors;
}
container.before('<div id="' + containerId + '-controls" class="chart-controls group"> '
<div class="chart-legend" /> ');
//Plot the chart
var chart = $.plot(container, data.dataSet, data.options);
container.bind('plothover', chartClient.hoverFunction);
container.bind('plotclick', chartClient.clickFunction);
container.bind('plothover', function(event, pos, item) {
if (item) {
$(event.target).css({cursor:"pointer"});
} else {
$(event.target).css({cursor:"auto"});
}
});
}, 100);
},
hoverFunction : function(event, pos, item) {
if (item) {
if (chartClient.previousPoint != item.dataIndex) {
chartClient.previousPoint = item.dataIndex;
$("#chart-tooltip").remove();
var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(0);
var date = new Date(parseInt(x, 10));
date.add({minutes: Date.today().getTimezoneOffset()}); // compensate for local TZ
var contents = date.toString("MMM d ") + date.toString("t") + "<br />" + y + " times";
$('<div id="chart-tooltip">' + contents + '</div>').css({
top: item.pageY + 5,
left: item.pageX + 5
}).appendTo("body").fadeIn(200);
}
} else {
$("#chart-tooltip").remove();
chartClient.previousPoint = null;
}
},
这是我的选项对象:
Object {xaxis: Object, grid: Object, legend: Object, series: Object, colors: Array[5]}
colors: Array[5]0: "#0073B5"1: "#6A4A3C"2: "#CC333F"3: "#EB6841"4: "#EDC951"
length: 5
grid: Object
borderColor: "#EDEDED"
borderWidth: 1
clickable: true
hoverable: true
legend: Object
container: "#occurrence-chart-39631-controls .chart-legend"
noColumns: 1
series: Object
bars: Object
fill: true
show: true
xaxis: Object
mode: "time"
因此,为了在flotHover事件处理程序中获取项目对象,您必须使用以下"点"选项将数据点包括在图表中:
$options['grid']['clickable'] = true;
$options['grid']['hoverable'] = true;
$options['series'] = array(
'bars' => array('show' => true),
'points' => array('show' => true, 'radius' => 0, 'symbol' => 'square')
);
如果你想避免显示这些点,你可以像我一样使用0的半径。悬停函数仍然有效,项对象存在于回调中,但对图表栏没有可见的更改。
相关文章:
- 用chart.js绘制条形图
- d3.js用按钮更新条形图工具提示
- 添加新数据时D3.JS条形图列偏移量
- Chart.js条形图:网格颜色和隐藏标签
- 在条形图中呈现数据AngularJS,如何制作一个好的多条形图
- Chart.js 2.1.2条形图动画问题
- 如何在Extjs5中更改条形图的标签
- d3.js条形图转换无法正常工作
- 从数组在d3中创建条形图时出现问题
- 条形图元素的HTML5 JavaScript锚点
- d3.js组条形图不起作用
- 图表.js:条形图点击事件
- 如何使用chartjs设置条形图中每个条形图的颜色
- Raphael.js条形图及教程
- 对d3堆叠条形图的数据进行排序
- Javascript FLOT组合条形图;以x轴为字符串的折线图
- d3.js条形图未根据单击事件进行更新
- Chart.js条形图标签在悬停时被隐藏
- D3:如何更改现有条形图中的数据
- flot chart plothover事件触发,但条形图中的项始终为空