Невозможно показать линию по убыванию в d c. js - PullRequest
0 голосов
/ 30 марта 2020

индекс. html:

<div id="line-chart2" class="svg-container">
    <div class="chart-title">
        <span>
            <strong>Line Types</strong>
        </span>
        <span>
            <a href="javascript:lineChart2.filterAll(); dc.redrawAll();" style="display:none;" class="reset">reset</a>
        </span>
    </div>
</div>

индекс. js:

const lineChart2 = dc.lineChart("#line-chart2");
var data = crossfilter([{foo:"one",bar:1},{foo:"two",bar:2},{foo:"three",bar:3},{foo:"one",bar:4},{foo:"one",bar:5},{foo:"two",bar:6}]);

var dim = data.dimension(function(d) {
   return d.foo;
});
var group = dim.group();
let TypeGroup = group.reduceCount(function(d) {
   return d.bar;
});

lineChart2
   .height(500)
   .width(lineChart2.width() * 0.95) //give it a width
   // .margins({top: 10, right: 10, bottom: 20, left: 100})//give it margin left of 100 so that the y axis ticks dont cut off
   .dimension(dim)
   .group(TypeGroup)
   .x(d3.scale.ordinal())
   .xUnits(dc.units.ordinal)
   .ordering(function(kv) {
      console.log("val:", kv.value);
      return -kv.value;
   })
   .interpolate('linear')
   .elasticY(true)
   .renderArea(true)
   .xAxis().ticks(3).tickFormat(function(d) {
      // console.log("kkk:",d)
      return d;
   });

Выход:

enter image description here

Я хочу что-то вроде этого: enter image description here

Линия идет вниз и показывает значения точек (количество).

Я пытался упорядочить, но он не работает (console.log там не работает)

Редактировать: Я обновил код: index. js:

var data = crossfilter([
  { foo: 'one', bar: 1 },
  { foo: 'two', bar: 2 },
  { foo: 'three', bar: 3 },
  { foo: 'one', bar: 4 },
  { foo: 'one', bar: 5 },
  { foo: 'two', bar: 6 },
]);

var dim = data.dimension(function(d) { return d.foo; });
var group = dim.group();


let TypeGroup = group.reduceCount(function(d) { 
    return d.bar; }
    );

TypeGroup.order(function(p) {
    return p;
});

TypeGroup.all = function() {
    return TypeGroup.top(Infinity);
}

    lineChart2
        .height(600)
        .width(lineChart2.width()*0.95) //give it a width
        // .margins({top: 10, right: 10, bottom: 20, left: 100})//give it margin left of 100 so that the y axis ticks dont cut off
        .dimension(dim)
        .group(TypeGroup) 
        .ordering(function(kv) { 
            console.log("val:",kv.value);
            return -kv.value; })
        .x(d3.scale.ordinal( ))
        .xUnits(dc.units.ordinal)
        .interpolate('linear')
        .elasticY(true)
        .renderArea(true)
         .renderlet(function(chart){chart.selectAll("circle.dot").style("fill-opacity", 1).on('mousemove', null).on('mouseout', null);})

        // .renderTitle(true)
        .renderLabel(true)
        .xAxis().ticks(3).tickFormat(function(d) {
            return d;
        });

enter image description here

renderLabel не работает. Мне нужно показать значение метки поверх него.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...