[英]ChartJs: Chart not display in VF page
I'm using Chart.Js to draw a scatter chart in VF page but in the preview, the chart is not displayed.我正在使用 Chart.Js 在 VF 页面中绘制散点图,但在预览中,图表未显示。 Not getting any errors but the chart is not displayed.
没有收到任何错误,但图表未显示。 Below is my VF page code.Appreciate your help
以下是我的 VF 页面代码。感谢您的帮助
<apex:page showHeader="true" sidebar="false" id="page" docType="html-5.0">
<html>
<head>
<meta charset="utf-8"/>
<title>Chart.js demo</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/0.2.0/Chart.min.js" type="text/javascript"></script>
</head>
<body>
<h1>Chart.js Sample</h1>
<canvas id="myChart" width="600" height="400"></canvas>
<script>
var ctx= document.getElementById("myChart").getContext("2d");
new Chart(ctx, {
type: 'scatter',
data: {
datasets: [{
label: 'Scatter Dataset',
backgroundColor: 'green',
data: [{
x: -10,
y: 0
}, {
x: 0,
y: 10
}, {
x: 10,
y: 5
}]
}]
},
options: {
scales: {
x: {
type: 'linear',
position: 'bottom'
}
}
}
});
</script>
</body>
</html>
</apex:page>
you are using a very old version of chart.js (as a matter of fact, the first ever released).您使用的是非常旧的 chart.js 版本(事实上,第一次发布)。
You could solve this by replacing:你可以通过替换来解决这个问题:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/0.2.0/Chart.min.js" type="text/javascript"></script>
with和
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.