gpt4 book ai didi

javascript - qtip工具提示中的图表?

转载 作者:太空宇宙 更新时间:2023-11-04 03:27:38 24 4
gpt4 key购买 nike

我试图在 qtip 工具提示中包含一个图表,但该图表没有显示在工具提示中。我已经为工具提示制图区域指定了一个自己的 ID,但该区域中没有显示图表。

有一个earlier posting在 Stack Overflow 上,它解决了同样的问题,但该解决方案没有提供足够的细节让我正确应用它。同样在 qtip help forum 上.

我做了一个 fiddle 来展示我的问题。有一个普通的工具提示,然后是一个应该包含图表(但实际上没有)的工具提示。

Fiddle here

我也会贴出相关代码:

HTML:

<body>

Hello
<div id="hello1"></div>

<br style="margin-bottom: 50px;" />

<div id="hello2">Hello again!</div>

<br style="margin-bottom: 30px;" />

</body>

CSS:

#hello1,
#hello2{
height: 100px;
width: 200px;
}

#tooltipchart{
height: 100px;
width: 200px;
}

Javascript:

$('#hello1').qtip({ // Grab some elements to apply the tooltip to
content: { text: 'Here is a chart!'},
position: { target: 'mouse' }
})

$('#hello2').qtip({
content: { text: "No chart inside the tooltip :(" },
position: { target: 'mouse' },
api:{onShow: function(){return tooltipcontent();}}

})

function tooltipcontent(){
var div = document.createElement("div");
div.setAttribute("id", "tooltipchart");
div.setAttribute("height", "100px");
div.setAttribute("width", "100px");
return div;
}

$(document).ready(function(){
var plot1 = $.jqplot('hello1', [
[[4,1], [7,2], [1,3], [2,4]]], {
seriesDefaults: {
pointLabels: { show: true}
}
});

var plot2 = $.jqplot('tooltipchart', [
[[4,1], [7,2], [1,3], [2,4]]], {
seriesDefaults: {
pointLabels: { show: true}
}
});

});

请指教如何解决这个问题。

最佳答案

您首先创建元素,然后抓取它以在工具提示中显示。如果您在 jsfiddle 中复制下面的代码,它应该可以工作:

$('#hello1').qtip({ // Grab some elements to apply the tooltip to
content: { text: 'Here is a chart!'},
position: { target: 'mouse' }
})

$('#hello2').qtip({
content: function(){return tooltipcontent();},
position: { target: 'mouse' },
api:{onShow: function(){return tooltipcontent();}}

})

function tooltipcontent(){
return $("#tooltipchart").css('display','');
}

$(document).ready(function(){
var plot1 = $.jqplot('hello1', [
[[4,1], [7,2], [1,3], [2,4]]], {
seriesDefaults: {
pointLabels: { show: true}
}
});

var div = document.createElement("div");
div.setAttribute("id", "tooltipchart");
div.setAttribute("height", "100px");
div.setAttribute("width", "100px");
$('body').append(div);
var plot2 = $.jqplot('tooltipchart', [
[[4,1], [7,2], [1,3], [2,4]]], {
seriesDefaults: {
pointLabels: { show: true}
}
});
$("#tooltipchart").css('display','none')

});

关于javascript - qtip工具提示中的图表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26845208/

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