0
當我在條形圖中選擇任何特定字段時,所有圖形都會相應更改。如何使用dc.js在圖上添加標籤?
我想介紹一個圖表上面的標題,它應該顯示哪些數據當前顯示在圖表和計數中。
那麼我應該在我的代碼中做些什麼改變?
var data = [{
"city": "New York",
"neighborhood": "N/A",
"hits": 200
}, {
"city": "New York",
"neighborhood": "Brooklyn",
"hits": 225
}, {
"city": "New York",
"neighborhood": "Queens",
"hits": 1
}, {
"city": "San Francisco",
"neighborhood": "Chinatown",
"hits": 268
}, {
"city": "San Francisco",
"neighborhood": "Downtown",
"hits": 22
}, {
"city": "Seattle",
"neighborhood": "N/A",
"hits": 2
}, {
"city": "Seattle",
"neighborhood": "Freemont",
"hits": 25
}];
var pieChart = dc.pieChart("#pieChart"),
rowChart = dc.rowChart("#rowChart");
var ndx = crossfilter(data),
cityDimension = ndx.dimension(function (d) {
return d.city;
}),
cityGroup = cityDimension.group().reduceSum(function (d) {
return d.hits;
}),
neighborhoodDimension = ndx.dimension(function (d) {
return d.neighborhood;
}),
neighborhoodGroup = neighborhoodDimension.group().reduceSum(function (d) {
return d.hits;
});
pieChart.width(200)
.height(200)
.slicesCap(4)
.dimension(cityDimension)
.group(cityGroup);
pieChart.filter = function() {};
rowChart.width(500)
.height(500)
.dimension(neighborhoodDimension)
.group(neighborhoodGroup);
dc.renderAll();
<div id="pieChart"> </div>
<div id="rowChart"> </div>
但我想爲我的網站做的是,我有一長串客戶,併爲每個客戶選擇圖表根據客戶數據的變化,所以我想介紹一個標籤上方的圖表,目前的數據顯示是爲這個客戶和這個特定的服務。那麼,我該怎麼做才能做到這一點。 – amru
所以你在過濾器中過濾客戶?該過濾器是通過dc.js還是外部的?如果是通過dc.js,那麼'過濾的'事件就是要走的路。 – Gordon