2016-08-20 34 views
0

我一直在試圖讓圖表工作,所有的數據似乎都是圖表,但是工具提示並沒有從最右側移動。這當然是一個問題,因爲我不能在特定點上查看數據。c3圖表工具提示不會移動

這裏是發生了什麼事的JS提琴例如:https://jsfiddle.net/kp7eyf8o/6/

注:出於某種原因堆棧溢出的jsfiddle給我一個錯誤,但URL應該顯示我的問題。

var chart = c3.generate({ 
 
    bindto: '#test', 
 
    data: { 
 
    x: 'x', 
 
    columns: [ 
 
     ['x', '2016-01-01', '2016-02-02', '2016-03-03', '2016-04-04', '2016-05-05', '2016-06-06', '2016-07-07', '2016-08-08', '2016-09-09', '2016-10-10', '2016-11-11', '2016-12-12'], 
 
     ['2016 Actual', 12873666.64, 15976835.94, 19232540.28, 23649495.4, 26338636.36, 29496799.84, 43801703.66, 4263924.64, 5788580.3, ], 
 
     ['2016 Projected', 3916752.11, 4626643.23, 5146264.25, 6148854.32, 6640724.57, 7409783.48, 8263054.46, 8488001.54, 8837809.1, 9068047.68, 9402019.15, 9513505.72, ], 
 
     ['2015 Actual', 3256870.0, 3825580.0, 4394290.0, 5550000.0, 6044000.0, 7100000.0, 7700000.0, 8154000.0, 8860000.0, 9200000.0, 9500000.0, 9600328.45, ] 
 
    ], 
 
    colors: { 
 
     '2016 Actual': '#2cd554', 
 
     '2016 Projected': '#1bc4fc', 
 
     '2015 Actual': '#fdaf5a' 
 
    } 
 
    }, 
 
    axis: { 
 
    x: { 
 
     type: 'timeseries', 
 
     tick: { 
 
     culling: false, 
 
     format: '%b' 
 
     } 
 
    }, 
 
    y: { 
 
     tick: { 
 
     format: d3.format("$,.2f") 
 
     } 
 
    } 
 
    }, 
 
});
<link href="https://rawgit.com/masayuki0812/c3/master/c3.css" rel="stylesheet" /> 
 
<script src="https://rawgit.com/masayuki0812/c3/master/c3.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.3.12/d3.min.js"></script> 
 

 

 
<div id="test"></div>

我看到有人提到使用「的xs:{X ....Ÿ....},但我沒能得到那個工作。我需要X軸是日期(現在硬編碼,但在我的應用程序中,我使用與正在循環的一個數據集相關的日期),Y軸爲$。

回答

1

當不同長度的數據數組輸入到列中時,C3工具提示似乎會中斷。您可以嘗試將空值放入較短的數組中,以便工具提示可以正確移動。 JS小提琴:https://jsfiddle.net/stancheta/7zgny2yd/

['2016 Actual', 12873666.64, 15976835.94, 19232540.28, 23649495.4, 26338636.36, 29496799.84, 43801703.66, 4263924.64, 5788580.3, null, null, null], 
+0

謝謝,這很完美!因此,如果我使用3個數據集,最好是以某種方式確定哪個數據庫最長,然後讓其他2個循環遍歷所有數據,然後返回null以便將其填入數據庫中。 – edhog

+0

只要數據集的大小相同,就沒問題了:)。我也在瀏覽C3知識庫,並注意到這個確切的問題有一個公開的拉取請求,所以也許在未來的版本中,這可能會成爲一個問題。 –

+0

謝謝,你一直非常有幫助。 – edhog