gpt4 book ai didi

javascript - C3 图表 - 工具提示的内容可点击

转载 作者:搜寻专家 更新时间:2023-11-01 04:15:36 25 4
gpt4 key购买 nike

我正在使用 c3.js 制作图表.我必须使工具提示的内容可调用。到目前为止,只有当我将鼠标悬停在图表上时,工具提示才可见。我有一些信息,当我点击工具提示中的链接时会显示这些信息。我无法从 c3 documentation 找到任何帮助.我正在处理的代码片段如下所示。

$scope.timelineConfig.tooltip.contents = function (data, defaultTitleFormat, defaultValueFormat, color) {
var $$ = this, config = $$.config,
titleFormat = config.tooltip_format_title || defaultTitleFormat,
nameFormat = config.tooltip_format_name || function (name) { return name; },
valueFormat = config.tooltip_format_value || defaultValueFormat,
text, i, title, value;
text = "<div id='tooltip' class='d3-tip'>";
title = dates[data[0].index];
text += "<span class='info'><b><u>Date</u></b></span><br>";
text += "<span class='info'>"+ title +"</span><br>";
text += "<span class='info'><b><u>Features</u> : </b> " + features[data[0].index] + "</span><br>";
text += "<span class='info'><b><u>Enhancements</u> : </b> " + defects[data[0].index] + "</span><br>";
text += "</div>";
return text;
};

我必须使内容 ( <span><b><u>Features...</u></b></span>) 可点击。

最佳答案

首先(如果您还没有这样做的话)覆盖工具提示位置,这样当您尝试单击它时它就不会一直跑掉。

tooltip: {
position: function () {
var position = c3.chart.internal.fn.tooltipPosition.apply(this, arguments);
position.top = 0;
return position;
},

然后您需要覆盖 hideTooltip 函数,以便它不会在检测到您的点击事件之前关闭。

var originalHideTooltip = chart.internal.hideTooltip
chart.internal.hideTooltip = function () {
setTimeout(originalHideTooltip, 100)
};

然后,您只需重写pointer-events 样式(这样鼠标事件就不会被忽略),然后像通常在 jQuery 中那样附加处理程序

$(".c3-tooltip-container")
.css("pointer-events", "auto")
.on('click', '.info:eq(2)', function () {
// add click functionality here. you could pass in additional data using the span attributes
alert($(this).text())
})

根据需要修改选择器(比如添加图表包装器 ID...)


fiddle - http://jsfiddle.net/5vbeb4k8/

关于javascript - C3 图表 - 工具提示的内容可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31532349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com