Reputation: 11
I am currently building a data visualization for a class using Vega and I would like to be able to print the data so I can see my transform results for debugging purposes. I have had no problem with this when the data is in JSON format but for whatever reason when the data is in CSV format the method returns null. This is the case even when I have a functioning visualization with successfully applied transforms, so I know the data is not null.
Example code showing what I am trying to do
let spec = {
"$schema": "https://vega.github.io/schema/vega/v5.json",
"data": [
{
"name": "data",
"url": "link.csv", //removed class website link
"format": {"type": "csv", "parse": "auto"}
}
]
};
let runtime = vega.parse(spec);
let view = new vega.View(runtime)
.logLevel(vega.Error)
.renderer("svg")
.initialize("#view")
.hover();
let dd = view.data("data"); //This method works fine with JSON, but not CSV
console.log(dd);
Upvotes: 0
Views: 280
Reputation: 797
For debugging, a better approach is to inspect the Vega view runtime datasets and signals (no setTimeout required). For example:
console.log("Vega datasets:", view._runtime.data, "\nVega signals:", view._signals);
Upvotes: 1
Reputation: 797
The reason why console.log is not showing the data from url is because javascript processes the code asynchronously. The console.log statement is executed immediately after the Vega view -- before Vega has completed retrieval and procvessing the data from external url link.
The solution is to delay execution of console.log (e.g. by 2 seconds) using setTimeout():
setTimeout(function(){console.log(view.data("data"))}, 2000);
Upvotes: 1