[D3.js advanced series-1.1] Reading of other table files, d3.js1.1

Source: Internet
Author: User

[D3.js advanced series-1.1] Reading of other table files, d3.js1.1

CSV table files use commas as unit delimiters, other TSV files with Tab as unit delimiters, and table files with other manually defined delimiters. This article describes how to read them in D3.

1. What is a TSV table file?

TSV (Tab Separated Values), tabulation delimiter value, which is different from the CSV file only by separator. The format is as follows:

Nameage Zhang San 22 Li Si 24

2. Reading TSV files in D3

The method for reading TSV files in D3 is the same as that for CSV files. You only need to change the function name. The method is as follows:

d3.tsv("table.tsv",function(error,tsvdata){console.log(tsvdata);var str = d3.tsv.format( tsvdata );console.log(str.length);console.log(str);});

We can see that this is basically the same as [advanced series-1.0]. For details, see this article.


3. Reading the essence of CSV and TSV in D3

In the above two sections, we can see that reading CSV is surprisingly similar to reading TSV. In fact, they are essentially a function. Let's take a look at the definitions in the D3 source code:

  d3.csv = d3.dsv(",", "text/csv");  d3.tsv = d3.dsv("", "text/tab-separated-values");

As you can see, they are all d3.dsv functions. So what is this dsv function? Dsv can actually read Table files that use any character or string as the separator. Next, we will try to use the dsv function to read Table files with semicolons as separators. Suppose there are the following files:

Name; age Zhang San; 22 Li Si; 24

The read code is as follows:

var dsv = d3.dsv(";", "text/plain");dsv("table.dsv",function(error,dsvdata){if(error)console.log(error);console.log(dsvdata);});

Use d3.dsv (";", "text/plain"); Define the separator as a semicolon, and then read it in the same way as reading csv and tsv files. Note that d3.dsv is no longer needed in the second line, because the variable dsv is already a function.


4. Conclusion

CSV files and TSV files only have different delimiters. They are essentially called DSV functions. Therefore, DSV functions are crucial.

Thank you for reading.

Document Information

  • Copyright Disclaimer: BY-non-commercial (NC)-deduction prohibited (ND)
  • Published on: February 1, October 03, 2014
  • More content: OUR D3.JS-data visualization special site and CSDN personal blog
  • Note: Please indicate the source for reprinting. Thank you.

Copy the excel files to the word3doc file as excel files.

Open WORD, select "object" in the Insert menu of WORD-> Create from file ~~~ Select the EXCEL3.XLS path and save it as WORD3.DOC.


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.