"D3.js Advanced Series-1.1" Reading of other table files

Source: Internet
Author: User

CSV table files are comma-delimited, and others have a TSV file with Tab tab as the cell delimiter, and others are table files that define other separators. This article explains how to read them in D3.

1. What is the TSV table file?

TSV (Tab Separated Values), the tab-delimited value, and the CSV file are just delimiters inconsistent. It has the following format:

Nameage Zhang 322 Li 424

2. Read the TSV file in D3

The method to read the TSV file in D3 is the same as the CSV file, as long as you change the function name. Here's how:

D3.TSV ("TABLE.TSV", function (error,tsvdata) {console.log (tsvdata); var str = D3.tsv.format (tsvdata); Console.log ( Str.length); Console.log (str);});

As we can see, this is basically the same as the "Advanced Series-1.0", which is described in detail in this article.


3. Read the nature of CSV and TSV in D3

In the above two sections we can see that reading CSV and TSV are surprisingly similar. In fact, they are essentially a function, let's look at the definition of D3 source code:

  D3.csv = D3.DSV (",", "text/csv");  D3.TSV = D3.DSV ("", "text/tab-separated-values");

As you can see, they are actually D3.DSV functions. So what is this DSV function about? A DSV can actually read a table file with any character or string as a delimiter . Let's try using the DSV function to read a table file with a semicolon as a delimiter. Suppose you have the following file:

Name;age Zhang San; 22 John Doe; 24

Read the following code:

var DSV = D3.DSV (";", "Text/plain");d sv ("TABLE.DSV", function (Error,dsvdata) {if (Error) Console.log (error); Console.log (Dsvdata);});

First Use D3.DSV (";", "Text/plain"); The delimiter is defined as a semicolon, and then read in the same way as the CSV and TSV files. Note, however, that the second line is no longer required to use D3.DSV because the variable DSV is already a function.


4. Concluding remarks

CSV files and TSV files are simply delimiters, and their essence is called the DSV function, so the control of the DSV function is critical.

Thank you for reading.

Document Information

    • Copyright Notice: Attribution (by)-Non-commercial (NC)-No deduction (ND)
    • Published: October 03, 2014
    • More content: our D3. JS-Data Visualization special station and CSDN personal blog
    • NOTE: Reprint please indicate the source, thank you

"D3.js Advanced Series-1.1" Reading of other table files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.