简体   繁体   English

通过更改绘图数据更新浮点图

[英]Update the flot graph by changing plot data

I want to update a flot graph by changing one value in the series and corresponding plots also should be updated based on the changed value. 我想通过更改系列中的一个值来更新浮点图,并且也应根据更改后的值来更新相应的图。 My x-axis is date and time and my y-axis is the count. 我的x轴是日期和时间,我的y轴是计数。

样本图片

In the above image its explained what exactly i want. 在上图中,它解释了我到底想要什么。

function fnUpdateGraph(isNew,isUndo,isRedo){
 if(selectednodeid==undefined){
  showdialog(message.information,messages.informatio,"No nodes selected",null,false);
  return false;
 }
 var newHeadDate=new Date();
 var updateDate=document.getElementById("txt_node_head_date").value.split("-",3);
 newHeadDate.setDate(updateDate[0]);
 newHeadDate.setDate(+updateDate[1]-1);
 newHeadDate.setDate(updateDate[2]);
 var updateTime=document.getElementById("txt_node_head_time").value.split(":",2);
 newHeadDate.setHours(updateTime[0],updatetime[1],0,0);
 var maxNodeId=vehicle[selectedvehicle].length;
 if(selectedNodeId<maxNodeID){
  if(newHeadDate.getTime()>=new Date(vehicle[selectedvehicle][selectedNodeId+1].headDate).getTime()){
   plot.setData();
   plot.setupGrid();
   plot.draw();
   return;
  }
 }

I have added a part of my code where I have defined the updateGraph function. 我在定义了updateGraph函数的代码中添加了一部分。 What are the changes to be made in order to get the graph plotted with changed values. 为了获得绘制有变化值的图形,需要进行哪些更改。

You need to use a combination of plot.getData and plot.setData (see docs here ). 您需要结合使用plot.getDataplot.setData (请参阅此处的文档)。 getData will return an array of series, loop those until you find the point of interest and modify the value. getData将返回一系列数组,循环遍历这些序列,直到找到兴趣点并修改值为止。 Then call setData , setupGrid and draw . 然后调用setDatasetupGriddraw

var someData = somePlot.getData();
// loop first series
for (var i = 0; i < someData[0].data.length; i++) {
  // the data member of the series contains x/y point data
  // look at X values until you find the one you want
  if (someData[0].data[i][0] == someSearchXValue) {
     someData[0].data[i][2] = someNewYValue;
     plot.setData(someData);
     plot.setupGrid();
     plot.draw();
     return;
  }
}

Here's a fiddle demonstration . 这是一个小提琴表演

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM