Super easy to use Java data visualization library: Tablesaw

This article is for people just finished learning the Java language-based, follow this article to learn and use Tablesaw project. Examples are demonstrated in the Windows operating system

Author: HelloGitHub- Qin

HelloGitHub launched "to explain open source projects" series, today to give us a Java-based data visualization library open source project - Tablesaw

Tablesaw is a Java data visualization library. It mainly includes two parts: a data parsing library, the other is the data visualization library. Loading data analysis mainly database data, manipulate the data (conversion, filtering, aggregation, etc.). Data visualization library is a target data into visual diagrams.

Project Source address: https: //github.com/jtablesaw/tablesaw

First, the project structure

Directory Description:

  1. aggregate: maven project parent project, the definition of the main items packaged configuration.
  2. beakerx: registry tablesaw library, the main registry and columns.
  3. core: tablesaw library core code, mainly processing operational data: additional data, sorting, grouping, inquiries.
  4. data: Project Test data directory.
  5. docs: Project MarkDown documents directory.
  6. docs-src: source directory project documentation, the main role is to generate MarkDown document.
  7. excel: excel file parsing subproject data.
  8. html: html parsing subproject file data.
  9. json: parse sub json file data.
  10. jsplot: visualization sub data, the main role loading data generating visual diagrams.
  11. saw: tablesaw read and write data sub chart.

Second, combat operations

2.1 Preparations

Project dependencies introduced Tablesaw

<dependency>
    <groupId>tech.tablesaw</groupId>
    <artifactId>tablesaw-core</artifactId>
    <version>LATEST</version>
</dependency>

2.2 data analysis

2.2.1 Internal data creation data table

@Test
public void tableSawTest6() {
    String[] students = {"小明", "李雷", "小二"};
    double[] scores = {90.1, 84.3, 99.7};
    Table table = Table.create("学生分数统计表").addColumns(
                    StringColumn.create("姓名", students),
                    DoubleColumn.create("分数", scores));
    System.out.println(table.print());
}

Code is super simple, first define the column data to show students and scores. Then create a data table showing the definition of a table name, column data tables can be added.

Results are shown below:

2.2.2 load a data file creation data table

@Test
public void tableSawTest10() throws Exception{
    Table table = Table.read().csv("/data/bush.csv");
    Table whoPercents = table.xTabPercents("who");
    whoPercents.columnsOfType(ColumnType.DOUBLE)
    .forEach(x -> ((NumberColumn) x).setPrintFormatter(
        NumberColumnFormatter.percent(0)));
    System.out.println(whoPercents.toString());
}

First, Table.readload the data files, loading data support csv, database result set, file, URL, etc.

Field specifies the x-axis of the table, and the percentages of conversion data.

bash.csv document reads as follows:

Operating results are as follows:

2.3 Data Visualization

Table robberies = Table.read().csv("./data/boston-robberies.csv");
Plot.show(
    AreaPlot.create(
        "Boston Robberies by month: Jan 1966-Oct 1975", 
        robberies, "Record", "Robberies"));

First, load data Table.read, charting AreaPlot.create, and then Plot.showgenerate html pages in the local chart, automatically open the browser.

boston-robberies.csv document reads as follows:

Operating results are as follows:

Tablesaw can also draw a lot of types of charts, look forward to your excavations.

Third, and finally

Tutorial At this point, you should have a simple understanding of the Tablesaw. Here to tell you one way, you can quickly grasp the open source libraries: find items in the source code of unit test code. Then, we then project into development tools run directly in the project unit tests. This is probably the most efficient and effective control method to use open source libraries.

This tutorial is for a certain Java-based programming, if you just need to project data visualization library, Tablesaw library is a good choice!


"Explain open source projects Series" - to let people interested in open source projects are no longer afraid, let sponsors open source projects are no longer alone. Follow our articles, you'll discover the fun of programming, the use of open source projects and found to be involved so simple. Welcome messages to contact us, join us, so that more people fall in love with open source, open source contribution ~

Guess you like

Origin www.cnblogs.com/xueweihan/p/11721955.html