我试图打开一个对话窗口,每当饼图切片在JQPlot饼图中点击。我尝试了很多不同的方法来尝试使这个工作,但没有运气。我知道它需要绑定到jqplotDataClick函数,但我无法以这种方式得到它。如何使用jqplotDataClick从jqplot饼图打开对话框?
这里是我的图表脚本:
$(document).ready(function(){
plot1 = $.jqplot('chart1', [[[2,1], [4,2], [6,3], [3,4]]], {
seriesDefaults: {
// Make this a pie chart.
renderer: jQuery.jqplot.DonutRenderer,
rendererOptions: {
// Put data labels on the pie slices.
// By default, labels show the percentage of the slice.
showDataLabels: true
}
},
legend: { show:false, location: 'e' },
grid: {background:'transparent', borderColor: 'none', shadow: false}
}
);
plot1 = $.jqplot('chart2', [[[2,1,'medical.htm'], [4,2,'link1.html'], [6,3,'link1.html'], [3,4,'link1.html']]], {
seriesDefaults: {
// Make this a pie chart.
renderer: jQuery.jqplot.DonutRenderer,
rendererOptions: {
// Put data labels on the pie slices.
// By default, labels show the percentage of the slice.
showDataLabels: true
}
},
legend: { show:false, location: 'e' },
grid: {background:'transparent', borderColor: 'none', shadow: false}
}
);
plot1 = $.jqplot('chart3', [[[2,1], [4,2], [6,3], [3,4]]], {
seriesDefaults: {
// Make this a pie chart.
renderer: jQuery.jqplot.DonutRenderer,
rendererOptions: {
// Put data labels on the pie slices.
// By default, labels show the percentage of the slice.
showDataLabels: true
}
},
legend: { show:false, location: 'e' },
grid: {background:'transparent', borderColor: 'none', shadow: false}
}
);
plot1 = $.jqplot('chart4', [[[2,1], [4,2], [6,3], [3,4]]], {
seriesDefaults: {
// Make this a pie chart.
renderer: jQuery.jqplot.DonutRenderer,
rendererOptions: {
// Put data labels on the pie slices.
// By default, labels show the percentage of the slice.
showDataLabels: true
}
},
legend: { show:false, location: 'e' },
grid: {background:'transparent', borderColor: 'none', shadow: false}
}
);
$('#chart1, #chart2, #chart3, #chart4').bind('jqplotDataHighlight',
function (ev, seriesIndex, pointIndex, data) {
$('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data+ ', pageX: '+ev.pageX+', pageY: '+ev.pageY);
}
);
$('#chart1, #chart2, #chart3, #chart4').bind('jqplotDataClick',
function (ev, seriesIndex, pointIndex, data) {
$("#medical1").html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
//alert();
/* To open in a NEW window use: */
/* window.open(data[2]); */
/* To open in the same window use: */
//window.location.href=neighbor.data[2];
}
);
$('#chart1, #chart2, #chart3, #chart4').bind('jqplotDataUnhighlight',
function (ev) {
$('#info1').html('Nothing');
}
);
});
这是对话的脚本。该对话框打开一个应该与饼图切片一致的窗口。前提是 - 我有一个饼图,由用户通过选择出现在对话窗口中的选项提交的数据组成。一旦饼图由这些数据组成,用户就可以点击饼图并为每个切片打开一个对话框窗口,以更改图表该部分的选项。
<script type="text/javascript">
$(document).ready(function() {
var $loading = $('<img src="img/loading.gif" alt="loading" class="loading">');
$('#prod-dialog td a').each(function() {
var $dialog = $('<div></div>')
.append($loading.clone());
var $link = $(this).one('click', function() {
var $cnt = $(this).attr('href') + " #" + $(this).attr('id')
$dialog
.load($cnt)
.dialog({
title: $link.attr('title'),
width: 300,
height: 200,
buttons: [
{
text: "Ok",
click: function() {
$(this).dialog("close");
}
},
{
text: "Cancel",
click: function() {
$(this).dialog("close");
}
}
]
});
$link.click(function() {
$dialog.dialog('open');
return false;
});
return false;
});
});
});
这是HTML的一个类别,按钮打开一个对话框窗口的一部分 - 还有更多的这些,但太多的代码放在这里了。
<table id="prod-dialog">
<tr>
<td><div><img src="img/medical-icon.png" />
<p>Medical</p>
</div></td>
<td><a href="medical.htm" title="Medical 1" id="medical1"><img src="img/dialog-icon_08.png"/></a></td>
</tr>
</table>
那究竟是不是在这里工作? – 2013-03-19 20:40:49
@nick_w - 我试图得到一个jQuery对话框窗口,每当点击一个饼图片。 – 2013-03-19 20:48:05
啊,那个'#info1'对话框呢?无论哪种方式,你可以发布任何对话框相关的HTML你现在有吗? – 2013-03-19 20:57:27