我目前正在努力改进JavaScript,我决定挑战自己创建一个可以跟踪股票投资组合的网站。我已经设法用Chart.js和HTML / CSS获得我想要的图表,但现在的挑战是让它以“实时”的方式提取有关股票价格的信息。所以我面临的问题是我想要将我的图表更改为基于在线提供的价格信息,而不是每次我想要更新它时都要通过编写新的数据点来自行更新!下面是我用于图表的代码!
<script src="Chart.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"> .
</script>
<script>
var ctx = document.getElementById("portChart").getContext("2d");
var chart = new Chart(ctx, {
width: 200,
height: 200,
type: "line",
data: {
labels: ["October", "November", "December", "January", "February", "March", "April"],
datasets: [{
label: "My First Portfolio",
backgroundColor: "white",
borderColor: "black",
fill: false,
data: [100, 93, 94, 100, 110, 111, 116],
}, {
label: "OSEBX",
backgroundColor: "white",
borderColor: "red",
fill: false,
data: [100, 101, 101, 105, 100, 103, 105],
}
]
},
options: {}
});
</script>
很抱歉这个真正的noob问题,但我有点卡住,所以我真的很感激任何有关哪种方式的投入!