我试图在引导旋转木马中动态地在同一页面上创建高级图表。
我有一个像这样的函数"createChart“:
createChart(questiontitle, answers);
function createChart(questiontitle, answers){
chart = new Highcharts.Chart(options); // Create new chart with general options
chart.renderTo(container);
for (var i = 0; i < answers.length; i++) {
categories.push(answers[i].Text);
}
console.log(categories);
chart.xAxis[0].setCategories(categories);
chart.setTitle({ text: 'eerzera' });
// redraw chart
chart.redraw();
}
我有一个这样的div:
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
正如您所看到的,我有"chart.renderTo“,但我总是得到相同的错误:
高图表错误#13 未找到呈现div 如果chart.renderTo选项被错误地混淆了,从而无法找到要呈现图表的HTML,则会发生此错误。
我的可变选项如下:
var options = {
chart: {
type: 'bar'
},
subtitle: {
text: 'Source: Wikipedia.org'
},
xAxis: {
categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Population (millions)',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
valueSuffix: ' millions'
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: '#FFFFFF',
shadow: true
},
credits: {
enabled: false
},
series: [{
name: 'Year 1800',
data: [107, 31, 635, 203, 2]
}, {
name: 'Year 1900',
data: [133, 156, 947, 408, 6]
}, {
name: 'Year 2008',
data: [973, 914, 4054, 732, 34]
}]
}
这怎麽可能?
发布于 2013-09-11 11:05:55
如果您的目标是保持这种动态,通过能够构建多个具有多个呈现的图表,但使用相同的选项,您可以这样做:
变化
function createChart(questiontitle, answers){
chart = new Highcharts.Chart(options);
chart.renderTo(container);
至:
function createChart(questiontitle, answers){
chart = $('#container').highcharts(options);
或者,如果不使用jQuery,
function createChart(questiontitle, answers){
options.chart.renderTo = 'container';
chart = new Highcharts.Chart(options);
发布于 2014-02-08 13:51:44
当您在renderTo
中指定元素时,如果该元素是ID,则不应该包含该元素。
如果您有这个元素<div id="graph-container"></div>
这失败了:renderTo: '#graph-container'
这工作:renderTo: 'graph-container'
发布于 2013-09-11 05:22:33
类似于这样的情况:chart.renderTo(container);
并不存在于高图表中。
若要设置renderTo
,请使用以下选项:
var options = {
chart: {
type: 'bar',
renderTo: 'container'
},
https://stackoverflow.com/questions/18742065
复制相似问题