2016-05-11 10 views
2

私はd3型ライブラリを使用してキャンバス上にエリアチャートを作成しようとしています。以下はコードですキャンバスにd3字型の領域グラフを描画しますか?

const area = d3_shape.area() 
    .x(function(d) { return x(d.date); }) 
    .y(function(d) { return y(d.price); }) 
    .y0(height) 
    .context(context); 

context.strokeStyle = '#9DBBEB'; 
context.beginPath(); 
area(data); 
context.fillStyle = '#8ED6FF'; 
context.fill(); 
context.lineWidth = 1.5; 
context.stroke(); 

私はここで間違っていますか?

https://github.com/d3/d3-shape

https://bl.ocks.org/mbostock/1550e57e12e73b86ad9e

答えて

2

あなたはアクセサ関数間違ったエリアを設定している、次のようになります。コードhereを実行

var area = d3_shape.area() 
    .x(function(d) { return x(d.date); }) 
    .y0(height) //<-- y0 
    .y1(function(d) { return y(d.close); }) //<-- y1 
    .context(context); 

+0

ありがとうございます... – Daniyal

関連する問題