Veena
Veena

Reputation: 11

D3 charts and JSON

Hi I created one d3 stacked horizontal chart with data given as an array in the HTML itself. Now I want to remove the data from code and place it as a separate JSON file. When I tried its giving me error which am not able to solve. Here is my previous code which was working and the latest code

dataset = [{
        data: [{
            Region: 'N',
            count: 500
        }, {
            Region: 'W',
            count: 200
        }, {    
            Region: 'C',
            count: 300
        }, {
            Region: 'E',
            count: 150
        }],
        name: 'Average Order Management Time'
    }, {
        data: [{
            Region: 'N',
            count: 500
        }, {
            Region: 'W',
            count: 400
        }, {
            Region: 'C',
            count: 150
        },    {
            Region: 'E',
            count: 255
        }],     
        name: 'Average Enrichment Time'
   }];

dataset = dataset.map(function (d) {
               //code goes here
          });

now I created a separated json file and modified the code as below.

d3.csv("AvgHori.json", function(error, data){
   //code goes here
}),

Chart is not appearing and when I debugged it gave me this error.

SCRIPT5007: Unable to get property 'prototype' of undefined or null reference What is this? Why the cart is not taking my JSON file

Upvotes: 0

Views: 164

Answers (1)

Gilsha
Gilsha

Reputation: 14591

D3 parses json files using d3.json method, not d3.csv. d3.csv is used for csv files.

d3.json("AvgHori.json", function(error, data){
   //code goes here
}),

Upvotes: 1

Related Questions