我对使用 canvasjs 图表插件相当陌生。有一个要求,我必须将图表容器的大小调整为特定的宽度。在将宽度从 100% 更改为 300px 时,我在 IE 和 chrome 上收到以下错误:recursionCount is undefined。以下是我正在使用的相同代码片段:
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",
{
title:{
text: "Common Names"
},
exportFileName: "Pie Chart",
exportEnabled: true,
animationEnabled: true,
legend:{
verticalAlign: "bottom",
horizontalAlign: "center"
},
data: [
{
type: "pie",
showInLegend: true,
toolTipContent: "{legendText}: <strong>{y}%</strong>",
indexLabel: "{label} {y}%",
dataPoints: [
{ y: 732, legendText: "James", exploded: true, label: "James" },
{ y: 4, legendText: "West", label: "West" },
{ y: 3, legendText: "John", label: "John" },
{ y: 247, legendText: "Peter", label: "Peter"},
{ y: 2716, legendText: "Mark", label: "MArk" },
{ y: 2, legendText: "Luke", label: "Luke"}
]
}
]
});
chart.render();
var chart1 = new CanvasJS.Chart("chartContainer1",
{
title:{
text: "Top Categoires of New Year's Resolution"
},
exportFileName: "Bar Graph",
exportEnabled: true,
animationEnabled: true,
legend:{
verticalAlign: "bottom",
horizontalAlign: "center"
},
data: [
{
type: "bar",
showInLegend: true,
toolTipContent: "{legendText}: <strong>{y}%</strong>",
indexLabel: "{label} {y}%",
dataPoints: [
{ y: 35, legendText: "Health", exploded: true, label: "Health" },
{ y: 20, legendText: "Finance", label: "Finance" },
{ y: 18, legendText: "Career", label: "Career" },
{ y: 15, legendText: "Education", label: "Education"},
{ y: 5, legendText: "Family", label: "Family" },
{ y: 7, legendText: "Real Estate", label: "Real Estate"}
]
}
]
});
chart1.render();
var chart2 = new CanvasJS.Chart("chartContainer2",
{
theme: "theme2",
title:{
text: "Earthquakes - per month"
},
animationEnabled: true,
axisX: {
valueFormatString: "MMM",
interval:1,
intervalType: "month"
},
axisY:{
includeZero: false
},
data: [
{
type: "line",
//lineThickness: 3,
dataPoints: [
{ x: new Date(2012, 00, 1), y: 450 },
{ x: new Date(2012, 01, 1), y: 414},
{ x: new Date(2012, 02, 1), y: 520, indexLabel: "highest",markerColor: "red", markerType: "triangle"},
{ x: new Date(2012, 03, 1), y: 460 },
{ x: new Date(2012, 04, 1), y: 450 },
{ x: new Date(2012, 05, 1), y: 500 },
{ x: new Date(2012, 06, 1), y: 480 },
{ x: new Date(2012, 07, 1), y: 480 },
{ x: new Date(2012, 08, 1), y: 410 , indexLabel: "lowest",markerColor: "DarkSlateGrey", markerType: "cross"},
{ x: new Date(2012, 09, 1), y: 500 },
{ x: new Date(2012, 10, 1), y: 480 },
{ x: new Date(2012, 11, 1), y: 510 }
]}]
});
chart2.render();
}
</script>
<script type="text/javascript" src="canvasjs.min.js"></script>
</head>
<body>
<div id="chartContainer" style="height: 300px; width: 300px;"></div>
<div id="chartContainer1" style="height: 300px; width: 100%;"></div>
<div id="chartContainer2" style="height: 300px; width: 100%;"></div>
</body>
</html>
我不明白如何将元素 id:chartContainer 的宽度从 100% 更改为 300px 会导致这样的错误...
提前致谢。