--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/a9fcd23d-752c-43da-8ae9-5d5a3a25b986%40googlegroups.com.
Assume we have an array names.
compositeChart.shareTitle(false);
compositeChart.compose(
names.map(function(name) {
return dc.lineChart(compositeChart)
.dimension(writtenDimension)
.colors('red')
.group(hoursSumGroup)
.valueAccessor(function(kv) {
return kv.value[name];
})
.title(function(kv) {
return name + ' ' + kv.key + ': ' + kv.value;
});
}));To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/efcf58aa-8375-4347-9415-64f90357872f%40googlegroups.com.
queue()
.defer(d3.json, "/livmanu/data")
.await(makeGraphs);
function makeGraphs(error, json_results) {
//Create a Crossfilter instance
var results = crossfilter(json_results);
//Define Dimensions
var yearDim = results.dimension(function(d) {
return d["Season"];
});
//Create array of objects with finishing positions for both teams by year
var positions = yearDim.group().reduce(
function(p, v) { // add
p[v["Team"]] = (p[v["Team"]] || 0) + v["OverallPosition"];
return p;
},
function(p, v) { // remove
p[v["Team"]] -= v["OverallPosition"];
return p;
},
function() { // initial
return {};
});
//Chart
var composite = dc.compositeChart("#time-chart");
//Number formatting for x-axis
var xTicks = d3.format(".0f");
//Create array of team names
var names = json_results.map(function(row) { return row.Team; });
composite
.width(800)
.height(200)
.margins({top: 10, right: 50, bottom: 30, left: 50})
.x(d3.time.scale().domain([1894, 2016]))
.y(d3.scale.linear().domain([44,0]))
.shareTitle(false)
.compose(
names.map(function(name) {
return dc.lineChart(composite)
.dimension(yearDim)
.colors(function() {
if (name == "Liverpool") {
return "red";
} else {
return "black";
}
})
.group(positions)
.valueAccessor(function(kv) {
return kv.value[name];
})
.title(function(kv) {
return name + ' ' + kv.key + ': ' + kv.value;
});
}))
.xAxisLabel("Season")
.yAxisLabel("League Position")
.xAxis().tickFormat(xTicks);
dc.renderAll();
}