久久久久久久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?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 亚洲午夜视频在线观看 | 亚洲一区在线播放 | h片在线观看网站 | 中文二区 | 国产精品18久久久久久白浆动漫 | 亚洲一区有码 | 一本在线 | 亚洲精品在线视频 | 97视频人人澡人人爽 | 国产激情一区二区三区 | 91精品国产91久久综合桃花 | 亚洲一区二区三区四区五区午夜 | 91久久精品国产91久久性色tv | 亚洲精品视频免费 | 国产精产国品一二三产区视频 | 亚洲精品久久久久久首妖 | 欧美日韩一区二区三区四区 | 国产精品99免费视频 | 日韩欧美视频 | 欧美日韩一 | 黄色免费看| 国产电影一区二区在线观看 | 国产视频1区 | 国产亚洲精品久久19p | 中国免费黄色片 | 依人成人| 国产女人与拘做受视频 | 国产精品一区二区久久精品爱微奶 | 日韩视频精品在线 | 国产三级 | 精品日韩 | 亚洲一区 中文字幕 | 97日日碰人人模人人澡分享吧 | 国产精品美女久久久 | 日本不卡免费新一二三区 | 成人在线视频看看 | aaa在线观看 | 一区二区三区电影网 | 亚洲第一中文字幕 | 亚洲日韩中文字幕一区 | 综合久久久久 |