2016-01-25 52 views
1

幫助。我試圖製作甘特圖,我只是沒有看到 這樣做。 甘特圖與水平條形圖類似,每條開始點的座標爲 。 所以它看起來像:無論如何都是爲了製作甘特圖而積攢嗎?

 
    XXXXX 
     XXXXXX 
    XXXXXXXXXXXXXXXXXXXXX 
      XXXX 

我不能找到一種方法,使以條形圖開頭的「酒吧」在特定 X座標。 任何提示/技巧/提示?

+0

根據這張圖表,plotly.js沒有做甘特圖,但也有少數的替代品。 https://en.wikipedia.org/wiki/Comparison_of_JavaScript_charting_frameworks –

+0

無賴。我寧願留在plotly.js,因爲我用它來處理其他圖表...... – user3089203

+0

在我放棄之前..我會嘗試製作一個水平堆疊條,並在第一個數據集上使用「不透明度:0%」 。這應該會使條形看起來像甘特圖一樣浮動。 – user3089203

回答

1

這裏是我的結果...不是一個完美的甘特圖, (你不能改變的大小吧,沒有依賴項之間 ),但對我來說已經足夠了:

enter image description here

的代碼段,以顯示我是如何做到透明痕跡(S):

 // loop through all obj's to draw, for each one 
     // make a transparent offset to mimic gantt chart. 
     traces.push({ 
      x: [ obj.totalrunTime ], 
      y: [ key ], 
      name: key, 
      text: [ obj.totalrunTime+' '+key ], 
      orientation: 'h', 
      marker: { color: obj.color }, 
      type: 'bar' 
     }); 
     traces.push({ 
      x: [ offset ], 
      y: [ key ], 
      showlegend: false, 
      orientation: 'h', 
      marker: { color: 'rgba(255,255,255,0)' }, 
      hoverinfo: "none", 
      name: key, 
      type: 'bar' 
     }); 

     offset = offset + jobs[key].totalrunTime; 
0

Riddhiman已R. 做出了很大的解決方案,這0。 由於循環的原因,我一開始並不情願,但它給予了大量的自由。

我加一點額外的佈局我的需求:

p <- plot_ly() 
for(i in 1:(nrow(df) - 1)){ 
    p <- add_trace(p, 
      x   = c(df$Start[i], df$Start[i] + df$Duration[i]), # x0, x1 
      y   = c(i, i), # y0, y1 
      mode  = "lines+markers+text", 
      marker = list(color = df$color[i] 
          ,symbol = "line-ns-open" 
          ,size = 13), #markers ensures visability 
      text  = c(df$text[i],"") # adds a text string 
      textposition = "middle left" #to the left of the bar 
      line  = list(color = df$color[i] 
          , width = 20), 
      showlegend = F, 
      hoverinfo = "text", 

      # Create custom hover text 

      text  = paste0("<b>Task:</b> ",  df$Task[i],  "<br>", 
           "<b>Duration:</b> ", df$Duration[i], " days<br>", 
           "<b>Resource:</b> ", df$Resource[i]), 

      evaluate = T # needed to avoid lazy loading 
)} 
0

是的! 進口plotly.figure_factory爲ff

ff.create_gantt(DF)

Plotly已建成甘特圖。您不需要從條形圖創建它們。你可以給它一個字典列表,或者你可以給它一個數據框。如果你選擇後者,請確保告訴圖中哪個列是任務,以及你的開始和結束日期。我發現使用數據時間更容易,併爲Start和Finish列添加標籤。這樣甘特圖會自動讀取它們,文檔位於以下鏈接中。

https://plot.ly/python/gantt/