久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何配置 flot 以在 y 軸上的零點繪制缺失的時間

How to configure flot to draw missing time series on y-axis at point zero?(如何配置 flot 以在 y 軸上的零點繪制缺失的時間序列?)
本文介紹了如何配置 flot 以在 y 軸上的零點繪制缺失的時間序列?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用flot(

I'm using flot (flot on github) to draw a graph with the following time series data:

[
    [1357171200000, 1],
    [1357344000000, 1],
    [1357430400000, 2],
    [1357516800000, 2],
    [1357689600000, 3],
    [1357776000000, 1]
]

As you can see there are some points in the graph wich show the sales for the given day. My json response doesn't contain sales count / data for days where no sale has happened. For example the 04th of January. How can i configure flot to draw the missing days on y-axis at point zero (because there are no sales)? As you can see in the image flot does connect the points so there are no zero points in the graph.

解決方案

Here's a solution that creates a new Array adding in missing days and setting their values to zero:

/* create and return new array padding missing days*/
function newDataArray(data) {
  var startDay = data[0][0],
    newData = [data[0]];

  for (i = 1; i < data.length; i++) {
    var diff = dateDiff(data[i - 1][0], data[i][0]);
    var startDate = new Date(data[i - 1][0]);
    if (diff > 1) {
      for (j = 0; j < diff - 1; j++) {
        var fillDate = new Date(startDate).setDate(startDate.getDate() + (j + 1));
          newData.push([fillDate, 0]);
      }
    }
    newData.push(data[i]);
  }
  return newData;
}


/* helper function to find date differences*/
function dateDiff(d1, d2) {
  return Math.floor((d2 - d1) / (1000 * 60 * 60 * 24));
}

To use:

var data = [
  [1357171200000, 1],
  [1357344000000, 1],
  [1357430400000, 2],
  [1357516800000, 2],
  [1357689600000, 3],
  [1357776000000, 1]
];

var newData=newDataArray(data);
/* pass newData to flot*/

DEMO: http://jsfiddle.net/LK2gD/3/

這篇關于如何配置 flot 以在 y 軸上的零點繪制缺失的時間序列?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 在线观看免费av网 | 91国自产 | 黄色国产| 日韩在线观看一区 | 国产人成精品一区二区三 | 成人精品视频在线观看 | 日韩精品成人一区二区三区视频 | 三极网站 | 日本三级全黄三级a | 国产精品久久久久久久久久久免费看 | 欧美性网| 国产成人jvid在线播放 | 亚洲一区二区三区国产 | 国产亚洲精品a | 天天干天天干 | 欧美日韩综合 | 久久久久九九九女人毛片 | 成人小视频在线观看 | 国产精品一区二 | 中文字幕亚洲一区二区三区 | a级网站| 久久国产精品无码网站 | 中文字幕高清av | 亚洲欧美中文日韩在线v日本 | 黄色操视频 | 在线看日韩av | 日韩欧美精品在线 | 天天射视频| 日日夜精品视频 | 欧美精品91 | 在线观看欧美日韩视频 | 一区二区三区在线 | 国产亚洲精品久久久久动 | 国产日韩一区二区 | 天天干b | 91精品久久久久久久久久入口 | 国产精品视频久久久 | 干狠狠| 蜜桃视频在线观看www社区 | 欧美日韩亚洲国产综合 | 久久国产精品久久 |