1
1
2
2
// Use the margin convention practice
3
3
var ExampleMargin = { top : 50 , right : 70 , bottom : 50 , left : 70 } ,
4
- width = $ ( "#ExampleLineChart " ) . width ( ) - ExampleMargin . left - ExampleMargin . right , // Use the window's width
5
- height = $ ( "#ExampleLineChart " ) . height ( ) - ExampleMargin . top - ExampleMargin . bottom ; // Use the window's height
4
+ width = $ ( "#HalfLifeGeldChart " ) . width ( ) - ExampleMargin . left - ExampleMargin . right , // Use the window's width
5
+ height = $ ( "#HalfLifeGeldChart " ) . height ( ) - ExampleMargin . top - ExampleMargin . bottom ; // Use the window's height
6
6
7
- // The number of datapoints
8
- var n = 21 ;
9
7
10
- var xScale = d3 . scaleLinear ( )
11
- . domain ( [ 0 , n - 1 ] ) // input
12
- . range ( [ 0 , width ] ) ; // output
13
8
14
- var yScale = d3 . scaleLinear ( )
15
- . domain ( [ 0 , 1 ] ) // input
16
- . range ( [ height , 0 ] ) ; // output
9
+
10
+
11
+ d3 . csv ( "../data/hl/arbeit.csv" , function ( csv ) {
12
+
13
+ csv . forEach ( function ( d ) {
14
+ d . x = + d . x ;
15
+ d . y = + d . y ;
16
+ } ) ;
17
+
18
+ data = csv ;
19
+
20
+
21
+
22
+ var testMin = d3 . min ( data , function ( d ) { return d . y } ) ;
23
+ console . log ( testMin ) ;
24
+ var testMax = d3 . max ( data , function ( d ) { return d . y } ) ;
25
+ console . log ( testMax ) ;
26
+
27
+ var xScale = d3 . scaleLinear ( )
28
+ . domain ( [ d3 . min ( data , function ( d ) { return d . x } ) , d3 . max ( data , function ( d ) { return d . x } ) ] ) // input
29
+ . range ( [ 0 , width ] ) ; // output
30
+
31
+ var yScale = d3 . scaleLog ( )
32
+ . domain ( [ d3 . min ( data , function ( d ) { return d . y } ) , d3 . max ( data , function ( d ) { return d . y } ) ] ) // input
33
+ . range ( [ height , 0 ] ) ; // output
34
+
17
35
18
36
// d3's line generator
19
- var line = d3 . line ( )
20
- . x ( function ( d , i ) { return xScale ( i ) ; } ) // set the x values for the line generator
21
- . y ( function ( d ) { return yScale ( d . y ) ; } ) // set the y values for the line generator
22
- . curve ( d3 . curveMonotoneX ) ; // apply smoothing to the line
23
-
24
-
25
- d3 . csv ( "data/MartiniStoryTwo_StackedAreaChart_DATA.csv" , function ( data ) {
26
-
27
- } ;
28
-
29
-
30
- console . log ( "test" ) ;
31
- console . log ( dataset ) ;
32
-
33
- // Add the SVG to the page and employ
34
- var svg = d3 . select ( "#ExampleLineChart" ) . append ( "svg" )
35
- . attr ( "width" , width + ExampleMargin . left + ExampleMargin . right )
36
- . attr ( "height " , height + ExampleMargin . top + ExampleMargin . bottom )
37
- . append ( "g" )
38
- . attr ( "transform" , "translate(" + ExampleMargin . left + "," + ExampleMargin . top + ")" ) ;
39
-
40
- // Call the x axis in a group tag
41
- svg . append ( "g ")
42
- . attr ( "class" , "x axis" )
43
- . attr ( "transform" , "translate(0," + height + ")" )
44
- . call ( d3 . axisBottom ( xScale ) ) ; // Create an axis component with d3.axisBottom
45
-
46
- // Call the y axis in a group tag
47
- svg . append ( "g" )
48
- . attr ( "class" , "y axis" )
49
- . call ( d3 . axisLeft ( yScale ) ) ; // Create an axis component with d3.axisLeft
50
-
51
- // Append the path, bind the data, and call the line generator
52
- svg . append ( "path" )
53
- . datum ( dataset ) // Binds data to the line
54
- . attr ( "class" , "line" ) // Assign a class for styling
55
- . attr ( "d" , line ) // Calls the line generator
56
- . attr ( "fill" , "none" )
57
- . attr ( "stroke" , "#960510" )
58
- . attr ( "stroke-width" , 2 ) ;
59
-
60
-
61
- // Appends a circle for each datapoint
62
- svg . selectAll ( ".dot" )
63
- . data ( dataset )
64
- . enter ( ) . append ( "circle" ) // Uses the enter().append() method
65
- . attr ( "class " , "dot" ) // Assign a class for styling
66
- . attr ( "cx " , function ( d , i ) { return xScale ( i ) } )
67
- . attr ( "cy" , function ( d ) { return yScale ( d . y ) } )
68
- . attr ( "r" , 3 )
69
- . attr ( "fill" , "#960510" ) ;
37
+ var line = d3 . line ( )
38
+ . x ( function ( d ) { return xScale ( d . x ) ; } ) // set the x values for the line generator
39
+ . y ( function ( d ) { return yScale ( d . y ) ; } ) // set the y values for the line generator
40
+ . curve ( d3 . curveCardinal ) ; // apply smoothing to the line
41
+
42
+
43
+
44
+
45
+ console . log ( "showing the data" ) ;
46
+ console . log ( data ) ;
47
+
48
+
49
+ // Add the SVG to the page and employ
50
+ var svg = d3 . select ( "#HalfLifeGeldChart" ) . append ( "svg" )
51
+ . attr ( "width" , width + ExampleMargin . left + ExampleMargin . right )
52
+ . attr ( "height" , height + ExampleMargin . top + ExampleMargin . bottom )
53
+ . append ( "g" )
54
+ . attr ( "transform " , "translate(" + ExampleMargin . left + "," + ExampleMargin . top + ")" ) ;
55
+
56
+ // Call the x axis in a group tag
57
+ svg . append ( "g" )
58
+ . attr ( "class" , "x axis" )
59
+ . attr ( "transform" , "translate(0," + height + ") ")
60
+ . call ( d3 . axisBottom ( xScale ) ) ; // Create an axis component with d3.axisBottom
61
+
62
+ // Call the y axis in a group tag
63
+ svg . append ( "g" )
64
+ . attr ( "class" , "y axis" )
65
+ . call ( d3 . axisLeft ( yScale ) ) ; // Create an axis component with d3.axisLeft
66
+
67
+ // Append the path, bind the data, and call the line generator
68
+ svg . append ( "path" )
69
+ . datum ( data ) // Binds data to the line
70
+ . attr ( "class" , "line" ) // Assign a class for styling
71
+ . attr ( "d" , line ) // Calls the line generator
72
+ . attr ( "fill" , "none" )
73
+ . attr ( "stroke" , "#960510" )
74
+ . attr ( "stroke-width" , 2 ) ;
75
+
76
+
77
+ // Appends a circle for each datapoint
78
+ svg . selectAll ( ".dot" )
79
+ . data ( data )
80
+ . enter ( ) . append ( "circle" ) // Uses the enter().append() method
81
+ . attr ( "class" , "dot" ) // Assign a class for styling
82
+ . attr ( "cx" , function ( d ) { return xScale ( d . x ) } )
83
+ . attr ( "cy " , function ( d ) { return yScale ( d . y ) } )
84
+ . attr ( "r " , 0.1 )
85
+ . attr ( "fill" , "#960510" ) ;
86
+
87
+ } ) ;
0 commit comments