I have a dataset, as follows
[
{
"outTimestamp": 1415635862,
"compressionRatioInPercent": 13.974863249659291,
},
{
"outTimestamp": 1415635965,
"compressionRatioInPercent": 14.771445012891368,
},
{
"outTimestamp": 1415636146,
"compressionRatioInPercent": 15.475327655845122,
},
{
"outTimestamp": 1415636244,
"compressionRatioInPercent": 14.30788993821171,
}]I have read about this problem, and i guess the error occurs when there is a problem with parsing dataset. However I have tried so many solutions until now i cannot figure out what is causing the problem. I am trying ti render a simple line chart.
here is the code, i think is causing the problem but i cannot figure out the solution
d3.json("transcoder_data.json", function(error, data) {
data.forEach(function(d) {
d.outTimestamp = new Date(d.outTimestamp*1000);
d.compressionRatioInPercent = +d.compressionRatioInPercent;
});
complete code jsfidle is here
I'd suggest inserting a breakpoint right after your d3.json call and inspecting the error variable, or even just adding a "console.log(error);" straight after the call. You should be able to glean some information from there as to what is going wrong.
Ben.
d3.json is an asynchronous function. You are treating it like a synchronous one by doing:
var data = d3.json....
You need to place your rendering function inside the callback for d3.json. Something like this:
var chartData;
d3.json("data/data-simple.json", function(error, data) {
if (error) return console.error(error);
data.forEach(function(d) {
d.outTimestamp = new Date(d.outTimestamp*1000);
d.compressionRatioInPercent = +d.compressionRatioInPercent;
});
chartData = data;
d3.select('#chart svg')
.datum(chartData)
.transition().duration(500)
.call(chart);
});
You may want to read up on asynchronous functions here
Andy
On Fri, Feb 13, 2015 at 7:17 AM, Max Goldstein <maxgol...@gmail.com> wrote:
Hmm, right below logging the error, can you add console.log(json); and see if it's what you expect?
--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.