Package smile.plot.vega
Class Data
java.lang.Object
smile.plot.vega.Data
The basic data model used by Vega-Lite is tabular data. Individual data sets
are assumed to contain a collection of records, which may contain any number
of named data fields.
A dataset may be either inline data (values) or a URL from which to load the
data (url). Or we can create an empty, named data source (name), which can
be bound at runtime or populated from top-level datasets.
-
Method Summary
Modifier and TypeMethodDescriptionLoads a comma-separated values (CSV) fileLoads a delimited text file with a custom delimiter.Loads a delimited text file with a custom delimiter.Sets the format for parsing the data.Sets the format for parsing the data.Loads a JSON file.Sets a placeholder name and bind data at runtime.Loads a JSON file using the TopoJSON format.Returns the specification in pretty print.toString()
Loads a tab-separated values (TSV) fileSets the url of the data source.Sets an array describing the data source.<T> Data
Sets a list describing the data source.<T> Data
values
(T[] data) Sets an array describing the data source.
-
Method Details
-
toString
-
toPrettyString
Returns the specification in pretty print.- Returns:
- the specification in pretty print.
-
name
Sets a placeholder name and bind data at runtime.- Parameters:
name
- the dataset name.- Returns:
- this object.
-
url
Sets the url of the data source.- Parameters:
url
- A URL from which to load the data set.- Returns:
- this object.
-
format
Sets the format for parsing the data.- Parameters:
format
- "json", "csv", "tsv", or "dsv".- Returns:
- this object.
-
format
Sets the format for parsing the data.- Parameters:
format
- "json", "csv", "tsv", or "dsv".type
- Explicit data type. Each key corresponds to a field name, and the value to the desired data type (one of "number", "boolean", "date", or null (do not parse the field)). If set to null, disable type inference based on the spec and only use type inference based on the data.- Returns:
- this object.
-
values
Sets an array describing the data source. Set to null to ignore the parent's data source. If no data is set, it is derived from the parent.- Parameters:
json
- JSON content to parse.- Returns:
- this object.
-
values
Sets an array describing the data source. Set to null to ignore the parent's data source. If no data is set, it is derived from the parent.- Parameters:
data
- an array of data.- Returns:
- this object.
-
values
Sets a list describing the data source. Set to null to ignore the parent's data source. If no data is set, it is derived from the parent.- Parameters:
data
- a list of data.- Returns:
- this object.
-
json
Loads a JSON file. Assumes row-oriented data, where each row is an object with named attributes.- Parameters:
url
- A URL from which to load the data set.property
- The JSON property containing the desired data. This parameter can be used when the loaded JSON file may have surrounding structure or meta-data. For example "values.features" is equivalent to retrieving json.values.features from the loaded JSON object.- Returns:
- this object.
-
topojson
Loads a JSON file using the TopoJSON format. The input file must contain valid TopoJSON data. The TopoJSON input is then converted into a GeoJSON format. There are two mutually exclusive properties that can be used to specify the conversion process: "feature" or "mesh".- Parameters:
url
- A URL from which to load the data set.conversion
- "feature" or "mesh".name
- The name of the TopoJSON object set to convert to a GeoJSON feature collection (or mesh).- Returns:
- this object.
-
csv
Loads a comma-separated values (CSV) file- Parameters:
url
- A URL from which to load the data set.type
- Explicit data type. Each key corresponds to a field name, and the value to the desired data type (one of "number", "boolean", "date", or null (do not parse the field)). If set to null, disable type inference based on the spec and only use type inference based on the data.- Returns:
- this object.
-
tsv
Loads a tab-separated values (TSV) file- Parameters:
url
- A URL from which to load the data set.type
- Explicit data type. Each key corresponds to a field name, and the value to the desired data type (one of "number", "boolean", "date", or null (do not parse the field)). If set to null, disable type inference based on the spec and only use type inference based on the data.- Returns:
- this object.
-
dsv
Loads a delimited text file with a custom delimiter. This is a general version of CSV and TSV.- Parameters:
url
- A URL from which to load the data set.delimiter
- The delimiter between records. The delimiter must be a single character (i.e., a single 16-bit code unit); so, ASCII delimiters are fine, but emoji delimiters are not.- Returns:
- this object.
-
dsv
Loads a delimited text file with a custom delimiter. This is a general version of CSV and TSV.- Parameters:
url
- A URL from which to load the data set.delimiter
- The delimiter between records. The delimiter must be a single character (i.e., a single 16-bit code unit); so, ASCII delimiters are fine, but emoji delimiters are not.type
- Explicit data type. Each key corresponds to a field name, and the value to the desired data type (one of "number", "boolean", "date", or null (do not parse the field)). If set to null, disable type inference based on the spec and only use type inference based on the data.- Returns:
- this object.
-