잠시 시간을내어 버블 차트를 살펴보십시오. 그것은 Illustrator에서 만든 이미지입니다. 지금은 dc.js으로 버블 차트를 복제하려고합니다. this page에 주어진 예 그래프에 대한 코드를 해부dc.js 버블 차트의 x 축으로 월별로 플롯
는 I 위를 달성하려고 시도했다.
'use strict'
// define bubble chart and get a handle
var referralsChart = dc.bubbleChart('#referrals-bubble-chart');
// load the csv data
d3.csv("data/data.csv", function (data) {
/* since its a csv file we need to format the data a bit */
var dateFormat = d3.time.format("%d/%m/%Y");
var numberFormat = d3.format(".2f");
data.forEach(function (d) {
d.dd = dateFormat.parse(d.date);
});
// create cross-filter dimensions and groups
// see the crossfilter api at (https://github.com/square/crossfilter/wiki/API-Reference) for reference.
var referralsChartXFilter = crossfilter(data);
var referralsChartXGroups = referralsChartXFilter.groupAll();
// dimension by full date
var dateDimension = referralsChartXFilter.dimension(function (d) {
return d.dd.getMonth();
});
var diagnosisDimension = referralsChartXFilter.dimension(function (d) {
return d.referredfor;
});
// dimension group
var diagnosisDimensionGroup = diagnosisDimension.group();
// define the referrals bubble chart attributes
referralsChart
.width(700)
.height(400)
.transitionDuration(1500) // (optional) define chart transition duration, :default = 750
.margins({top: 10, right: 50, bottom: 30, left: 40})
.dimension(dateDimension)
//Bubble chart expect the groups are reduced to multiple values which would then be used
//to generate x, y, and radius for each key (bubble) in the group
.group(diagnosisDimensionGroup)
.colors(colorbrewer.RdYlGn[9]) // (optional) define color function or array for bubbles
.colorDomain([0, 100]) //(optional) define color domain to match your data domain if you want to bind data or color
//##### Accessors
//Accessor functions are applied to each value returned by the grouping
//
//* `.colorAccessor` The returned value will be mapped to an internal scale to determine a fill color
//* `.keyAccessor` Identifies the `X` value that will be applied against the `.x()` to identify pixel location
//* `.valueAccessor` Identifies the `Y` value that will be applied agains the `.y()` to identify pixel location
//* `.radiusValueAccessor` Identifies the value that will be applied agains the `.r()` determine radius size, by default this maps linearly to [0,100]
.colorAccessor(function (d) {
return d.value/100
})
.keyAccessor(function (p) {
return p.value
})
.valueAccessor(function (p) {
return p.value
})
.radiusValueAccessor(function (p) {
return p.value
})
.maxBubbleRelativeSize(0.1)
.x(d3.scale.linear().domain([0, 5000]))
.y(d3.scale.linear().domain([0, 5000]))
.r(d3.scale.linear().domain([0, 4000]))
//##### Elastic Scaling
//`.elasticX` and `.elasticX` determine whether the chart should rescale each axis to fit data.
//The `.yAxisPadding` and `.xAxisPadding` add padding to data above and below their max values in the same unit domains as the Accessors.
.elasticY(true)
.elasticX(true)
.yAxisPadding(100)
.xAxisPadding(500)
.renderHorizontalGridLines(true) // (optional) render horizontal grid lines, :default=false
.renderVerticalGridLines(true) // (optional) render vertical grid lines, :default=false
.xAxisLabel('Date') // (optional) render an axis label below the x axis
.yAxisLabel('Referrals') // (optional) render a vertical axis lable left of the y axis
//#### Labels and Titles
//Labels are displaed on the chart for each bubble. Titles displayed on mouseover.
.renderLabel(true) // (optional) whether chart should render labels, :default = true
.label(function (p) {
return p.key;
})
.renderTitle(true) // (optional) whether chart should render titles, :default = false
.title(function (p) {
return [p.key,
"Referrals: " + numberFormat(p.value.absGain),
"Index Gain in Percentage: " + numberFormat(p.value.percentageGain) + "%",
"Fluctuation/Index Ratio: " + numberFormat(p.value.fluctuationPercentage) + "%"]
.join("\n");
})
//#### Customize Axis
//Set a custom tick format. Note `.yAxis()` returns an axis object, so any additional method chaining applies to the axis, not the chart.
.yAxis().tickFormat(function (v) {
return v + "%";
});
dc.renderAll();
});
위의 코드는 내가 거품이 그려 얻을 의미에서 작동하지만, x 축과 y 축 쇼 잘못된 저울 : 여기 내 코드입니다. 여기에 위의 코드를지고있어 무엇의 스크린 샷입니다 : 내가 원하는 무엇
는 월별로 날짜가 x 축 (1 월, 2 월, 3 월 역모를 꾸몄다는 ... 등), y 축은 추천을위한 데이터 범위입니다.
전달되는 csv 데이터는 found here 일 수 있습니다.
내가 편집해야하는 것은 아래 두 줄이라는 것을 알고 있지만 데이터를 전달하는 방법을 모르겠습니다.
.x(d3.scale.linear().domain([0, 5000]))
.y(d3.scale.linear().domain([0, 5000]))
.r(d3.scale.linear().domain([0, 4000]))
도움을 주시면 감사하겠습니다.