如何在jqplot饼图上显示工具提示
How to display tooltips on jqplot pie chart
我有一个带有图例的jqplot饼图,我想让图例文本在鼠标悬停在饼上时显示为工具提示。我不知道该怎么做。有人有类似的经验吗?
示例代码:
$(document).ready(function(){
var data = [['Heavy Industry', 12],['Retail', 9], ['Light Industry', 14],['Out of home', 16],['Commuting', 7], ['Orientation', 9]];
var plot1 = jQuery.jqplot ('chart1', [data],
{
seriesDefaults: {
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
showDataLabels: true
}
},
legend: { show:true, location: 'e' }
}
);
});
我使用的是最新版本的jqPlot,并通过在"seriesDefaults"部分中使用以下内容来获得工具提示:
highlighter: {
show: true,
formatString:'%s',
tooltipLocation:'sw',
useAxesFormatters:false
}
重要的部分是"useAxesFormatters: false",因为饼图中没有轴。您可以随意更改"formatString"为您想要的任何内容,但对我来说,只是"%s"显示的是与图例中显示的完全相同的字符串。
您需要绑定jqplot数据高亮显示和取消高亮显示事件,获取您想要显示的数据并设置包含div标题属性的图表。
下面的代码显示了"x: y"格式的标题,其中x是图例标签,y是值:
var plot = $.jqplot('plotDivId',...);
$("#plotDivId").bind('jqplotDataHighlight', function(ev, seriesIndex, pointIndex, data) {
var $this = $(this);
$this.attr('title', data[0] + ": " + data[1]);
});
$("#plotDivId").bind('jqplotDataUnhighlight', function(ev, seriesIndex, pointIndex, data) {
var $this = $(this);
$this.attr('title',"");
});
这段代码正在我的系统中使用,运行正常
我在以下链接上使用的是荧光笔插件的版本:
https://github.com/tryolabs/jqplot-highlighter我使用的参数:
highlighter: {
show:true,
tooltipLocation: 'n',
tooltipAxes: 'pieref', // exclusive to this version
tooltipAxisX: 20, // exclusive to this version
tooltipAxisY: 20, // exclusive to this version
useAxesFormatters: false,
formatString:'%s, %P',
}
新参数确保工具提示出现的固定位置。我更喜欢把它放在左上角,以避免在调整容器div大小时出现问题。
我不相信这是内置的。您需要将处理程序绑定到'jqplotDataHighlight'和'jqplotDataUnhighlight'事件。请参阅本页底部的示例。这是对气泡图的处理,但它也应该转化为饼图。
由于我无法让荧光笔工作-它在饼图上没有为我显示任何内容-我最终采用了基于荧光笔事件显示浏览器工具提示的解决方案。
var plot1 = jQuery.jqplot ('chart1', [data], {
seriesDefaults: {
renderer: jQuery.jqplot.PieRenderer
}
}
);
$('#chart1').bind('jqplotDataHighlight', function (ev, seriesIndex, pointIndex, data) {
document.getElementById('chart1').title = data;
//alert('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
});
相关文章:
- Highcharts-在单击而不是悬停时显示工具提示
- C3.js通过单击按钮显示工具提示
- 未单击按钮时显示工具提示
- 高图表在点单击时显示工具提示
- Flexslider-当鼠标悬停在点上时显示工具提示
- 高亮显示工具提示共享项,具体取决于Highcharts中悬停的系列
- 显示工具提示而不双击字段
- 在 Twitter 引导程序中自动显示工具提示,而无需放置光标
- 悬停时显示工具提示
- 隐藏 x 轴标签,但在图表.js中显示工具提示
- 突出显示工具提示中未显示名称的 3D 散点
- 如何在图像库森时更改颜色和显示工具提示
- q提示 2 - 鼠标按下以显示工具提示?鼠标向上隐藏
- D3.js水平折线图无法正确显示工具提示
- 在 d3.js 折线图中永久显示工具提示
- 如何在 SVG 上的鼠标光标旁边显示工具提示,尽管网站上有非 SVG 元素
- 高图表在类别标签悬停时显示工具提示
- 仅在完全创建时显示工具提示
- 鼠标输入时未显示工具提示
- 鼠标悬停时无法显示工具提示,jQuery1.11