3
目前在互聯網上沒有關於具有圖例的氣泡圖的例子,使用dc.js和dc.legend()函數。是否可以製作泡泡圖的傳說?
that.sessions_scatterplot
.width(830)
.height(350)
.transitionDuration(1000)
.margins({top: 100, right: 10, bottom: 30, left: 25})
.dimension(that.dim_Source)
.group(that.fact_Source_Sessions)
.ordinalColors(["#70c5a4","#8cd4f2","#fdc976","#9d97c8"])
.colorAccessor(function(d){
return d.value.src_category;
})
.keyAccessor(function (d) {
var x = d.value.avg_time/d.value.count;
return x;
})
.valueAccessor(function (d) {
var y = d.value.hundred_bounce_rate/d.value.count;
return y;
})
.radiusValueAccessor(function (d) {
var r = Math.round(d.value.sessions/d.value.count);
return r;
})
.title(function(p){
return [p.key,
"Average Time On Page: " + (p.value.avg_time/p.value.count).toFixed(2),
"100 - Bounce Rate: " + (p.value.hundred_bounce_rate/p.value.count).toFixed(2),
"Sessions/Page Views: " + (p.value.sessions/p.value.count).toFixed(2)]
.join("\n");
})
.renderTitle(true)
.maxBubbleRelativeSize(0.03)
.x(d3.scale.linear().domain(that.avg_time_extent).range([0,that.width]))
.y(d3.scale.linear().domain(that.hundred_bounce_rate_extent).range([0,that.height]))
.r(d3.scale.linear().domain(that.sessions_pg_views_extent))
.minRadiusWithLabel(30)
.yAxisPadding(0.5)
.xAxisPadding(500)
.xAxisLabel('Average Time On Page')
.yAxisLabel('100 - Bounce Rate')
.legend(dc.legend().x(200).y(30).gap(5).horizontal(true).itemWidth(100).legendWidth(200));
有MUST是好歹在氣泡圖使用的傳說。
假設:
1)已經使用了最高利潤率。
2)使用colorAccessor()函數使用一個組給顏色着色。
3)'g'元素被附加到'svg','dc-legend'類被分配給'g'元素。但傳說中沒有子元素。
我相信這不直接支持dcjs。 你將不得不破解 https://github.com/dc-js/dc.js/blob/master/src/bubble-chart.js 並採取了一些靈感來源於 https://開頭github上。 com/dc-js/dc.js/blob/master/src/composite-chart.js#L363 或其他支持圖例支持的示例 – Navyseal 2014-12-05 06:13:26