【发布时间】:2018-03-06 16:39:38
【问题描述】:
我们在实时数据浮动的环境中使用 c3 图表库的条形图功能。这确实导致了一个问题,即如果用户将鼠标悬停在条形上方条形本身确实更新但工具提示没有更新 已显示。有没有办法更新/重新加载工具提示?
@更新 1: 回复较晚,抱歉。基本上我们有一个观察者来监听数据的变化。这将触发一个名为 reload 的方法,该方法具有以下几行(数据如何显示在 cmets 中):
chart.load({
xs: xs, // AmberViolation:"facilityId",BlueViolation:"facilityId",RedViolation:"facilityId"
columns: columns, // [["facilityId", "SUB-GTW"],["RedViolation", 0],["BlueViolation", 2],["AmberViolation", 0]]
unload: _.difference(drawnChartYCols, nextDrawColumns),
types: types, // AmberViolation:"bar",BlueViolation:"bar",RedViolation:"bar"
colors: colors,
done: function () {
if (columns.length && columns[0].length > 10) {
chart.zoom([0, 11]);
d3.select(element[0]).selectAll('svg > g').filter(function(d, i) { return i === 1 }).attr('display', null);
chart.resize({width: $scope.width, height: $scope.height});
d3.select(element[0]).select('.extent').attr('x', 0);
} else {
chart.unzoom();
d3.select(element[0]).selectAll('svg > g').filter(function(d, i) { return i === 1 }).attr('display', 'none');
chart.resize({width: $scope.width, height: $scope.height + 70});
}
}
});
chart.groups([groups]);// ["RedViolation","BlueViolation","AmberViolation"]
@更新 2:
您甚至可以在 http://c3js.org/samples/chart_bar_stacked.html 上看到这种行为。 在更新数据时将鼠标悬停在其中一个栏上,然后让鼠标停留在那里。工具提示不会更新。只有再次移动鼠标才会刷新。
@Update 3:由于即使在 c3 图表的示例上也会发生这种情况,我在 Github 上创建了一个错误:https://github.com/c3js/c3/issues/2307
【问题讨论】:
-
您是否在图表上使用
.load(args)来加载传入的新数据? c3js.org/reference.html#api-load -
是的,我们使用chart.load并用它更新xs、columns、unload、types和colors。
-
如果您包含一个最小、完整且可验证的示例来解决您的问题stackoverflow.com/help/mcve,您可能会在此问题上获得更多帮助
-
请查看c3js.org/samples/chart_bar_stacked.html 并在更新数据时将鼠标悬停在其中一个栏上并让鼠标停留在那里。您会看到工具提示不会更新。
标签: javascript angularjs c3.js