gpt4 book ai didi

javascript - Chart.js - (中间值).Doughnut 不是一个函数

转载 作者:行者123 更新时间:2023-11-29 15:27:43 30 4
gpt4 key购买 nike

我正在尝试使用 Chart Js 库生成圆环图,结果抛出错误 Uncaught TypeError: (intermediate value).Doughnut is not a function。我仔细检查了 js 文件链接,一切看起来都很好。有人之前遇到过这个问题吗?

这是我的代码:

function getPieChart(pAmt, iAmt, pFee) {


//pie chart code starts here


var data = [
{
value: pAmt,
color: "#F7464A",
highlight: "#FF5A5E",
label: "Principal Amount"
}, {
value: iAmt,
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Interest Amount"
}, {
value: pFee,
color: "#FDB45C",
highlight: "#FFC870",
label: "Processing Fee"
}];

var options = {
segmentShowStroke: true,
animateRotate: true,
animateScale: false,
percentageInnerCutout: 50,
segmentStrokeColor: "#fff",
tooltipTemplate: "<%= label%>: Rs.<%= converter(value) %>",
segmentStrokeWidth: 2,
legendTemplate: "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><div class=\"col-md-12\"><div class=\"emicleft col-md-6\"><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%=segments[i].label%></div><div class=\"emicright col-md-6\"><i class=\"fa fa-inr\"></i> <span class=\"emicrightspan\"><%=converter(segments[i].value)%></span></div></div></li><%}%></ul>"
};
var ctx = document.getElementById("emichart").getContext("2d");
var myChart = new Chart(ctx).Doughnut(data, options);
document.getElementById('js-legend').innerHTML = myChart.generateLegend();
}

最佳答案

如果您已切换到 chart.js v2,则会出现此错误,因为有一个新的语法。

这是一个link to the issue这是一个link to the new syntax .

这是一个例子:

var config = {
type: 'pie',
data: {
datasets: [{
data: [
pAmt,
iAmt,
pFee
],
backgroundColor: [
"#F7464A",
"#46BFBD",
"#FDB45C"
],
}],
labels: [
"Principal Amount",
"Interest Amount",
"Processing Fee"
]
},
options: {
responsive: true
}
};

window.onload = function() {
var ctx = document.getElementById("emichart").getContext("2d");
window.myPie = new Chart(ctx, config);
};

关于javascript - Chart.js - (中间值).Doughnut 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37627372/

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