如何将canvasJS生成的数据保存到数据库?

I am new to graphs and I want to create a real time graph that generates random data and save the data on database. I already saw a code in canvasjs that generates random data and create a real time graph. My problem is how to save the data generated in canvasjs to the database. I have a database name randgraph and I want save the y value to data column and x value to id column.. Thanks..

Here is the Javascript code.

window.onload = function () {

var dps = []; // dataPoints
var chart = new CanvasJS.Chart("chartContainer", {
  title :{
    text: "Dynamic Data"
  },
  axisY: {
    includeZero: false
  },      
  data: [{
    type: "line",
    dataPoints: dps
  }]
});

var xVal = 0;
var yVal = 100; 
var updateInterval = 1000;
var dataLength = 20; // number of dataPoints visible at any point

var updateChart = function (count) {

  count = count || 1;

  for (var j = 0; j < count; j++) {
    yVal = yVal +  Math.round(5 + Math.random() *(-5-5)); //generate random number for y value
    dps.push({
      x: xVal,
      y: yVal
    });
    xVal++; 
  }

  if (dps.length > dataLength) {
    dps.shift();
  }

  chart.render();
};

updateChart(dataLength);
setInterval(function(){updateChart()}, updateInterval);

}

Here is the image of the graph as well as full code. CanvasJs. My problem is how to save the generated data into database.

douzhuijing4911
douzhuijing4911 将此功能分为两部分。一个生成数据数组,另一个更新图表的数据属性并在更新后呈现它。然后创建一个第三个函数,它将调用第一个函数来生成数据,然后将该数据传递给将更新图表的第二个函数。这样,创建数据与更新图表完全分离,因此,您可以在main函数内添加POST请求以将数据发送到服务器。
接近 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐