Question
I am working on using d3 to write the code in a .html file. I tried to follow the steps in the codes to get
I am working on using d3 to write the code in a .html file. I tried to follow the steps in the codes to get the result in the image but cannot succeed.
// define the dimensions and margins for the graph
// define function to parse time in years format
// create scales x & y for X and Y axis and set their ranges
// append svg element to the body of the page
// set dimensions and position of the svg element
var svg = d3.select("body").append("svg")
// Get the data
var pathToCsv = ""; // path to csv
d3.dsv(",", pathToCsv, function (d) {
return {
// format data attributes if required
}
}).then(function (data) {
console.log(data); // you should see the data in your browser's developer tools console
/* Create bar plot using data from csv */
// set the domains of X and Y scales based on data
x.domain();
y.domain();
// Add bars to svg - create new elements based on your data
svg.selectAll()
// Add the X Axis
svg.append()
// Add the text label for X Axis
svg.append()
// Add the Y Axis
svg.append()
// Add the text label for Y axis
svg.append()
}).catch(function (error) {
console.log(error);
});
The data we use is a .csv file. the content in the file is listed below. There are two columns: year and running_total.
year running_total
1884 1
1885 1
1886 3
1887 11
1888 12
1889 12
1890 15
1891 17
1892 24
1893 25
1894 59
1895 89
1896 246
1897 430
1898 616
1899 775
1900 985
1901 1180
1902 1328
1903 1539
1904 1725
1905 1853
1906 1996
1907 2110
1908 2287
1909 2502
1910 2795
1911 3159
1912 3690
1913 4167
1914 4564
1915 5021
1916 5558
1917 6090
1918 6540
1919 6975
1920 7486
1921 7959
1922 8405
1923 8892
1924 9443
1925 10083
1926 10826
1927 11566
1928 12296
1929 13060
1930 13924
1931 14824
1932 15868
1933 16831
1934 17852
1935 18942
1936 20002
1937 21098
1938 22102
1939 23065
1940 24060
1941 25080
1942 26058
1943 26988
1944 27875
1945 28772
1946 29605
1947 30365
1948 31228
1949 32110
1950 33023
1951 33897
1952 34760
1953 35655
1954 36450
1955 37293
1956 38132
1957 39017
1958 39857
1959 40635
1960 41379
1961 42152
1962 42955
1963 43765
1964 44724
1965 45797
1966 46894
1967 48109
1968 49366
1969 50710
1970 52143
1971 53514
1972 54985
1973 56371
1974 57824
1975 59148
1976 60465
1977 61732
1978 63177
1979 64632
1980 66054
1981 67413
1982 68793
1983 70278
1984 71846
1985 73449
1986 75128
1987 77073
1988 79082
1989 81089
1990 83122
1991 85189
1992 87268
1993 89368
1994 91646
1995 94024
1996 96467
1997 98981
1998 101690
1999 104570
2000 107622
2001 110974
2002 114763
2003 118990
2004 123698
2005 129124
2006 134943
2007 140902
2008 147303
2009 154027
2010 160885
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started