您可以在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);
不幸的是,您提供的数据并没有那么有趣,因为提供者并没有真正重叠。一旦你加载了所有数据,它应该看起来更好:)