图例标签和颜色更改为黑色dc.js d3.js
我有一个包含两行代码的组合图表:图例标签和颜色更改为黑色dc.js d3.js,d3.js,data-visualization,dc.js,crossfilter,D3.js,Data Visualization,Dc.js,Crossfilter,我有一个包含两行代码的组合图表: function fakeGrouper(source_group) { return { all:function () { var cumulate = 100; var result = []; return [{key: 0, value:
function fakeGrouper(source_group) {
return {
all:function () {
var cumulate = 100;
var result = [];
return [{key: 0, value: cumulate}]
.concat(source_group.all().map(function(d) {
cumulate -= d.value;
return {key:d.key, value:cumulate};
}));
}
};
}
var recDim = cf1.dimension(dc.pluck('recidiefNa'));
var recGroup = recDim.group().reduceCount();
var RecGroup = fakeGrouper(recGroup);
var resDim = cf1.dimension(dc.pluck('residuNa'));
var resGroup = resDim.group().reduceCount();
var ResGroup = fakeGrouper(resGroup);
var scChart = dc.compositeChart("#scStepChart");
scChart
.width(600)
.height(400)
.x(d3.scale.linear().domain([0,52]))
.y(d3.scale.linear().domain([0,100]))
.clipPadding(10)
.brushOn(false)
.xAxisLabel("tijd in weken")
.yAxisLabel("percentage vrij van residu/recidief")
.legend(dc.legend().x(70).y(250).itemHeight(13).gap(5))
.compose([
dc.lineChart(scChart)
.dimension(recDim)
.group(RecGroup)
.renderDataPoints(true)
.interpolate("step-after")
,
dc.lineChart(scChart)
.dimension(resDim)
.group(ResGroup)
.colors(['#ff9933'])
.renderDataPoints(true)
.interpolate("step-after")
])
.xAxis().ticks(4);
scChart.render();
除了图例有0作为两个图表的标签这一事实之外,它呈现得非常完美。在这里查看我的小提琴:
现在我在某个地方读到,您可以通过将组从以下位置更改来解决此问题:
.group(GROUP)
到
然而,一旦我这样做了,第二张图表在图例中变黑了,图表中的线条也消失了。如第二把小提琴所示
你知道为什么以及如何解决这个问题吗?我想这可能与我使用了一个假组有关。您正在传递
.colors()
数组。您应该这样传递单个值:
.colors('#ff9933')
因此,图表函数如下所示:
.legend(dc.legend().x(70).y(250).itemHeight(13).gap(5))
.compose([
dc.lineChart(scChart)
.dimension(recDim)
.group(RecGroup, "Recidief")
.colors('red')
.renderDataPoints(true)
.interpolate("step-after")
,
dc.lineChart(scChart)
.dimension(resDim)
.group(ResGroup, "Residu")
.colors('#ff9933')
.renderDataPoints(true)
.interpolate("step-after")
])
.xAxis().ticks(10)
scChart.render();
更新的小提琴:我不确定我是否理解。标签上的0在哪里?@thisOneGuy如果你打开第一把小提琴,你会看到传说中有2个0,就像labelsah一样。我看到了,打开的是错误的一个,我很快会看一看
.legend(dc.legend().x(70).y(250).itemHeight(13).gap(5))
.compose([
dc.lineChart(scChart)
.dimension(recDim)
.group(RecGroup, "Recidief")
.colors('red')
.renderDataPoints(true)
.interpolate("step-after")
,
dc.lineChart(scChart)
.dimension(resDim)
.group(ResGroup, "Residu")
.colors('#ff9933')
.renderDataPoints(true)
.interpolate("step-after")
])
.xAxis().ticks(10)
scChart.render();