2016-03-30 5 views
0

dc.jsを使用して個別の棒グラフを生成しようとしています。データがインターガー形式であれば、チャームのようなチャートを生成します。しかし、私は入力データをStringに変更すると動作しません。私は以下のコードで何かを見逃していますか? は、ここに私のバイオリンのリンクです:jsfiddle linkdc.jsがグラフを生成するために文字列データを受け入れない

var chart = dc.barChart("#test"); 
var data = [ 
    { "x": "Urgent","y": 5 }, 
    { "x": "High", "y": 10 }, 
    { "x": "Medium", "y": 0 }, 
    { "x": "Low", "y": 50 }, 
    { "x": "None", "y": 0 } 
]; 
var ndx = crossfilter(data), 
     priorityValue = ndx.dimension(function(d) {return d.x;}), 
     countValue = priorityValue.group().reduceSum(function(d) {return d.y;}); 
    console.log("xaxis",priorityValue); 
    chart 
    .width(768) 
    .height(480) 
    .gap(20) 
    .x(d3.scale.linear().domain([0, data.length + 1])) 
    .xAxisLabel("Priority") 
    .brushOn(false) 
    .centerBar(true) 
    .renderLabel(true) 
    .yAxisLabel("Number of Alerts") 
    .elasticX(true) 
    .dimension(priorityValue) 
    .group(countValue) 
    .renderTitle(true).title(function (d) { 
     return 'test: ' + d.value; 
     }) 
    .renderHorizontalGridLines(true) 
    .label(function (d) { 
      console.log(d); 
      return 'test'; 
     }); 


    chart.render(); 

labels = chart.g().selectAll("rect.bar text"); 
console.log(labels); 

答えて

0

あなたのXデータは、文字列は、あなたがより多くの情報のためにD3スケールのマニュアルを参照してください代わりにd3.scale.linear().domain(...)

d3.scale.ordinal()を使用する必要がある場合:

https://github.com/mbostock/d3/wiki/Ordinal-Scales

https://github.com/mbostock/d3/wiki/Quantitative-Scales

.xUnits(dc.units.ordinal)が必要かもしれません - 完全に自動化されたdc.jsはごくわずかです。

関連する問題