Pergunta

I'm using dc.js/crossfilter/d3 to draw a chart with the following data

var jsonStr = ([
  {"date": "2011-11-14", "value": 0.1121},
  {"date": "2011-11-15", "value": 0.2221},
  {"date":"2011-11-16", "value": 0.3321},
  {"date":"2011-11-17", "value": 0.4221},
 ...
  {"date":"2011-11-22", "value": -0.6544},
  {"date":"2011-11-23", "value": -0.3131},
  {"date":"2011-11-24", "value": -0.2122},
  {"date":"2011-11-25", "value": -0.0231}
]);

setting up my dimmension like such:

// set up my date objects
var timeFormat = d3.time.format("%Y-%m-%d");
jsonStr.forEach(function (e) {
    e.date = timeFormat.parse(e.date);
    e.dd = new Date(e.date);
    e.month = d3.time.month(e.dd);
});

// feed it through crossfilter
var ndx = crossfilter(jsonStr);
var all = ndx.groupAll();

//setup dimmensions
var dateDimension = ndx.dimension(function (d) {
    return d.dd;
});

//fluctuation chart, I bet i'm doing something wrong here...
var fluctuation = ndx.dimension(function (d) {
    return d.value.toFixed(2);
    // return Math.round(d.value);
});

When the chart is drawn, I cannot select individual negative values. Anyone have an idea on what I need to do?

Full fiddle here: http://jsfiddle.net/wbott70/Fvw9m/

Foi útil?

Solução

Your bet was right! d.value.toFixed returns a string of the value and crossfilter functions called by the histogram brush are trying to work with numeric values.

Let the fluctuation dimension handle the exact numeric values and use fluctuationGroup to group close values for the histogram:

//fluctuation chart
var fluctuation = ndx.dimension(function (d) {
    return d.value;
});

var fluctuationGroup = fluctuation.group(function(d){
  return Math.round(d*10)/10;
});

http://jsfiddle.net/Fvw9m/2/

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top