我已经查看了各种教程,但找不到涵盖的用例。
这是我的数据集的子集,格式为CSV:
Provider,Service date,Unique patients seen
10800,2007-12-03,1
10800,2008-03-21,9
10800,2008-04-16,3
10800,2008-04-18,6
11451,2008-06-27,24
11451,2008-07-10,1
11451,2008-07-14,31
11451,2008-07-15,6
12980,2008-06-17,24
12980,2008-06-27,14
12980,2008-06-28,24
13907,2008-05-04,23
13907,2008-05-05,20
13907,2008-05-08,6
14618,2008-08-27,27
14618,2008-09-04,21
14618,2008-09-05,20
我想为每个唯一的提供者提供一个系列,该系列的X轴为服务日期,Y轴为患者看到的时间。
到目前为止,我已经看过multi-series line chart tutorial,但是我不能说服它使用我拥有的数据而不是现在的列。
有什么建议或读数吗?
tarek:)
最佳答案
您可以在http://jsfiddle.net/YHW6H/1/上看到一个有效的示例。
我做了以下工作来强制您的数据。您将要使用d3.csv
读取csv文件,但我将示例的值硬编码。
// you would use d3.csv('filename.csv', function (data) {...})
// in order to populate the data variable, I'm just hard coding it here
var data = [
{Provider:'10800', 'Service Date': '2007-12-03', 'Unique patients seen':'1'},
{Provider:'10800', 'Service Date': '2008-03-21', 'Unique patients seen':'9'},
{Provider:'10800', 'Service Date': '2008-04-16', 'Unique patients seen':'3'},
{Provider:'10800', 'Service Date': '2008-04-18', 'Unique patients seen':'6'},
{Provider:'11451', 'Service Date': '2008-06-27', 'Unique patients seen':'24'},
{Provider:'11451', 'Service Date': '2008-07-10', 'Unique patients seen':'1'},
{Provider:'11451', 'Service Date': '2008-07-14', 'Unique patients seen':'31'},
{Provider:'11451', 'Service Date': '2008-07-15', 'Unique patients seen':'6'},
{Provider:'12980', 'Service Date': '2008-06-17', 'Unique patients seen':'24'},
{Provider:'12980', 'Service Date': '2008-06-27', 'Unique patients seen':'14'},
{Provider:'12980', 'Service Date': '2008-06-28', 'Unique patients seen':'24'},
{Provider:'13907', 'Service Date': '2008-05-04', 'Unique patients seen':'23'},
{Provider:'13907', 'Service Date': '2008-05-05', 'Unique patients seen':'20'},
{Provider:'13907', 'Service Date': '2008-05-08', 'Unique patients seen':'6'},
{Provider:'14618', 'Service Date': '2008-08-27', 'Unique patients seen':'27'},
{Provider:'14618', 'Service Date': '2008-09-04', 'Unique patients seen':'21'},
{Provider:'14618', 'Service Date': '2008-09-05', 'Unique patients seen':'20'}
];
// first we need to coerce the data into the right formats and make the
// names a little more sane
data = data.map( function (d) {
return {
provider: +d.Provider, // the + sign will coerce strings to number values
date: new Date(d['Service Date']),
patients: +d['Unique patients seen'] };
});
// then we need to nest the data on Provider since we want to only draw one
// line per provider
data = d3.nest().key(function(d) { return d.provider; }).entries(data);
不幸的是,您提供的数据并不是很有趣,因为提供者并没有真正重叠。一旦加载了所有数据,它看起来就会更好:)
关于jquery - 如何为第一列中的每个唯一项创建具有系列的多系列折线图?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12993906/