1
+
2
+ // Use the margin convention practice
3
+ var ExampleMargin = { top : 50 , right : 70 , bottom : 50 , left : 70 } ,
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
+
7
+
8
+
9
+
10
+
11
+ d3 . csv ( "../data/hl/arbeit2.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
+
35
+
36
+ // d3's line generator
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