JavaScript中的直方图? [英] Histogram in JavaScript?

查看:217
本文介绍了JavaScript中的直方图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个收入数据集:


Income      Number of people
0           245981
8.8         150444
30          126063
49.9        123519
70          115029
90.7        277149
109.1       355768
130         324246
150.3       353239
170.2       396008
190         396725
210         398640
230.1       401932
250         416079
270         412727
289.8       385192
309.7       343178
329.7       293707
349.6       239982
369.7       201557
389.3       165132
442.3       442075
543.4       196526
679.9       146784
883.9       48600
1555        44644

(正如你所看到的,收入水平之间的宽度朝向末端变大。)

(As you can see, the width between income levels gets larger towards the end.)


  1. 如何在JavaScript中准确地计算这些数据的直方图? (在
    a线性x轴刻度,范围从例如0 - 2000)

  2. 如何计算人只显示百分比在
    不同的时间间隔?

  3. 如果我想要显示100个代表数据的符号,那么
    如何决定它们放在哪里?


推荐答案

现有的直方图示例基于从样本计算直方图,说如果你有一个个人和他们的收入的列表。在这种情况下,你已经有了直方图的数据,你只是想显示它。

The existing histogram examples are based on computing the histogram from samples, say if you had a list of individual people and their incomes. In this case, you already have the data for the histogram—you just want to display it.

这里的棘手的事情是你的直方图有可变宽度的bin。你可以做的第一件事是忽略每个bin的可变宽度,只显示一个简单的棒棒糖图表。 x 轴是收入的线性尺度, y 轴是人数计算的线性尺度:

The tricky thing here is that your histogram has variable-width bins. The first thing you can do is ignore the variable-width of each bin and just display a simple lollipop chart. The x-axis is a linear scale for income, and the y-axis is a linear scale for count of people:

http://bl.ocks.org/1624656

如果要将其转换为直方图,则不能使用可变宽度条替换这些固定宽度的行;您需要对数据进行标准化,以便条码的区域可以编码具有该收入的人的频率。因此,条的宽度是收入范围(例如,对于第一个bin,从0到8.8),条的高度是人的数量除以宽度。结果,面积(宽×高)与人数成正比。如下所示:

If you want to convert this to a histogram, you can't just replace those fixed-width lines with variable-width bars; you need to normalize the data so that the area of the bar encodes the frequency of people with that income. Therefore, the width of the bar is the income range (such as from 0 to 8.8 for the first bin), and the height of the bar is the quantity of people divided by the width. As a result, the area (width × height) is proportional to the number of people. That looks like this:

http://bl.ocks .org / 1624660

这篇关于JavaScript中的直方图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆