- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
//这是经过深入研究的系列图表 - 但这里仍然存在一些错误。
所以我们有一批数据 - 健康与美容、餐厅、咖啡馆、公共(public)场所。-- 会有 COUNT 个 -- 以及结帐信息的总和。所以我希望这张图表能够显示 field 的数量,但也能表明它们有多受欢迎……例如,酒吧的数量可能会更少,但签到的数量会更高,因为它们更受欢迎。所以在那种情况下想要反转圆圈的颜色。
当前的代码尝试存在一些错误。
用“V”代替“L”,但暂时无法正常工作。
第 2 阶段 我认为它的工作更加一致,但存在一些问题。另外,我不确定圆圈的数据和缩放比例。 (我添加了额外的标签,以便可以看到圆圈的值是什么)
稍微更改了 getCircleSize,尽管我认为更一致的做法应该是这样 layerSet.push(parseInt(getPercentage(layerArray[i], meansPerGroup[0])*60, 10)) ;
所以这里第一步首先按大小顺序绘制圆圈...所以在这种情况下按计数..但这里可能存在错误,反转颜色以指示 checkin 计数 - 所以也许我们需要排序计数,检查顺序 - 这样第一个被绘制的圆圈就会正确跟随。
// Create Circles
function setCircles(items) {
// sort elements in order to draw them by size
items.sort(function(a, b) {
return parseFloat(b.value) - parseFloat(a.value);
});
var circlelayer = svg.append("g")
.attr("class", "circlelayer");
var circle = circlelayer.selectAll("circle")
.data(items);
circle.enter().append("circle")
.attr("class", function(d, i) {
if (d.l == 0) {
return "blue";
}
return "gold";
})
.attr("cy", 60)
.attr("cx", function(d, i) {
var distance = calculateDistance(d, items);
if (d.l == 1) {
distancesL1.push(distance);
} else {
distancesL0.push(distance);
}
return distance;
})
.attr("r", function(d, i) {
return Math.sqrt(d.value);
})
.attr("filter", function(d) {
return "url(#drop-shadow)";
});
circle.exit().remove();
}
json 结构看起来像这样
[{
"label": "Health and Beauty",
"count": 30,
"checkin": 100
}, {
"label": "Restaurants",
"count": 23,
"checkin": 200
}, {
"label": "Cafes",
"count": 11,
"checkin": 900
}, {
"label": "Public Houses",
"count": 5,
"checkin": 1000
}]
最佳答案
我不确定我明白你的问题是什么,但我决定尝试根据你的截图和你的 plunker 的示例数据创建该图表。这是我的结果:
我的脚本确保较小的圆圈始终位于愤怒的圆圈之上,因此两个圆圈始终可见。在这里你可以找到我的代码:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v5.min.js"></script>
<style>
html {
font-family: sans-serif;
}
</style>
</head>
<body>
<div id="container">
</div>
<script>
const data = [{
"name": "Twitter",
"vists": "15 billion",
"unit": "per day",
"layer1value": 15000000,
"layer2value": 450
}, {
"name": "Facebook",
"vists": "5 billion",
"unit": "per day",
"layer1value": 4000000,
"layer2value": 5000000
}, {
"name": "Google",
"vists": "5 billion",
"unit": "per day",
"layer1value": 5000000,
"layer2value": 25000
}, {
"name": "Netflix",
"vists": "10 billion",
"unit": "per day",
"layer1value": 3000000,
"layer2value": 2200
}, {
"name": "Ebay",
"vists": "8 billion",
"unit": "per day",
"layer1value": 2500000,
"layer2value": 4900000
}, {
"name": "Klout",
"vists": "2 billion",
"unit": "per day",
"layer1value": 1000000,
"layer2value": 45
}];
/*
* Finding max and min layer size
*/
const values = data.reduce((acumulator, datum) => [...acumulator, datum.layer1value, datum.layer2value], []);
const maxValue = Math.max(...values);
const minValue = Math.min(...values);
/*
* Creating scale based on the smallest and largest layer1value or layer2value
*/
const radiusScale = d3.scaleLinear()
.domain([minValue, maxValue])
.range([10, 150]); // min and max value of the circle
const width = 900;
const height = 500;
const orangeColour = '#ffb000';
const blueColour = '#00a1ff';
// Creating svg element
const svg = d3.select('#container').append('svg').attr('width', width).attr('height', height);
let xPos = 0; // position of circle
/*
* iterate over each datum and render all associated elements: two circles, and two labels with pointer lines
*/
for (let i = 0; i < data.length; i++) {
const d = data[i]; // current data point
const currMaxRadius = radiusScale(Math.max(d.layer1value, d.layer2value)); // get largest radius within current group of two layers
xPos += currMaxRadius; // add that radius to xPos
// create group element containing all view elements for current datum
const group = svg.append('g')
.attr('transform', `translate(${xPos}, ${height / 2})`);
group.append('circle')
.attr('r', radiusScale(d.layer1value))
.style('fill', blueColour);
group.insert('circle', d.layer2value > d.layer1value ? ':first-child' : null) // if layer2value is larger than layer1value then insert this circle before the previous one
.attr('r', radiusScale(d.layer2value))
.style('fill', orangeColour);
xPos += currMaxRadius * 0.9;
/*
* ADDING LABEL UNDERNEATH THE CIRCLES
*/
group.append('text')
.text(d.name)
.attr('dy', radiusScale(maxValue) + 40) // add 40px of padding so label is not just bellow the circle
.style('text-anchor', 'middle');
group.append('line')
.attr('y1', radiusScale(d.layer2value))
.attr('y2', radiusScale(maxValue) + 20) // add 20px of padding so the pointer line is not overlapping with label
.style('stroke', orangeColour);
/*
* ADDING LABEL AT THE ANGLE OF 45deg RELATIVE TO THE CIRCLES
*/
// we are creating new group element so we can easily rotate both line and label by -45deg
const rotatedLabelGroup = group.append('g').style('transform', 'rotate(-45deg)');
rotatedLabelGroup.append('line')
.attr('x1', radiusScale(d.layer2value))
.attr('x2', radiusScale(maxValue) + 20)
.style('stroke', orangeColour);
rotatedLabelGroup.append('text')
.text(d.vists)
.attr('dx', radiusScale(maxValue))
.attr('dy', -5); // this way label is slightly above the line
}
</script>
</body>
关于javascript - d3.js Checking/Count 系列图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39306307/
目录 count作用 测试 count(*) count(1) count(col) count(id):统计id count(inde
目录 1.初识COUNT 2.COUNT(字段)、COUNT(常量)和COUNT(*)之间的区别 3.COUNT(*)的优化 MyIS
以下 SQL Server 2008 语句之间有什么区别? SELECT COUNT(*) FROM dbo.Regular_Report SELECT COUNT(0) FROM dbo.Regul
如果字符串(短语)中只有元音,它(对我而言)说True;否则说 False。我不明白为什么它总是返回 False,因为 (x >= x) 总是返回 True。我感谢任何人检查此查询的解决方案。 (st
1.概述 在这个文章之前,我一直用count(1) 查询所有数据,以前我们都是说 count(*) 是最慢的。但是这个博客恰恰相反。 对于 count(主键 id) 来说,InnoDB 引擎会遍历整张
这个问题已经有答案了: Count(*) vs Count(1) - SQL Server (13 个回答) 已关闭 8 年前。 我经常发现这三种变体: SELECT COUNT(*) FROM Fo
为什么三个查询的成本相同?我想至少应该有一个更快。否则,只使用关键字 COUNT() 而不是 COUNT(parameter) 就可以了。 例如,以下是不依赖于参数的 COUNT() 示例实现: wh
我有一个“产品”表和一个“评论”表。 我想编写一个查询来返回每个产品的评论的 COUNT 和 AVG。 并且如果没有评论,我希望它为 COUNT 和 AVG 返回 0/null。 产品表 +-----
我会保持简短和亲切,因为我确信我缺少的是一些简单的东西。我正在尝试获取一个 NSMutableArray 的计数,它可以包含可变数量的对象(id 号)。数组是从 JSon 数据创建的,数组本身是完美创
我想知道查询计数的计数。 查询是 sourcetype="cargo_dc_shipping_log" OR sourcetype="cargo_dc_deliver_log" | stats cou
任何人都知道我如何在 SQL 炼金术中进行计数 COUN(IF(table_row = 1 AND table_row2 =2),1,0) 我做了这样的东西, func.COUNT(func.IF((
我有一个有四列的表(销售); id, user_id, product_id, and date_added. 我需要统计某个用户已售出的具有特定 id 的产品数量,并获取该用户当月售出的产品总数。
我是来问这个问题的实现的 MYSQL count of count? 我的问题是将我从一个表中提取结果的结果联系起来,使用它们来查询同一数据库的另一个表 (抱歉,我不是强大的 xySQL)。 我有一个
这是我的查询 SELECT COUNT(*) as total, toys, date FROM T1 WHERE (date >= '2012-06-26'AND date '0') UNION
我有 2 个表:成员,订单。 Members: MemberID, DateCreated Orders: OrderID, DateCreated, MemberID 我想找出给定月份中新成员的数
我最近在一次采访中被问到这个问题。我在 mySQL 中尝试了这个,并得到了相同的结果(最终结果)。All 给出了该特定表中的行数。谁能解释它们之间的主要区别。 最佳答案 没什么,除非您在表格中指定字段
我有一个包含 2157 条记录的表,假设有 3 列(A、B、C),我知道在 A 列中有 2154 个不同的值。 使用连接到 BigQuery 的 Tableau Desktop(及其自身的功能),我得
我试图查看当天的车辆销量,并创建另外两个列来告诉我过去 10 天的销量和过去 20 天的销量。同一天和同一辆车可能有多个销售。我的目标是获取不同的车辆和日期并查看他们的销售数量。 N 天计数应与该行中
我有一个非常简单的问题。我想知道某个数据库行是否存在。 我通常使用: SELECT 1 FROM `my_table` WHERE `field_x` = 'something' 然后我获取结果: $
我想要的输出的描述:我想要两个线程 Gaurav 和 john 完成一个 while 循环(从 1 到 8),这样无论哪个线程启动 ist,都会运行 5 次迭代(即直到 count=5 ) ,然后进入
我是一名优秀的程序员,十分优秀!