我创建了一个图表,该图表使用chart.js中的按钮进行更新。我将如何保存该数据,以使其在刷新后保持不变?我正在计划建立一个基本的用户系统,以便每个人在购买或出售时都具有余额。 (不必只是基本的身份识别系统就必须非常安全)。
链接到我的代码: https://jsfiddle.net/JB123/bogejacf/
window.onload = function() {
var chart = new CanvasJS.Chart("chartContainer", {
title: {
text: "Stock"
},
data: [{
type: "spline",
dataPoints: [{
y: 100
},
{
y: 90
},
{
y: 80
},
{
y: 70
}
]
}]
});
chart.render();
$("#buy").click(function() {
var length = chart.options.data[0].dataPoints.length;
chart.options.title.text = "New DataPoint Added at the end";
chart.options.data[0].dataPoints.push({
y: (chart.options.data[0].dataPoints[length - 1].y) + (chart.options.data[0].dataPoints[length - 1].y) / 50
});
chart.render();
});
$("#sell").click(function() {
var lastpoint = chart
var length = chart.options.data[0].dataPoints.length;
chart.options.title.text = "New DataPoint Added at the end";
chart.options.data[0].dataPoints.push({
y: (chart.options.data[0].dataPoints[length - 1].y) - (chart.options.data[0].dataPoints[length - 1].y) / 50
});
chart.render();
});
}