我有正常工作的情况如下:将HighCharts渲染为类而不是id?
$(document).ready(function() {
get_data_for_chart();
function get_data_for_chart() {
$.ajax({
url: 'get_data.aspx?rand=' + Math.random(),
type: 'GET',
dataType: 'json',
error: function(xhr, status, error) {
console.log(status);
console.log(xhr.responseText);
},
success: function(results) {
var chart1;
chart1 = new Highcharts.Chart({
chart: {
renderTo: 'portlet_content_18',
defaultSeriesType: 'column'
}
});
}
});
}
});
凡HTML看起来是这样的:
<div id="portlet_content_18">
用户可以动态地选择其中portlet
他/她想要在屏幕上。出于比较的原因,他/她也可以选择在屏幕上多次使用相同的portlet
。
因此,如果HTML最终成为:
<div id="portlet_content_18">
<div id="portlet_content_18">
只有第一div
被填充与图表,而第二个保持空白。我怎样才能解决这个问题?
你不能有多个ID,但你可以尝试'class'。将其更改为class =“port-18”,并确保在“成功”上更新它。 –